/*
   * Elements returned by next() are BodyDeclaration or Annotation instances.
   */
  private Iterator<ASTNode> getReplacementScope() throws JavaModelException {
    boolean declPredecessorReached = false;

    Collection<ASTNode> scope = new ArrayList<>();

    AbstractTypeDeclaration containingType = getContainingTypeDeclarationNode();
    if (containingType instanceof EnumDeclaration) {
      // replace in all enum constants bodies
      EnumDeclaration enumDeclaration = (EnumDeclaration) containingType;
      scope.addAll(enumDeclaration.enumConstants());
    }

    for (Iterator<IExtendedModifier> iter = containingType.modifiers().iterator();
        iter.hasNext(); ) {
      IExtendedModifier modifier = iter.next();
      if (modifier instanceof Annotation) {
        scope.add((ASTNode) modifier);
      }
    }

    for (Iterator<BodyDeclaration> bodyDeclarations = containingType.bodyDeclarations().iterator();
        bodyDeclarations.hasNext(); ) {
      BodyDeclaration bodyDeclaration = bodyDeclarations.next();

      if (bodyDeclaration == getNodeToInsertConstantDeclarationAfter())
        declPredecessorReached = true;

      if (insertFirst()
          || declPredecessorReached
          || !isStaticFieldOrStaticInitializer(bodyDeclaration)) scope.add(bodyDeclaration);
    }
    return scope.iterator();
  }
示例#2
0
 @Override
 public boolean visit(EnumDeclaration node) {
   int flags = node.getModifiers();
   if (Modifier.isPublic(flags)) {
     clazz.setVisibility(Visibility.PUBLIC);
   } else {
     clazz.setVisibility(Visibility.PACKAGE_PRIVATE);
   }
   clazz.setEnum(true);
   for (Object constant : node.enumConstants()) {
     fields.add(new OutlineField(constant.toString(), clazz));
   }
   clazz.checkVisibility(flags);
   clazz.setImg();
   return super.visit(node);
 }
 /*
  * @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;
 }