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 checker Show documentation
Show all versions of checker Show documentation
The Checker Framework enhances Java's type system to
make it more powerful and useful. This lets software developers
detect and prevent errors in their Java programs.
The Checker Framework includes compiler plug-ins ("checkers")
that find bugs or verify their absence. It also permits you to
write your own compiler plug-ins.
package org.checkerframework.dataflow.expression;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.dataflow.analysis.Store;
import org.checkerframework.javacutil.AnnotationProvider;
import java.util.Objects;
import javax.lang.model.type.TypeMirror;
/**
* 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";
}
@Override
public boolean containsOfClass(Class extends JavaExpression> clazz) {
return getClass() == clazz;
}
@Override
public boolean isDeterministic(AnnotationProvider provider) {
return true;
}
@Override
public boolean isUnassignableByOtherCode() {
return true;
}
@Override
public boolean isUnmodifiableByOtherCode() {
return true;
}
@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 - 2024 Weber Informatics LLC | Privacy Policy