001/*-------------------------------------------------------------------------+ 002| | 003| Copyright (c) 2005-2017 The ConQAT Project | 004| | 005| Licensed under the Apache License, Version 2.0 (the "License"); | 006| you may not use this file except in compliance with the License. | 007| You may obtain a copy of the License at | 008| | 009| http://www.apache.org/licenses/LICENSE-2.0 | 010| | 011| Unless required by applicable law or agreed to in writing, software | 012| distributed under the License is distributed on an "AS IS" BASIS, | 013| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 014| See the License for the specific language governing permissions and | 015| limitations under the License. | 016| | 017+-------------------------------------------------------------------------*/ 018package org.conqat.engine.commons.findings; 019 020import java.io.Serializable; 021import java.util.Set; 022 023import org.conqat.engine.commons.findings.location.ElementLocation; 024import org.conqat.lib.commons.collections.CollectionUtils; 025import org.conqat.lib.commons.js_export.ExportToJavaScript; 026 027import com.fasterxml.jackson.annotation.JsonProperty; 028 029/** 030 * Element of a path of statements that is attached to a finding. See 031 * {@link DetachedFinding#getStatementPath()} for a more detailed description of 032 * its contract and usage. 033 */ 034 035@ExportToJavaScript 036public class StatementPathElement implements Serializable { 037 038 /** Serial version UID. */ 039 private static final long serialVersionUID = 1L; 040 041 /** 042 * Indices of the predecessors of this path element. The indices refer to the 043 * StatementPath (which is a list) that this element is a part of. 044 */ 045 @JsonProperty("predecessors") 046 private Set<Integer> predecessors; 047 048 /** Location that this path element refers to. */ 049 @JsonProperty("location") 050 private ElementLocation location; 051 052 /** 053 * A user-visible description that explains the role of this path element 054 * leading to a finding. 055 */ 056 @JsonProperty("description") 057 private String description; 058 059 /** Constructor. */ 060 public StatementPathElement(Set<Integer> predecessorPathElements, ElementLocation location, String description) { 061 this.predecessors = predecessorPathElements; 062 this.location = location; 063 this.description = description; 064 } 065 066 /** @see #predecessors */ 067 public Set<Integer> getPredecessorPathElements() { 068 return CollectionUtils.asUnmodifiable(predecessors); 069 } 070 071 /** @see #location */ 072 public ElementLocation getLocation() { 073 return location; 074 } 075 076 /** @see #location */ 077 public void setLocation(ElementLocation location) { 078 this.location = location; 079 } 080 081 /** @see #description */ 082 public String getDescription() { 083 return description; 084 } 085 086 /** {@inheritDoc} */ 087 @Override 088 public String toString() { 089 return getDescription(); 090 } 091 092 /** 093 * Adds the given predecessorId to the predecessors of this 094 * StatementPathElement. 095 */ 096 public void addPredecessorPathElement(Integer predecessorId) { 097 this.predecessors.add(predecessorId); 098 } 099 100}