use of javax.lang.model.element.Element in project commons by twitter.
the class CmdLineProcessor method processParsers.
private void processParsers(Set<? extends Element> elements) {
TypeElement parserType = typeElement(Parser.class);
for (Element element : elements) {
if (element.getKind() != ElementKind.CLASS) {
error("Found an @ArgParser annotation on a non-class %s", element);
} else {
TypeElement parser = (TypeElement) element;
if (!isAssignable(parser, Parser.class)) {
error("Found an @ArgParser annotation on a non-Parser %s", element);
return;
}
@Nullable String parsedType = getTypeArgument(parser, parserType);
if (parsedType != null) {
String parserClassName = getBinaryName(parser);
getBuilder(parserClassName).addParser(parsedType, getBinaryName(parser));
}
}
}
}
use of javax.lang.model.element.Element in project commons by twitter.
the class CmdLineProcessor method processVerifiers.
private void processVerifiers(Set<? extends Element> elements) {
TypeElement verifierType = typeElement(Verifier.class);
TypeElement verifierForType = typeElement(VerifierFor.class);
for (Element element : elements) {
if (element.getKind() != ElementKind.CLASS) {
error("Found a @VerifierFor annotation on a non-class %s", element);
} else {
TypeElement verifier = (TypeElement) element;
if (!isAssignable(verifier, Verifier.class)) {
error("Found a @Verifier annotation on a non-Verifier %s", element);
return;
}
String verifierClassName = getBinaryName(verifier);
@Nullable AnnotationMirror verifierFor = getAnnotationMirror(verifier, verifierForType);
if (verifierFor != null) {
@Nullable TypeElement verifyAnnotationType = getClassType(verifierFor, "value", null);
if (verifyAnnotationType != null) {
@Nullable String verifiedType = getTypeArgument(verifier, verifierType);
if (verifiedType != null) {
String verifyAnnotationClassName = elementUtils.getBinaryName(verifyAnnotationType).toString();
getBuilder(verifierClassName).addVerifier(verifiedType, verifyAnnotationClassName, verifierClassName);
}
}
}
}
}
}
use of javax.lang.model.element.Element in project classindex by atteo.
the class ClassIndexProcessor method process.
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
try {
for (Element element : roundEnv.getRootElements()) {
if (!(element instanceof TypeElement)) {
continue;
}
final PackageElement packageElement = getPackage(element);
element.accept(new ElementScanner6<Void, Void>() {
@Override
public Void visitType(TypeElement typeElement, Void o) {
try {
for (AnnotationMirror mirror : typeElement.getAnnotationMirrors()) {
final TypeElement annotationElement = (TypeElement) mirror.getAnnotationType().asElement();
storeAnnotation(annotationElement, typeElement);
}
indexSupertypes(typeElement, typeElement);
if (packageElement != null) {
storeClassFromPackage(packageElement, typeElement);
}
} catch (IOException e) {
messager.printMessage(Diagnostic.Kind.ERROR, "[ClassIndexProcessor] " + e.getMessage());
}
return super.visitType(typeElement, o);
}
}, null);
}
if (!roundEnv.processingOver()) {
return false;
}
writeIndexFiles(ClassIndex.SUBCLASS_INDEX_PREFIX, subclassMap);
writeIndexFiles(ClassIndex.ANNOTATED_INDEX_PREFIX, annotatedMap);
for (Map.Entry<String, Set<String>> entry : packageMap.entrySet()) {
writeSimpleNameIndexFile(entry.getValue(), entry.getKey().replace(".", "/") + "/" + ClassIndex.PACKAGE_INDEX_NAME);
}
} catch (IOException e) {
messager.printMessage(Diagnostic.Kind.ERROR, "[ClassIndexProcessor] Can't write index file: " + e.getMessage());
} catch (Throwable e) {
e.printStackTrace();
messager.printMessage(Diagnostic.Kind.ERROR, "[ClassIndexProcessor] Internal error: " + e.getMessage());
}
return false;
}
use of javax.lang.model.element.Element in project bazel by bazelbuild.
the class Analysis method callTransferFunction.
/**
* Call the transfer function for node {@code node}, and set that node as
* current node first.
*/
protected TransferResult<A, S> callTransferFunction(Node node, TransferInput<A, S> store) {
if (node.isLValue()) {
// store.hasTwoStores()), or is the following correct?
return new RegularTransferResult<A, S>(null, store.getRegularStore());
}
store.node = node;
currentNode = node;
TransferResult<A, S> transferResult = node.accept(transferFunction, store);
currentNode = null;
if (node instanceof ReturnNode) {
// save a copy of the store to later check if some property held at
// a given return statement
storesAtReturnStatements.put((ReturnNode) node, transferResult);
}
if (node instanceof AssignmentNode) {
// store the flow-refined value for effectively final local variables
AssignmentNode assignment = (AssignmentNode) node;
Node lhst = assignment.getTarget();
if (lhst instanceof LocalVariableNode) {
LocalVariableNode lhs = (LocalVariableNode) lhst;
Element elem = lhs.getElement();
if (ElementUtils.isEffectivelyFinal(elem)) {
finalLocalValues.put(elem, transferResult.getResultValue());
}
}
}
return transferResult;
}
use of javax.lang.model.element.Element in project bazel by bazelbuild.
the class ElementUtils method enclosingPackage.
/**
* Returns the innermost package element enclosing the given element.
* The same effect as {@link javax.lang.model.util.Elements#getPackageOf(Element)}.
* Returns the element itself if it is a package.
*
* @param elem the enclosed element of a package
* @return the innermost package element
*
*/
public static PackageElement enclosingPackage(final Element elem) {
Element result = elem;
while (result != null && result.getKind() != ElementKind.PACKAGE) {
/*@Nullable*/
Element encl = result.getEnclosingElement();
result = encl;
}
return (PackageElement) result;
}
Aggregations