Search in sources :

Example 41 with PackageElement

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

the class GeneratedTypeElement method newEmulatedType.

private static GeneratedTypeElement newEmulatedType(String qualifiedName, ElementKind kind, TypeMirror superclass) {
    int idx = qualifiedName.lastIndexOf('.');
    String packageName = idx < 0 ? "" : qualifiedName.substring(0, idx);
    PackageElement packageElement = new GeneratedPackageElement(packageName);
    return new GeneratedTypeElement(qualifiedName.substring(idx + 1), kind, packageElement, superclass, NestingKind.TOP_LEVEL, null, false, false);
}
Also used : PackageElement(javax.lang.model.element.PackageElement)

Example 42 with PackageElement

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

the class HeaderMap method get.

public String get(TypeElement type) {
    String explicitHeader = ElementUtil.getHeader(type);
    if (explicitHeader != null) {
        return explicitHeader;
    }
    String qualifiedName = ElementUtil.getQualifiedName(type);
    String mappedHeader = map.get(qualifiedName);
    if (mappedHeader != null) {
        return mappedHeader;
    }
    String name = inferSourceName(type);
    PackageElement pkg = ElementUtil.getPackage(type);
    return outputDirFromPackage(pkg) + name + ".h";
}
Also used : PackageElement(javax.lang.model.element.PackageElement)

Example 43 with PackageElement

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

the class SignatureGenerator method createJniFunctionSignature.

public String createJniFunctionSignature(ExecutableElement method) {
    // Mangle function name as described in JNI specification.
    // http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/design.html#wp615
    StringBuilder sb = new StringBuilder();
    sb.append("Java_");
    String methodName = ElementUtil.getName(method);
    TypeElement declaringClass = ElementUtil.getDeclaringClass(method);
    PackageElement pkg = ElementUtil.getPackage(declaringClass);
    if (pkg != null && !pkg.isUnnamed()) {
        String pkgName = pkg.getQualifiedName().toString();
        for (String part : pkgName.split("\\.")) {
            sb.append(part);
            sb.append('_');
        }
    }
    jniMangleClass(declaringClass, sb);
    sb.append('_');
    sb.append(jniMangle(methodName));
    // Check whether the method is overloaded.
    int nameCount = 0;
    for (ExecutableElement m : ElementUtil.getExecutables(declaringClass)) {
        if (methodName.equals(ElementUtil.getName(m)) && ElementUtil.isNative(m)) {
            nameCount++;
        }
    }
    if (nameCount >= 2) {
        // Overloaded native methods, append JNI-mangled parameter types.
        sb.append("__");
        for (VariableElement param : method.getParameters()) {
            String type = createTypeSignature(typeUtil.erasure(param.asType()));
            sb.append(jniMangle(type));
        }
    }
    return sb.toString();
}
Also used : TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) PackageElement(javax.lang.model.element.PackageElement) VariableElement(javax.lang.model.element.VariableElement)

Example 44 with PackageElement

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

the class ExternalAnnotationInjector method visit.

@Override
public boolean visit(PackageDeclaration node) {
    PackageElement element = node.getPackageElement();
    String elementName = element.getQualifiedName() + ".package-info";
    AClass annotatedElement = annotatedAst.classes.get(elementName);
    if (annotatedElement != null) {
        recordAnnotations(element, annotatedElement.tlAnnotationsHere);
    }
    return false;
}
Also used : AClass(scenelib.annotations.el.AClass) PackageElement(javax.lang.model.element.PackageElement)

Example 45 with PackageElement

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

the class Metaservices method validated.

@Nullable
private TypeElement validated(Element element) {
    Element enclosingElement = element.getEnclosingElement();
    if (element.getKind() == ElementKind.CLASS && element.getModifiers().contains(Modifier.PUBLIC) && enclosingElement != null) {
        if (enclosingElement.getKind() == ElementKind.PACKAGE && !element.getModifiers().contains(Modifier.ABSTRACT) && !((PackageElement) enclosingElement).isUnnamed()) {
            return (TypeElement) element;
        }
        if (enclosingElement.getKind() == ElementKind.CLASS && element.getModifiers().contains(Modifier.STATIC)) {
            return (TypeElement) element;
        }
    }
    processing().getMessager().printMessage(Diagnostic.Kind.ERROR, "Element annotated with @Metainf.Service annotation should be public top-level non-abstract or static class in a package", element);
    return null;
}
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) Nullable(javax.annotation.Nullable)

Aggregations

PackageElement (javax.lang.model.element.PackageElement)133 TypeElement (javax.lang.model.element.TypeElement)92 Element (javax.lang.model.element.Element)51 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