use of javax.lang.model.element.AnnotationMirror in project checker-framework by typetools.
the class FormatterTreeUtil method isFormatCall.
/**
* Returns true if {@code node} is a call to a method annotated with {@code @FormatMethod}.
*/
public boolean isFormatCall(MethodInvocationTree node, AnnotatedTypeFactory atypeFactory) {
ExecutableElement method = TreeUtils.elementFromUse(node);
AnnotationMirror anno = atypeFactory.getDeclAnnotation(method, FormatMethod.class);
return anno != null;
}
use of javax.lang.model.element.AnnotationMirror in project checker-framework by typetools.
the class FormatterVisitor method commonAssignmentCheck.
@Override
protected void commonAssignmentCheck(AnnotatedTypeMirror varType, AnnotatedTypeMirror valueType, Tree valueTree, @CompilerMessageKey String errorKey) {
super.commonAssignmentCheck(varType, valueType, valueTree, errorKey);
AnnotationMirror rhs = valueType.getAnnotationInHierarchy(atypeFactory.UNKNOWNFORMAT);
AnnotationMirror lhs = varType.getAnnotationInHierarchy(atypeFactory.UNKNOWNFORMAT);
// For method calls, it is issued in visitMethodInvocation.
if (AnnotationUtils.areSameIgnoringValues(rhs, atypeFactory.FORMAT) && AnnotationUtils.areSameIgnoringValues(lhs, atypeFactory.FORMAT)) {
ConversionCategory[] rhsArgTypes = atypeFactory.treeUtil.formatAnnotationToCategories(rhs);
ConversionCategory[] lhsArgTypes = atypeFactory.treeUtil.formatAnnotationToCategories(lhs);
if (rhsArgTypes.length < lhsArgTypes.length) {
checker.report(org.checkerframework.framework.source.Result.warning("format.missing.arguments", varType.toString(), valueType.toString()), valueTree);
}
}
}
use of javax.lang.model.element.AnnotationMirror in project Rocket by mozilla-tw.
the class GlideGenerator method overrideGlideStaticMethod.
private MethodSpec overrideGlideStaticMethod(ExecutableElement methodToOverride) {
List<? extends VariableElement> parameters = methodToOverride.getParameters();
TypeElement element = (TypeElement) processingEnv.getTypeUtils().asElement(methodToOverride.getReturnType());
MethodSpec.Builder builder = MethodSpec.methodBuilder(methodToOverride.getSimpleName().toString()).addModifiers(Modifier.PUBLIC, Modifier.STATIC).addJavadoc(processorUtil.generateSeeMethodJavadoc(methodToOverride)).addParameters(Lists.transform(parameters, new Function<VariableElement, ParameterSpec>() {
@Override
public ParameterSpec apply(VariableElement input) {
return ParameterSpec.get(input);
}
}));
TypeElement visibleForTestingType = processingEnv.getElementUtils().getTypeElement(VISIBLE_FOR_TESTING_QUALIFIED_NAME);
for (AnnotationMirror mirror : methodToOverride.getAnnotationMirrors()) {
builder.addAnnotation(AnnotationSpec.get(mirror));
// See #1977.
if (mirror.getAnnotationType().asElement().equals(visibleForTestingType)) {
builder.addAnnotation(AnnotationSpec.builder(ClassName.get(SUPPRESS_LINT_PACKAGE_NAME, SUPPRESS_LINT_CLASS_NAME)).addMember("value", "$S", "VisibleForTests").build());
}
}
boolean returnsValue = element != null;
if (returnsValue) {
builder.returns(ClassName.get(element));
}
String code = returnsValue ? "return " : "";
code += "$T.$N(";
List<Object> args = new ArrayList<>();
args.add(ClassName.get(glideType));
args.add(methodToOverride.getSimpleName());
if (!parameters.isEmpty()) {
for (VariableElement param : parameters) {
code += "$L, ";
args.add(param.getSimpleName());
}
code = code.substring(0, code.length() - 2);
}
code += ")";
builder.addStatement(code, args.toArray(new Object[0]));
return builder.build();
}
use of javax.lang.model.element.AnnotationMirror in project Rocket by mozilla-tw.
the class RequestBuilderGenerator method generateRequestBuilderOverride.
/**
* Generates an override of a particular method in {@link com.bumptech.glide.RequestBuilder} that
* returns {@link com.bumptech.glide.RequestBuilder} so that it returns our generated subclass
* instead.
*/
private MethodSpec generateRequestBuilderOverride(ExecutableElement methodToOverride) {
// We've already verified that this method returns a RequestBuilder and RequestBuilders have
// exactly one type argument, so this is safe unless those assumptions change.
TypeMirror typeArgument = ((DeclaredType) methodToOverride.getReturnType()).getTypeArguments().get(0);
ParameterizedTypeName generatedRequestBuilderOfType = ParameterizedTypeName.get(generatedRequestBuilderClassName, ClassName.get(typeArgument));
MethodSpec.Builder builder = MethodSpec.overriding(methodToOverride).returns(generatedRequestBuilderOfType).addCode(CodeBlock.builder().add("return ($T) super.$N(", generatedRequestBuilderOfType, methodToOverride.getSimpleName()).add(FluentIterable.from(methodToOverride.getParameters()).transform(new Function<VariableElement, String>() {
@Override
public String apply(VariableElement input) {
return input.getSimpleName().toString();
}
}).join(Joiner.on(", "))).add(");\n").build());
for (AnnotationMirror mirror : methodToOverride.getAnnotationMirrors()) {
builder.addAnnotation(AnnotationSpec.get(mirror));
}
return builder.build();
}
use of javax.lang.model.element.AnnotationMirror in project JikesRVM by JikesRVM.
the class SysCallVisitor method getMatchingAnnotationsFromElement.
private AnnotationMirror getMatchingAnnotationsFromElement(Element element, String fullyQualifiedAnnotationName) {
List<? extends AnnotationMirror> annotationsOnElement = element.getAnnotationMirrors();
for (AnnotationMirror annotationMirror : annotationsOnElement) {
DeclaredType declType = annotationMirror.getAnnotationType();
String fullyQualifiedName = declType.toString();
if (fullyQualifiedName.equals(fullyQualifiedAnnotationName)) {
return annotationMirror;
}
}
return null;
}
Aggregations