use of javax.lang.model.element.PackageElement in project java-common-lib by sosy-lab.
the class OptionAnnotationProcessor method returnPackagePrefixCompletions.
private Iterable<? extends Completion> returnPackagePrefixCompletions(Element element, String userText) {
List<Completion> packages = new ArrayList<>();
PackageElement pkg = elementUtils().getPackageOf(element);
if (!pkg.isUnnamed()) {
@Var String name = pkg.getQualifiedName().toString();
do {
if (!name.startsWith(userText)) {
break;
}
packages.add(Completions.of(name));
int pos = name.lastIndexOf('.');
name = name.substring(0, Math.max(pos, 0));
} while (!name.isEmpty());
}
return packages;
}
use of javax.lang.model.element.PackageElement in project ballerina by ballerina-lang.
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) {
log.error(e.getMessage(), e);
messager.printMessage(Diagnostic.Kind.ERROR, "[ClassIndexProcessor] Internal error: " + e.getMessage());
}
return false;
}
use of javax.lang.model.element.PackageElement in project graal by oracle.
the class MatchProcessor method createFiles.
private void createFiles(MatchRuleDescriptor info) {
String pkg = ((PackageElement) info.topDeclaringType.getEnclosingElement()).getQualifiedName().toString();
Name topDeclaringClass = info.topDeclaringType.getSimpleName();
String matchStatementClassName = topDeclaringClass + "_" + MatchStatementSet.class.getSimpleName();
Element[] originatingElements = info.originatingElements.toArray(new Element[info.originatingElements.size()]);
Types typeUtils = typeUtils();
Filer filer = processingEnv.getFiler();
try (PrintWriter out = createSourceFile(pkg, matchStatementClassName, filer, originatingElements)) {
out.println("// CheckStyle: stop header check");
out.println("// CheckStyle: stop line length check");
out.println("// GENERATED CONTENT - DO NOT EDIT");
out.println("// Source: " + topDeclaringClass + ".java");
out.println("package " + pkg + ";");
out.println("");
out.println("import java.util.*;");
out.println("import " + MatchStatementSet.class.getPackage().getName() + ".*;");
out.println("import " + NodeMatchRules.class.getName() + ";");
out.println("import " + Position.class.getName() + ";");
out.println("import " + ServiceProvider.class.getName() + ";");
for (String p : info.requiredPackages) {
out.println("import " + p + ".*;");
}
out.println("");
out.println("@" + ServiceProvider.class.getSimpleName() + "(" + MatchStatementSet.class.getSimpleName() + ".class)");
out.println("public class " + matchStatementClassName + " implements " + MatchStatementSet.class.getSimpleName() + " {");
out.println();
// Generate declarations for the wrapper class to invoke the code generation methods.
for (MethodInvokerItem invoker : info.invokers.getValues()) {
StringBuilder args = new StringBuilder();
StringBuilder types = new StringBuilder();
int count = invoker.fields.size();
int index = 0;
for (VariableElement arg : invoker.fields) {
args.append('"');
args.append(arg.getSimpleName());
args.append('"');
types.append(String.format("(%s) args[%s]", fullClassName(typeUtils.asElement(arg.asType())), index++));
if (count-- > 1) {
args.append(", ");
types.append(", ");
}
}
out.printf(" private static final String[] %s = new String[] {%s};\n", invoker.argumentsListName(), args);
out.printf(" private static final class %s implements MatchGenerator {\n", invoker.wrapperClass());
out.printf(" static MatchGenerator instance = new %s();\n", invoker.wrapperClass());
out.printf(" @Override\n");
out.printf(" public ComplexMatchResult match(NodeMatchRules nodeMatchRules, Object...args) {\n");
out.printf(" return ((%s) nodeMatchRules).%s(%s);\n", invoker.nodeLIRBuilderClass, invoker.methodName, types);
out.printf(" }\n");
out.printf(" @Override\n");
out.printf(" public String getName() {\n");
out.printf(" return \"%s\";\n", invoker.methodName);
out.printf(" }\n");
out.printf(" }\n");
out.println();
}
String desc = MatchStatement.class.getSimpleName();
out.println(" @Override");
out.println(" public Class<? extends NodeMatchRules> forClass() {");
out.println(" return " + topDeclaringClass + ".class;");
out.println(" }");
out.println();
out.println(" @Override");
out.println(" public List<" + desc + "> statements() {");
out.println(" // Checkstyle: stop ");
for (String positionDeclaration : info.positionDeclarations) {
out.println(" " + positionDeclaration);
}
out.println();
out.println(" List<" + desc + "> statements = Collections.unmodifiableList(Arrays.asList(");
int i = 0;
for (MatchRuleItem matchRule : info.matchRules) {
String comma = i == info.matchRules.size() - 1 ? "" : ",";
out.printf(" %s%s\n", matchRule.ruleBuilder(), comma);
i++;
}
out.println(" ));");
out.println(" // Checkstyle: resume");
out.println(" return statements;");
out.println(" }");
out.println();
out.println("}");
}
}
use of javax.lang.model.element.PackageElement in project glide by bumptech.
the class AppModuleProcessor method getIndexedClassNames.
@SuppressWarnings("unchecked")
private FoundIndexedClassNames getIndexedClassNames(PackageElement glideGenPackage) {
Set<String> glideModules = new HashSet<>();
Set<String> extensions = new HashSet<>();
List<? extends Element> glideGeneratedElements = glideGenPackage.getEnclosedElements();
for (Element indexer : glideGeneratedElements) {
Index annotation = indexer.getAnnotation(Index.class);
// that we can safely ignore.
if (annotation != null) {
Collections.addAll(glideModules, annotation.modules());
Collections.addAll(extensions, annotation.extensions());
}
}
processorUtil.debugLog("Found GlideModules: " + glideModules);
return new FoundIndexedClassNames(glideModules, extensions);
}
use of javax.lang.model.element.PackageElement in project arez by arez.
the class ArezProcessor method process.
private void process(@Nonnull final Element element) throws IOException, ArezProcessorException {
final PackageElement packageElement = processingEnv.getElementUtils().getPackageOf(element);
final TypeElement typeElement = (TypeElement) element;
final ComponentDescriptor descriptor = parse(packageElement, typeElement);
emitTypeSpec(descriptor.getPackageName(), descriptor.buildType(processingEnv.getTypeUtils()));
if (descriptor.shouldGenerateComponentDaggerModule()) {
emitTypeSpec(descriptor.getPackageName(), descriptor.buildComponentDaggerModule());
}
if (descriptor.hasRepository()) {
emitTypeSpec(descriptor.getPackageName(), descriptor.buildRepository(processingEnv.getTypeUtils()));
}
}
Aggregations