All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.conqat.engine.commons.findings.location.ElementLocation Maven / Gradle / Ivy

There is a newer version: 2025.1.0-rc2
Show newest version
/*-------------------------------------------------------------------------+
|                                                                          |
| Copyright 2005-2011 The ConQAT Project                                   |
|                                                                          |
| Licensed under the Apache License, Version 2.0 (the "License");          |
| you may not use this file except in compliance with the License.         |
| You may obtain a copy of the License at                                  |
|                                                                          |
|    http://www.apache.org/licenses/LICENSE-2.0                            |
|                                                                          |
| Unless required by applicable law or agreed to in writing, software      |
| distributed under the License is distributed on an "AS IS" BASIS,        |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and      |
| limitations under the License.                                           |
+-------------------------------------------------------------------------*/
package org.conqat.engine.commons.findings.location;

import java.io.Serializable;

import org.conqat.lib.commons.js_export.ExportToTypeScript;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;

/**
 * Base class for locations. Locations are immutable and thus return this at
 * deep cloning.
 */
@ExportToTypeScript
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type", defaultImpl = ElementLocation.class)
@JsonSubTypes({ @JsonSubTypes.Type(value = TextRegionLocation.class, name = "TextRegionLocation"),
		@JsonSubTypes.Type(value = QualifiedNameLocation.class, name = "QualifiedNameLocation"), })
public class ElementLocation implements Serializable {

	/** Version used for serialization. */
	private static final long serialVersionUID = 1;

	/** The name of the JSON property name for {@link #location}. */
	protected static final String LOCATION_PROPERTY = "location";

	/** The name of the JSON property name for {@link #uniformPath}. */
	protected static final String UNIFORM_PATH_PROPERTY = "uniformPath";

	/** The location (see {@link #getLocation()}). */
	@JsonProperty(LOCATION_PROPERTY)
	private final String location;

	/** The uniform path (see {@link #getUniformPath()}). */
	@JsonProperty(UNIFORM_PATH_PROPERTY)
	private final String uniformPath;

	@JsonCreator
	public ElementLocation(@JsonProperty(LOCATION_PROPERTY) String location,
			@JsonProperty(UNIFORM_PATH_PROPERTY) String uniformPath) {
		this.location = location;
		this.uniformPath = uniformPath;
	}

	public ElementLocation(String uniformPath) {
		this(uniformPath, uniformPath);
	}

	/**
	 * Get a string that identifies the location of the element, e.g. a file system
	 * path. This location is specific to the running analysis, i.e. depends on time
	 * and the concrete machine ConQAT is running on.
	 */
	public String getLocation() {
		return location;
	}

	/**
	 * Returns the uniform path. This is an artificial path that uniquely defines a
	 * resource across machine boundaries. This should be used for persisted
	 * information.
	 */
	public String getUniformPath() {
		return uniformPath;
	}

	/**
	 * Returns a single line description of the location that is meaningful to the
	 * user.
	 */
	public String toLocationString() {
		return getUniformPath();
	}

	/** {@inheritDoc} */
	@Override
	public String toString() {
		return toLocationString();
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy