Package org.eclipse.jdt.core.dom

Examples of org.eclipse.jdt.core.dom.EnumDeclaration


          if (type.getName().getFullyQualifiedName()
              .equals(getProperty(ResultProperty.NAME)))
            typeDec = type;
        }
        if (typeBodyDec.getNodeType() == BodyDeclaration.ENUM_DECLARATION) {
          EnumDeclaration type = (EnumDeclaration) typeBodyDec;
          if (type.getName().getFullyQualifiedName()
              .equals(getProperty(ResultProperty.NAME)))
            typeDec = type;
        }
      }
      return typeDec;
View Full Code Here


          String reportedName = getProperty(ResultProperty.NAME);
          if (typeName.equals(reportedName))
            declaration = type;
        }
        if (typeBodyDec.getNodeType() == BodyDeclaration.ENUM_DECLARATION) {
          EnumDeclaration type = (EnumDeclaration) typeBodyDec;
          if (type.getName().getFullyQualifiedName()
              .equals(getProperty(ResultProperty.NAME)))
            declaration = type;
        }
      }
      return copyProperties(declaration);
View Full Code Here

        else
          logger.warning("Get null TypeMetric when initializing.");

        addInnerClasses(typeDeclaration, type);
      } else if (declaration instanceof EnumDeclaration) {
        EnumDeclaration enumDeclaration = (EnumDeclaration) declaration;
        IType type = ((ICompilationUnit) getJavaElement())
            .getType(enumDeclaration.getName().getIdentifier());
        AbstractMetricElement next = new EnumMetric(type
            .getHandleIdentifier(), enumDeclaration, analyzer);
        if (next != null)
          addChild(next);
        else
View Full Code Here

      IType[] types = type.getTypes();

      for (int i = 0; i < types.length; i++) {
        AbstractMetricElement inner = null;
        if (types[i].isEnum()) {
          EnumDeclaration enumDecl = null;
          for (ASTNode decl : bodyDecls) {
            if (decl instanceof EnumDeclaration) {
              enumDecl = (EnumDeclaration) decl;
              if (enumDecl.getName().toString().compareTo(
                  types[i].getElementName()) == 0) {
                break;
              }
            }
          }
View Full Code Here

  private static EnumDeclaration createNewEnumDeclaration(AST ast,
      SimpleName name, Collection enumConstantDeclarationCollection,
      Object[] enumTypeModifierCollection) {

    final EnumDeclaration enumDecl = ast.newEnumDeclaration();
    enumDecl.setName(name);
    for (int i = 0; i < enumTypeModifierCollection.length; i++)
      enumDecl.modifiers().add(enumTypeModifierCollection[i]);
    enumDecl.enumConstants().addAll(enumConstantDeclarationCollection);
    return enumDecl;
  }
View Full Code Here

       ******************************************************************/
      if (!(Flags.isPublic(flag) || Flags.isPackageDefault(flag)))
        status
            .addFatalError(Messages.ConvertConstantsToEnumRefactoring_EnumTypeMustHaveCorrectVisibility);

      EnumDeclaration newEnumDeclaration = null;
      // only add modifier if it is not package default.
      if (!Flags.isPackageDefault(flag)) {
        final Modifier newModifier = ast
            .newModifier(Modifier.ModifierKeyword
                .fromFlagValue(flag));

        newEnumDeclaration = createNewEnumDeclaration(ast, ast
            .newSimpleName((String) this.simpleTypeNames.get(col)),
            enumConstantDeclarationCollection,
            new Object[] { newModifier });
      } else
        newEnumDeclaration = createNewEnumDeclaration(ast, ast
            .newSimpleName((String) this.simpleTypeNames.get(col)),
            enumConstantDeclarationCollection, new Object[] {});

      // TODO [bm] pretty dirty hack to workaround 16: Refactoring should not use UI components for code changes
      //       http://code.google.com/p/constants-to-enum-eclipse-plugin/issues/detail?id=16
      final NewEnumWizardPage[] result = new NewEnumWizardPage[1];
      Display.getDefault().syncExec(new Runnable() {
        public void run() {
          result[0]= new NewEnumWizardPage();
        }
      });
      NewEnumWizardPage page = result[0];
      page.setTypeName((String) this.simpleTypeNames.get(col), false);

      final IPackageFragmentRoot root = this.getPackageFragmentRoot();
      page.setPackageFragmentRoot(root, false);

      final IPackageFragment pack = this.getPackageFragment(
          (String) this.packageNames.get(col), monitor);
      page.setPackageFragment(pack, false);

      /*******************************************************************
       * * TODO: This is somewhat of a dirty workaround. Basically, I am
       * creating a new Enum type only to replace the root AST node. If
       * you have any better ideas please let me know!
       ******************************************************************/
      /*******************************************************************
       * TODO: Need a way of inserting this new type such that it appears
       * in the text changes for rollback purposes, etc.
       ******************************************************************/
      try {
        page.createType(monitor);
      } catch (final InterruptedException E) {
        status.addFatalError(E.getMessage());
      }

      // Modify the newly created enum type.
      final IType newEnumType = page.getCreatedType();
      final CompilationUnit node = (CompilationUnit) Util.getASTNode(
          newEnumType, monitor);

      final ASTRewrite astRewrite = ASTRewrite.create(node.getAST());
      final ImportRewrite importRewrite = ImportRewrite
          .create(node, true);

      final EnumDeclaration oldEnumDeclaration = (EnumDeclaration) node
          .types().get(0);

      // Add imports for annotations to the enum constants.
      for (final Iterator eit = newEnumDeclaration.enumConstants()
          .iterator(); eit.hasNext();) {
View Full Code Here

            return new JavaClassImpl(enclosingType, document, unit, typeDeclaration);
         }
      }
      else if (declaration instanceof EnumDeclaration)
      {
         EnumDeclaration enumDeclaration = (EnumDeclaration) declaration;
         return new JavaEnumImpl(enclosingType, document, unit, enumDeclaration);
      }
      else if (declaration instanceof AnnotationTypeDeclaration)
      {
         AnnotationTypeDeclaration annotationTypeDeclaration = (AnnotationTypeDeclaration) declaration;
View Full Code Here

   @SuppressWarnings("unchecked")
   public EnumConstant<JavaEnum> addEnumConstant(final String declaration)
   {
      EnumConstantImpl<JavaEnum> enumConst = new EnumConstantImpl<JavaEnum>(this, declaration);

      EnumDeclaration enumDeclaration = (EnumDeclaration) getBodyDeclaration();
      List<EnumConstantDeclaration> constants = enumDeclaration.enumConstants();
      constants.add((EnumConstantDeclaration) enumConst.getInternal());

      return enumConst;
   }
View Full Code Here

   @SuppressWarnings("unchecked")
   public EnumConstant<JavaEnum> addEnumConstant(final String declaration)
   {
      EnumConstantImpl<JavaEnum> enumConst = new EnumConstantImpl<JavaEnum>(this, declaration);

      EnumDeclaration enumDeclaration = (EnumDeclaration) getBodyDeclaration();
      List<EnumConstantDeclaration> constants = enumDeclaration.enumConstants();
      constants.add((EnumConstantDeclaration) enumConst.getInternal());

      return enumConst;
   }
View Full Code Here

            return new JavaClassImpl(enclosingType, document, unit, typeDeclaration);
         }
      }
      else if (declaration instanceof EnumDeclaration)
      {
         EnumDeclaration enumDeclaration = (EnumDeclaration) declaration;
         return new JavaEnumImpl(enclosingType, document, unit, enumDeclaration);
      }
      else if (declaration instanceof AnnotationTypeDeclaration)
      {
         AnnotationTypeDeclaration annotationTypeDeclaration = (AnnotationTypeDeclaration) declaration;
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.core.dom.EnumDeclaration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.