use of com.google.devtools.j2objc.types.GeneratedTypeElement in project j2objc by google.
the class BindingConverter method unwrapGeneratedElement.
private static IBinding unwrapGeneratedElement(GeneratedElement element) {
IBinding binding = generatedBindingCache.get(element);
if (binding != null) {
return binding;
}
if (element instanceof GeneratedVariableElement) {
binding = new GeneratedVariableBinding((GeneratedVariableElement) element);
generatedBindingCache.put(element, binding);
return binding;
}
if (element instanceof GeneratedExecutableElement) {
binding = new GeneratedMethodBinding((GeneratedExecutableElement) element);
generatedBindingCache.put(element, binding);
return binding;
}
if (element instanceof GeneratedTypeElement) {
throw new AssertionError("not supported");
}
if (element instanceof GeneratedPackageElement) {
binding = new GeneratedPackageBinding(((GeneratedPackageElement) element).getName());
generatedBindingCache.put(element, binding);
return binding;
}
throw new AssertionError("unknown generated element kind");
}
use of com.google.devtools.j2objc.types.GeneratedTypeElement in project j2objc by google.
the class TreeConverter method convertClassDeclaration.
private TreeNode convertClassDeclaration(ClassTree node, TreePath parent) {
TreePath path = getTreePath(parent, node);
TypeElement element = (TypeElement) getElement(path);
// to support our different declaration nodes.
if (element.getKind() == ElementKind.ANNOTATION_TYPE) {
throw new AssertionError("Annotation type declaration tree conversion not implemented");
}
TypeDeclaration newNode = convertClassDeclarationHelper(node, parent);
newNode.setInterface(node.getKind() == Kind.INTERFACE || node.getKind() == Kind.ANNOTATION_TYPE);
if (ElementUtil.isAnonymous(element)) {
TypeMirror classType = getTypeMirror(path);
if (!classType.getAnnotationMirrors().isEmpty()) {
newUnit.getEnv().elementUtil().mapElementType(element, classType);
} else {
// With javac 12 and above, annotations are no longer part of the supertype,
// so check to see if a mutated type that has them is necessary.
GeneratedTypeElement newElement = GeneratedTypeElement.mutableCopy(element);
boolean annotationFound = copyAnnotations(node.getExtendsClause(), path, newNode, newElement);
for (Tree clause : node.getImplementsClause()) {
annotationFound |= copyAnnotations(clause, path, newNode, newElement);
}
if (annotationFound) {
newUnit.getEnv().elementUtil().mapElementType(element, newElement.asType());
}
}
}
return newNode;
}
use of com.google.devtools.j2objc.types.GeneratedTypeElement in project j2objc by google.
the class DeadCodeEliminator method removeDeadClasses.
/**
* Remove empty classes marked as dead. This needs to be done after translation
* to avoid inner class references in the AST returned by DeadCodeEliminator.
*/
public static void removeDeadClasses(CompilationUnit unit, CodeReferenceMap deadCodeMap) {
ElementUtil elementUtil = unit.getEnv().elementUtil();
Iterator<AbstractTypeDeclaration> iter = unit.getTypes().iterator();
while (iter.hasNext()) {
AbstractTypeDeclaration type = iter.next();
TypeElement typeElement = type.getTypeElement();
if (!ElementUtil.isGeneratedAnnotation(typeElement)) {
if (deadCodeMap.containsClass(typeElement, elementUtil)) {
type.setDeadClass(true);
} else {
// Keep class, remove dead interfaces.
if (typeElement.getInterfaces().size() > 0) {
GeneratedTypeElement replacement = GeneratedTypeElement.mutableCopy(typeElement);
for (TypeElement intrface : ElementUtil.getInterfaces(typeElement)) {
if (!deadCodeMap.containsClass(intrface, elementUtil)) {
replacement.addInterface(intrface.asType());
}
}
if (typeElement.getInterfaces().size() > replacement.getInterfaces().size()) {
type.setTypeElement(replacement);
}
}
}
}
}
}
Aggregations