use of javax.lang.model.util.Types in project react4j by react4j.
the class ReactProcessor method determineLifecycleMethods.
private void determineLifecycleMethods(@Nonnull final TypeElement typeElement, @Nonnull final ComponentDescriptor descriptor) {
/*
* Get the list of lifecycle methods that have been overridden by typeElement
* a parent class, or by a default method method implemented by typeElement or
* a parent class.
*/
final Collection<ExecutableElement> lifecycleMethods = getComponentLifecycleMethods().values();
final Elements elementUtils = processingEnv.getElementUtils();
final Types typeUtils = processingEnv.getTypeUtils();
final TypeElement componentType = elementUtils.getTypeElement(Constants.COMPONENT_CLASSNAME);
final List<MethodDescriptor> overriddenLifecycleMethods = // Get all methods on type parent classes, and default methods from interfaces
ProcessorUtil.getMethods(typeElement, processingEnv.getTypeUtils()).stream().filter(m -> lifecycleMethods.stream().anyMatch(l -> elementUtils.overrides(m, l, typeElement))).filter(m -> m.getEnclosingElement() != componentType).map(m -> new MethodDescriptor(m, (ExecutableType) typeUtils.asMemberOf(descriptor.getDeclaredType(), m))).collect(Collectors.toList());
descriptor.setLifecycleMethods(overriddenLifecycleMethods);
}
use of javax.lang.model.util.Types in project checker-framework by typetools.
the class CFAbstractStore method canAlias.
/**
* Can the objects {@code a} and {@code b} be aliases? Returns a conservative answer (i.e.,
* returns {@code true} if not enough information is available to determine aliasing).
*/
@Override
public boolean canAlias(FlowExpressions.Receiver a, FlowExpressions.Receiver b) {
TypeMirror tb = b.getType();
TypeMirror ta = a.getType();
Types types = analysis.getTypes();
return types.isSubtype(ta, tb) || types.isSubtype(tb, ta);
}
use of javax.lang.model.util.Types in project checker-framework by typetools.
the class DefaultTypeHierarchy method castedAsSuper.
/**
* Calls asSuper and casts the result to the same type as the input supertype
*
* @param subtype subtype to be transformed to supertype
* @param supertype supertype that subtype is transformed to
* @param <T> the type of supertype and return type
* @return subtype as an instance of supertype
*/
@SuppressWarnings("unchecked")
public static <T extends AnnotatedTypeMirror> T castedAsSuper(final AnnotatedTypeMirror subtype, final T supertype) {
final Types types = subtype.atypeFactory.getProcessingEnv().getTypeUtils();
final Elements elements = subtype.atypeFactory.getProcessingEnv().getElementUtils();
if (subtype.getKind() == TypeKind.NULL) {
// Make a copy of the supertype so that if supertype is a composite type, the
// returned type will be fully annotated. (For example, if sub is @C null and super is
// @A List<@B String>, then the returned type is @C List<@B String>.)
T copy = (T) supertype.deepCopy();
copy.replaceAnnotations(subtype.getAnnotations());
return copy;
}
final T asSuperType = AnnotatedTypes.asSuper(subtype.atypeFactory, subtype, supertype);
fixUpRawTypes(subtype, asSuperType, supertype, types);
// @1 Enum<@2 E>
if (asSuperType != null && isEnum(asSuperType) && isDeclarationOfJavaLangEnum(types, elements, supertype)) {
final AnnotatedDeclaredType resultAtd = ((AnnotatedDeclaredType) supertype).deepCopy();
resultAtd.clearAnnotations();
resultAtd.addAnnotations(asSuperType.getAnnotations());
final AnnotatedDeclaredType asSuperAdt = (AnnotatedDeclaredType) asSuperType;
if (resultAtd.getTypeArguments().size() > 0 && asSuperAdt.getTypeArguments().size() > 0) {
final AnnotatedTypeMirror sourceTypeArg = asSuperAdt.getTypeArguments().get(0);
final AnnotatedTypeMirror resultTypeArg = resultAtd.getTypeArguments().get(0);
resultTypeArg.clearAnnotations();
resultTypeArg.addAnnotations(sourceTypeArg.getAnnotations());
return (T) resultAtd;
}
}
return asSuperType;
}
use of javax.lang.model.util.Types in project checker-framework by typetools.
the class IrrelevantTypeAnnotator method scan.
@Override
protected Void scan(AnnotatedTypeMirror type, Void aVoid) {
switch(type.getKind()) {
case TYPEVAR:
case WILDCARD:
case EXECUTABLE:
case INTERSECTION:
case UNION:
case NULL:
case NONE:
case PACKAGE:
case VOID:
return super.scan(type, aVoid);
default:
}
Types types = typeFactory.getContext().getTypeUtils();
TypeMirror typeMirror = type.getUnderlyingType();
if (TypesUtils.isPrimitive(typeMirror)) {
typeMirror = types.boxedClass((PrimitiveType) typeMirror).asType();
}
boolean shouldAnnotate = true;
if (allFoundRelevantTypes.contains(typeMirror)) {
shouldAnnotate = false;
} else if (typeMirror.getKind() == TypeKind.DECLARED) {
for (TypeMirror supportedType : relevantTypes) {
if (types.isSubtype(typeMirror, supportedType)) {
shouldAnnotate = false;
allFoundRelevantTypes.add(typeMirror);
break;
}
}
} else if (typeMirror.getKind() == TypeKind.ARRAY) {
shouldAnnotate = arraysAreRelevant;
if (arraysAreRelevant) {
allFoundRelevantTypes.add(typeMirror);
}
}
if (shouldAnnotate) {
type.addMissingAnnotations(annotations);
}
return super.scan(type, aVoid);
}
use of javax.lang.model.util.Types in project graal by oracle.
the class MatchProcessor method processMatchableNode.
private void processMatchableNode(Element element, TypeElement topDeclaringType, MatchableNode matchable, AnnotationMirror mirror) throws GraalError {
logMessage("processMatchableNode %s %s %s\n", topDeclaringType, element, matchable);
String nodeClass;
String nodePackage;
TypeMirror nodeClassMirror = null;
try {
matchable.nodeClass();
} catch (MirroredTypeException e) {
nodeClassMirror = e.getTypeMirror();
}
if (nodeClassMirror == null) {
throw new GraalError("Can't get mirror for node class %s", element);
}
if (nodeClassMirror.toString().equals(MatchableNode.class.getName())) {
nodeClass = topDeclaringType.getQualifiedName().toString();
} else {
nodeClass = nodeClassMirror.toString();
}
TypeElement typeElement = processingEnv.getElementUtils().getTypeElement(nodeClass);
if (typeElement == null) {
errorMessage(element, mirror, "Class \"%s\" cannot be resolved to a type", nodeClass);
return;
}
nodePackage = findPackage(typeElement);
assert nodeClass.startsWith(nodePackage);
nodeClass = nodeClass.substring(nodePackage.length() + 1);
assert nodeClass.endsWith("Node");
String shortName = nodeClass.substring(0, nodeClass.length() - 4);
Types typeUtils = processingEnv.getTypeUtils();
TypeElement nodeClassElement = (TypeElement) typeUtils.asElement(nodeClassMirror);
for (String input : matchable.inputs()) {
boolean ok = false;
TypeElement current = nodeClassElement;
while (!ok && current != null) {
for (Element fieldElement : ElementFilter.fieldsIn(current.getEnclosedElements())) {
if (fieldElement.getSimpleName().toString().equals(input)) {
ok = true;
break;
}
}
TypeMirror theSuper = current.getSuperclass();
current = (TypeElement) typeUtils.asElement(theSuper);
}
if (!ok) {
errorMessage(element, mirror, "Input named \"%s\" doesn't exist in %s", input, nodeClassElement.getSimpleName());
}
}
declareType(nodeClassMirror, shortName, nodeClass, nodePackage, matchable.inputs(), matchable.commutative(), matchable.shareable(), element);
}
Aggregations