Search in sources :

Example 71 with PackageElement

use of javax.lang.model.element.PackageElement in project qpid-broker-j by apache.

the class ConfiguredObjectRegistrationGenerator method processAnnotatedElement.

private void processAnnotatedElement(final Elements elementUtils, final TypeElement annotationElement, final Element e) {
    if (e.getKind().equals(ElementKind.INTERFACE) || e.getKind().equals(ElementKind.CLASS)) {
        PackageElement packageElement = elementUtils.getPackageOf(e);
        String packageName = packageElement.getQualifiedName().toString();
        String className = e.getSimpleName().toString();
        AnnotationMirror annotation = getAnnotation(e, annotationElement);
        AnnotationValue registerValue = getAnnotationValue(annotation, "register");
        if (registerValue == null || (Boolean) registerValue.getValue()) {
            AnnotationValue typeValue = getAnnotationValue(annotation, "type");
            if (typeValue != null) {
                _typeMap.put(packageName + "." + className, (String) typeValue.getValue());
                processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "looking for " + packageName + "." + className);
                _categoryMap.put(packageName + "." + className, getCategory((TypeElement) e));
            }
            Set<String> classNames = _managedObjectClasses.get(packageName);
            if (classNames == null) {
                classNames = new HashSet<>();
                _managedObjectClasses.put(packageName, classNames);
            }
            classNames.add(className);
        }
    }
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) TypeElement(javax.lang.model.element.TypeElement) AnnotationValue(javax.lang.model.element.AnnotationValue) PackageElement(javax.lang.model.element.PackageElement)

Example 72 with PackageElement

use of javax.lang.model.element.PackageElement in project mapstruct by mapstruct.

the class ImmutablesBuilderProvider method asImmutableElement.

protected TypeElement asImmutableElement(TypeElement typeElement) {
    Element enclosingElement = typeElement.getEnclosingElement();
    StringBuilder builderQualifiedName = new StringBuilder(typeElement.getQualifiedName().length() + 17);
    if (enclosingElement.getKind() == ElementKind.PACKAGE) {
        builderQualifiedName.append(((PackageElement) enclosingElement).getQualifiedName().toString());
    } else {
        builderQualifiedName.append(((TypeElement) enclosingElement).getQualifiedName().toString());
    }
    if (builderQualifiedName.length() > 0) {
        builderQualifiedName.append(".");
    }
    builderQualifiedName.append("Immutable").append(typeElement.getSimpleName());
    return elementUtils.getTypeElement(builderQualifiedName);
}
Also used : TypeElement(javax.lang.model.element.TypeElement) PackageElement(javax.lang.model.element.PackageElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) PackageElement(javax.lang.model.element.PackageElement)

Example 73 with PackageElement

use of javax.lang.model.element.PackageElement in project j2objc by google.

the class JdtElements method getPackageOf.

@Override
public PackageElement getPackageOf(Element type) {
    Element owner = type.getEnclosingElement();
    while (owner != null) {
        type = owner;
        owner = type.getEnclosingElement();
    }
    return type instanceof PackageElement ? (PackageElement) type : null;
}
Also used : PackageElement(javax.lang.model.element.PackageElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) PackageElement(javax.lang.model.element.PackageElement)

Example 74 with PackageElement

use of javax.lang.model.element.PackageElement in project j2objc by google.

the class TreeConverter method convertCompilationUnit.

public static CompilationUnit convertCompilationUnit(Options options, JavacEnvironment env, JCTree.JCCompilationUnit javacUnit) {
    String sourceFilePath = getPath(javacUnit.getSourceFile());
    try {
        TreeConverter converter = new TreeConverter(javacUnit, env);
        JavaFileObject sourceFile = javacUnit.getSourceFile();
        String source = sourceFile.getCharContent(false).toString();
        String mainTypeName = FileUtil.getMainTypeName(sourceFile);
        converter.newUnit = new CompilationUnit(new TranslationEnvironment(options, env), sourceFilePath, mainTypeName, source);
        PackageElement pkg = javacUnit.packge != null ? javacUnit.packge : env.defaultPackage();
        converter.newUnit.setPackage(converter.convertPackage(pkg, Trees.instance(env.task())));
        for (JCTree type : javacUnit.getTypeDecls()) {
            TreeNode newNode = converter.convert(type);
            if (newNode.getKind() != TreeNode.Kind.EMPTY_STATEMENT) {
                converter.newUnit.addType((AbstractTypeDeclaration) newNode);
            }
        }
        addOcniComments(converter.newUnit, options.jsniWarnings());
        return converter.newUnit;
    } catch (Throwable e) {
        ErrorUtil.fatalError(e, sourceFilePath);
        return null;
    }
}
Also used : CompilationUnit(com.google.devtools.j2objc.ast.CompilationUnit) JavaFileObject(javax.tools.JavaFileObject) TranslationEnvironment(com.google.devtools.j2objc.util.TranslationEnvironment) TreeNode(com.google.devtools.j2objc.ast.TreeNode) JCTree(com.sun.tools.javac.tree.JCTree) PackageElement(javax.lang.model.element.PackageElement)

Example 75 with PackageElement

use of javax.lang.model.element.PackageElement in project j2objc by google.

the class GeneratedTypeBinding method newTypeBinding.

/**
   * Creates a new non-array type, extracting the package from the provided name.
   */
public static GeneratedTypeBinding newTypeBinding(String name, ITypeBinding superClass, boolean isInterface) {
    int idx = name.lastIndexOf('.');
    String packageName = idx < 0 ? "" : name.substring(0, idx);
    PackageElement packageElement = (PackageElement) BindingConverter.getElement(new GeneratedPackageBinding(packageName));
    name = name.substring(idx + 1);
    return new GeneratedTypeBinding(name, packageElement, superClass, isInterface, null);
}
Also used : PackageElement(javax.lang.model.element.PackageElement)

Aggregations

PackageElement (javax.lang.model.element.PackageElement)134 TypeElement (javax.lang.model.element.TypeElement)93 Element (javax.lang.model.element.Element)52 ExecutableElement (javax.lang.model.element.ExecutableElement)34 VariableElement (javax.lang.model.element.VariableElement)32 TypeSpec (com.squareup.javapoet.TypeSpec)20 IOException (java.io.IOException)17 HashSet (java.util.HashSet)13 TypeMirror (javax.lang.model.type.TypeMirror)13 AnnotationMirror (javax.lang.model.element.AnnotationMirror)12 JavaFileObject (javax.tools.JavaFileObject)12 ClassName (com.squareup.javapoet.ClassName)11 ArrayList (java.util.ArrayList)11 Set (java.util.Set)10 Elements (javax.lang.model.util.Elements)10 PrintWriter (java.io.PrintWriter)9 HashMap (java.util.HashMap)9 ParameterizedTypeName (com.squareup.javapoet.ParameterizedTypeName)8 Map (java.util.Map)8 Messager (javax.annotation.processing.Messager)8