/* * @see ASTVisitor#visit(AnonymousClassDeclaration) */ @Override public boolean visit(AnonymousClassDeclaration node) { this.fBuffer.append("{"); // $NON-NLS-1$ List<BodyDeclaration> bodyDeclarations = node.bodyDeclarations(); for (Iterator<BodyDeclaration> it = bodyDeclarations.iterator(); it.hasNext(); ) { BodyDeclaration b = it.next(); b.accept(this); } this.fBuffer.append("}"); // $NON-NLS-1$ return false; }
/* * @see ASTVisitor#visit(AnnotationTypeDeclaration) * @since 3.0 */ @Override public boolean visit(AnnotationTypeDeclaration node) { if (node.getJavadoc() != null) { node.getJavadoc().accept(this); } printModifiers(node.modifiers()); this.fBuffer.append("@interface "); // $NON-NLS-1$ node.getName().accept(this); this.fBuffer.append(" {"); // $NON-NLS-1$ for (Iterator<BodyDeclaration> it = node.bodyDeclarations().iterator(); it.hasNext(); ) { BodyDeclaration d = it.next(); d.accept(this); } this.fBuffer.append("}"); // $NON-NLS-1$ return false; }
@Override public void merge(AnnotationMemberDeclaration remote, MergeEngine configuration) { super.merge(remote, configuration); setType((Type) configuration.apply(getType(), remote.getType(), Type.class)); setDefaultValue( (Expression) configuration.apply(getDefaultValue(), remote.getDefaultValue(), Expression.class)); }
@Override public void merge(FieldDeclaration remote, MergeEngine configuration) { super.merge(remote, configuration); setType((Type) configuration.apply(getType(), remote.getType(), Type.class)); List<VariableDeclarator> resultList = new LinkedList<VariableDeclarator>(); configuration.apply( getVariables(), remote.getVariables(), resultList, VariableDeclarator.class); setVariables(resultList); }
/* * @see ASTVisitor#visit(EnumDeclaration) * @since 3.0 */ @Override public boolean visit(EnumDeclaration node) { if (node.getJavadoc() != null) { node.getJavadoc().accept(this); } printModifiers(node.modifiers()); this.fBuffer.append("enum "); // $NON-NLS-1$ node.getName().accept(this); this.fBuffer.append(" "); // $NON-NLS-1$ if (!node.superInterfaceTypes().isEmpty()) { this.fBuffer.append("implements "); // $NON-NLS-1$ for (Iterator<Type> it = node.superInterfaceTypes().iterator(); it.hasNext(); ) { Type t = it.next(); t.accept(this); if (it.hasNext()) { this.fBuffer.append(", "); // $NON-NLS-1$ } } this.fBuffer.append(" "); // $NON-NLS-1$ } this.fBuffer.append("{"); // $NON-NLS-1$ for (Iterator<EnumConstantDeclaration> it = node.enumConstants().iterator(); it.hasNext(); ) { EnumConstantDeclaration d = it.next(); d.accept(this); // enum constant declarations do not include punctuation if (it.hasNext()) { // enum constant declarations are separated by commas this.fBuffer.append(", "); // $NON-NLS-1$ } } if (!node.bodyDeclarations().isEmpty()) { this.fBuffer.append("; "); // $NON-NLS-1$ for (Iterator<BodyDeclaration> it = node.bodyDeclarations().iterator(); it.hasNext(); ) { BodyDeclaration d = it.next(); d.accept(this); // other body declarations include trailing punctuation } } this.fBuffer.append("}"); // $NON-NLS-1$ return false; }
private void printMembers(List<BodyDeclaration> members, Object arg) { for (BodyDeclaration member : members) { member.accept(this, arg); } }
private void addMember(BodyDeclaration bodyDeclaration) { bodyDeclaration.setParentNode(type.get()); type.get().getMembers().add(bodyDeclaration); }
@Override public void validateInner() { super.validateInner(); Preconditions.checkState(annotations.isEmpty()); }
/* * @see ASTVisitor#visit(TypeDeclaration) */ @Override public boolean visit(TypeDeclaration node) { if (node.getJavadoc() != null) { node.getJavadoc().accept(this); } if (node.getAST().apiLevel() >= JLS3) { printModifiers(node.modifiers()); } this.fBuffer.append(node.isInterface() ? "interface " : "class "); // $NON-NLS-2$//$NON-NLS-1$ node.getName().accept(this); if (node.getAST().apiLevel() >= JLS3) { if (!node.typeParameters().isEmpty()) { this.fBuffer.append("<"); // $NON-NLS-1$ for (Iterator<TypeParameter> it = node.typeParameters().iterator(); it.hasNext(); ) { TypeParameter t = it.next(); t.accept(this); if (it.hasNext()) { this.fBuffer.append(","); // $NON-NLS-1$ } } this.fBuffer.append(">"); // $NON-NLS-1$ } } this.fBuffer.append(" "); // $NON-NLS-1$ if (node.getAST().apiLevel() >= JLS3) { if (node.getSuperclassType() != null) { this.fBuffer.append("extends "); // $NON-NLS-1$ node.getSuperclassType().accept(this); this.fBuffer.append(" "); // $NON-NLS-1$ } if (!node.superInterfaceTypes().isEmpty()) { this.fBuffer.append( node.isInterface() ? "extends " : "implements "); // $NON-NLS-2$//$NON-NLS-1$ for (Iterator<Type> it = node.superInterfaceTypes().iterator(); it.hasNext(); ) { Type t = it.next(); t.accept(this); if (it.hasNext()) { this.fBuffer.append(", "); // $NON-NLS-1$ } } this.fBuffer.append(" "); // $NON-NLS-1$ } } this.fBuffer.append("{"); // $NON-NLS-1$ BodyDeclaration prev = null; for (Iterator<BodyDeclaration> it = node.bodyDeclarations().iterator(); it.hasNext(); ) { BodyDeclaration d = it.next(); if (prev instanceof EnumConstantDeclaration) { // enum constant declarations do not include punctuation if (d instanceof EnumConstantDeclaration) { // enum constant declarations are separated by commas this.fBuffer.append(", "); // $NON-NLS-1$ } else { // semicolon separates last enum constant declaration from // first class body declarations this.fBuffer.append("; "); // $NON-NLS-1$ } } d.accept(this); prev = d; } this.fBuffer.append("}"); // $NON-NLS-1$ return false; }
public static List<BodyDeclaration> asDeclarationSublist(BodyDeclaration node) { List<BodyDeclaration> declarations = getBodyDeclarations(node.getParent()); int index = declarations.indexOf(node); assert index != -1; return declarations.subList(index, index + 1); }