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);
}
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";
}
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();
}
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;
}
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;
}
Aggregations