org.checkerframework.dataflow.expression.ClassName Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dataflow-shaded Show documentation
Show all versions of dataflow-shaded Show documentation
dataflow-shaded is a dataflow framework based on the javac compiler.
It differs from the org.checkerframework:dataflow artifact in two ways.
First, the packages in this artifact have been renamed to org.checkerframework.shaded.*.
Second, unlike the dataflow artifact, this artifact contains the dependencies it requires.
package org.checkerframework.dataflow.expression;
import java.util.Objects;
import javax.lang.model.type.TypeMirror;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.dataflow.analysis.Store;
import org.checkerframework.javacutil.AnnotationProvider;
/**
* A ClassName represents either a class literal or the occurrence of a class as part of a static
* field access or static method invocation.
*/
public class ClassName extends JavaExpression {
/** The string representation of the raw type of this. */
private final String typeString;
/**
* Creates a new ClassName object for the given type.
*
* @param type the type for the new ClassName. If it will represent a class literal, the type is
* declared primitive, void, or array of one of them. If it represents part of a static field
* access or static method invocation, the type is declared, type variable, or array
* (including array of primitive).
*/
public ClassName(TypeMirror type) {
super(type);
String typeString = type.toString();
if (typeString.endsWith(">")) {
typeString = typeString.substring(0, typeString.indexOf("<"));
}
this.typeString = typeString;
}
@Override
public boolean equals(@Nullable Object obj) {
if (!(obj instanceof ClassName)) {
return false;
}
ClassName other = (ClassName) obj;
return typeString.equals(other.typeString);
}
@Override
public int hashCode() {
return Objects.hash(typeString);
}
@Override
public String toString() {
return typeString + ".class";
}
@SuppressWarnings("unchecked") // generic cast
@Override
public @Nullable T containedOfClass(Class clazz) {
return getClass() == clazz ? (T) this : null;
}
@Override
public boolean isDeterministic(AnnotationProvider provider) {
return true;
}
@Override
public boolean isAssignableByOtherCode() {
return false;
}
@Override
public boolean isModifiableByOtherCode() {
return false;
}
@Override
public boolean syntacticEquals(JavaExpression je) {
if (!(je instanceof ClassName)) {
return false;
}
ClassName other = (ClassName) je;
return typeString.equals(other.typeString);
}
@Override
public boolean containsSyntacticEqualJavaExpression(JavaExpression other) {
return this.syntacticEquals(other);
}
@Override
public boolean containsModifiableAliasOf(Store> store, JavaExpression other) {
return false; // not modifiable
}
@Override
public R accept(JavaExpressionVisitor visitor, P p) {
return visitor.visitClassName(this, p);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy