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