use of com.google.devtools.j2objc.ast.BodyDeclaration in project j2objc by google.
the class TreeConverter method convertAbstractTypeDeclaration.
private TreeNode convertAbstractTypeDeclaration(JCTree.JCClassDecl node, AbstractTypeDeclaration newNode) {
convertBodyDeclaration(node, node.getModifiers(), newNode, node.sym);
List<BodyDeclaration> bodyDeclarations = new ArrayList<>();
for (JCTree bodyDecl : node.getMembers()) {
Object member = convert(bodyDecl);
if (member instanceof BodyDeclaration) {
// Not true for enum constants.
bodyDeclarations.add((BodyDeclaration) member);
} else if (member instanceof Block) {
JCTree.JCBlock javacBlock = (JCTree.JCBlock) bodyDecl;
Block block = (Block) member;
bodyDeclarations.add(new Initializer(block, javacBlock.isStatic()));
}
}
return newNode.setName(convertSimpleName(node.sym, node.sym.asType(), getNamePosition(node))).setTypeElement(node.sym).setBodyDeclarations(bodyDeclarations);
}
use of com.google.devtools.j2objc.ast.BodyDeclaration in project j2objc by google.
the class TreeConverter method convertEnum.
private TreeNode convertEnum(JCTree.JCClassDecl node) {
if (node.sym.isAnonymous()) {
return convertClassDeclaration(node).setPosition(getPosition(node));
}
EnumDeclaration newNode = (EnumDeclaration) new EnumDeclaration();
convertBodyDeclaration(node, node.getModifiers(), newNode, node.sym);
newNode.setName(convertSimpleName(node.sym, node.type, getNamePosition(node))).setTypeElement(node.sym);
for (JCTree bodyDecl : node.getMembers()) {
if (bodyDecl.getKind() == Kind.VARIABLE) {
TreeNode var = convertVariableDeclaration((JCTree.JCVariableDecl) bodyDecl);
if (var.getKind() == TreeNode.Kind.ENUM_CONSTANT_DECLARATION) {
newNode.addEnumConstant((EnumConstantDeclaration) var);
} else {
newNode.addBodyDeclaration((BodyDeclaration) var);
}
} else if (bodyDecl.getKind() == Kind.BLOCK) {
JCTree.JCBlock javacBlock = (JCTree.JCBlock) bodyDecl;
Block block = (Block) convert(javacBlock);
newNode.addBodyDeclaration(new Initializer(block, javacBlock.isStatic()));
} else {
newNode.addBodyDeclaration((BodyDeclaration) convert(bodyDecl));
}
}
return newNode;
}
use of com.google.devtools.j2objc.ast.BodyDeclaration in project j2objc by google.
the class PrivateDeclarationResolver method visit.
@Override
public boolean visit(CompilationUnit node) {
// Map the types by their elements.
for (AbstractTypeDeclaration typeNode : node.getTypes()) {
typeMap.put(typeNode.getTypeElement(), typeNode);
}
// Identify types that are public by their declaration.
for (AbstractTypeDeclaration typeNode : node.getTypes()) {
TypeElement typeElement = typeNode.getTypeElement();
if (!ElementUtil.isPrivateInnerType(typeElement)) {
addPublicType(typeElement);
}
}
// public because they are exposed by a field or method from another type.
while (!publicNodesToVisit.isEmpty()) {
AbstractTypeDeclaration publicNode = publicNodesToVisit.remove(publicNodesToVisit.size() - 1);
publicNode.setHasPrivateDeclaration(false);
for (BodyDeclaration decl : publicNode.getBodyDeclarations()) {
decl.accept(this);
}
}
// declarations as private.
for (AbstractTypeDeclaration typeNode : node.getTypes()) {
if (!publicTypes.contains(typeNode.getTypeElement())) {
typeNode.setHasPrivateDeclaration(true);
for (BodyDeclaration decl : typeNode.getBodyDeclarations()) {
decl.setHasPrivateDeclaration(true);
}
}
}
return false;
}
use of com.google.devtools.j2objc.ast.BodyDeclaration in project j2objc by google.
the class NilCheckResolver method visitType.
private boolean visitType(AbstractTypeDeclaration node) {
for (BodyDeclaration decl : node.getBodyDeclarations()) {
decl.accept(this);
}
pushFirstScope();
for (Statement stmt : node.getClassInitStatements()) {
stmt.accept(this);
}
popLastScope();
return false;
}
use of com.google.devtools.j2objc.ast.BodyDeclaration in project j2objc by google.
the class AnnotationRewriter method endVisit.
@Override
public void endVisit(AnnotationTypeDeclaration node) {
TypeElement type = node.getTypeElement();
if (!ElementUtil.isGeneratedAnnotation(type)) {
return;
}
List<AnnotationTypeMemberDeclaration> members = TreeUtil.getAnnotationMembers(node);
List<BodyDeclaration> bodyDecls = node.getBodyDeclarations();
Map<ExecutableElement, VariableElement> fieldElements = createMemberFields(node, members);
addMemberProperties(node, members, fieldElements);
addDefaultAccessors(node, members);
bodyDecls.add(createAnnotationTypeMethod(type));
bodyDecls.add(createDescriptionMethod(type, members, fieldElements));
addConstructor(node, fieldElements);
addEqualsMethod(node);
addHashCodeMethod(node);
}
Aggregations