Package org.eclipse.jdt.core.dom

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


  @SuppressWarnings("unchecked")
  @Test
  public void testGenerateConstructorWithTwoParameters() {
    AST ast = AST.newAST(AST.JLS3);
    CompilationUnit cu = ast.newCompilationUnit();
    EnumDeclaration ed = enumGenerator.generateEnum(clazz, ast, cu);

    EList<Property> firstProperties = mock(EList.class);
    Iterator<Property> firstPropertyIter = mock(Iterator.class);

    EList<Property> secondProperties = mock(EList.class);
View Full Code Here


  @SuppressWarnings("unchecked")
  @Test
  public void testGenerateContructorParameters() {
    AST ast = AST.newAST(AST.JLS3);
    CompilationUnit cu = ast.newCompilationUnit();
    EnumDeclaration ed = enumGenerator.generateEnum(clazz, ast, cu);
    MethodDeclaration md = ast.newMethodDeclaration();
    md.setConstructor(true);
    md.setName(ast.newSimpleName(clazz.getName()));
    md.modifiers().add(
        ast.newModifier(Modifier.ModifierKeyword.PRIVATE_KEYWORD));

    EList<Property> properties = mock(EList.class);
    Iterator<Property> propertyIter = mock(Iterator.class);
    Property propertyName = mock(Property.class);
    String name = "name";
    Type typeName = mock(Type.class);
    Property propertyCount = mock(Property.class);
    String count = "count";
    Type typeCount = mock(Type.class);

    EList<Comment> comments = mock(EList.class,
        Answers.RETURNS_DEEP_STUBS.get());

    when(clazz.getAttributes()).thenReturn(properties);
    when(properties.iterator()).thenReturn(propertyIter);
    when(propertyIter.hasNext()).thenReturn(true).thenReturn(true)
        .thenReturn(false);
    when(propertyIter.next()).thenReturn(propertyName).thenReturn(
        propertyCount);

    when(propertyName.getType()).thenReturn(typeName);
    when(propertyName.getName()).thenReturn(name);
    when(propertyName.getUpper()).thenReturn(1);
    when(propertyName.getLower()).thenReturn(1);
    when(propertyName.getOwnedComments()).thenReturn(comments);
    when(typeName.getName()).thenReturn("String");
    when(typeName.getQualifiedName()).thenReturn("String");

    when(propertyCount.getType()).thenReturn(typeCount);
    when(propertyCount.getName()).thenReturn(count);
    when(propertyCount.getUpper()).thenReturn(1);
    when(propertyCount.getLower()).thenReturn(1);
    when(propertyCount.getOwnedComments()).thenReturn(comments);
    when(typeCount.getName()).thenReturn("Integer");
    when(typeCount.getQualifiedName()).thenReturn("Integer");

    enumGenerator.generateContructorParameters(clazz, ast, md);

    ed.bodyDeclarations().add(md);

    assertEquals(
        "public enum Company {; private Company(String name,Integer count);\n}\n",
        cu.toString());
  }
View Full Code Here

  @SuppressWarnings("unchecked")
  @Test
  public void testGenerateConstantsWithConstructorParameterNamesAndWithFoundSlot() {
    AST ast = AST.newAST(AST.JLS3);
    CompilationUnit cu = ast.newCompilationUnit();
    EnumDeclaration ed = enumGenerator.generateEnum(clazz, ast, cu);

    Enumeration enumeration = mock(Enumeration.class);
    EList<EnumerationLiteral> enumLiterals = mock(EList.class);
    Iterator<EnumerationLiteral> enumIter = mock(Iterator.class);
    EnumerationLiteral enumLiteral = mock(EnumerationLiteral.class);

    EList<Slot> slots = mock(EList.class);
    Iterator<Slot> slotIter = mock(Iterator.class);
    Slot slot1 = mock(Slot.class);
    Slot slot2 = mock(Slot.class);

    Property property1 = mock(Property.class);
    Property property2 = mock(Property.class);
    Type type1 = mock(Type.class);
    Type type2 = mock(Type.class);

    EList<ValueSpecification> valueSpecifications1 = mock(EList.class);
    Iterator<ValueSpecification> valueSpecificationIter1 = mock(Iterator.class);
    EList<ValueSpecification> valueSpecifications2 = mock(EList.class);
    Iterator<ValueSpecification> valueSpecificationIter2 = mock(Iterator.class);
    ValueSpecification valueSpecification1 = mock(ValueSpecification.class);
    ValueSpecification valueSpecification2 = mock(ValueSpecification.class);

    when(enumeration.getOwnedLiterals()).thenReturn(enumLiterals);
    when(enumLiterals.iterator()).thenReturn(enumIter);
    when(enumIter.hasNext()).thenReturn(true).thenReturn(false);
    when(enumIter.next()).thenReturn(enumLiteral);
    when(enumLiteral.getName()).thenReturn("Home");

    when(enumLiteral.getSlots()).thenReturn(slots);
    when(slots.iterator()).thenReturn(slotIter);
    when(slotIter.hasNext()).thenReturn(true).thenReturn(true)
        .thenReturn(false);
    when(slotIter.next()).thenReturn(slot1).thenReturn(slot2);
    when(slot1.getDefiningFeature()).thenReturn(property1);
    when(slot2.getDefiningFeature()).thenReturn(property2);

    when(property1.getType()).thenReturn(type1);
    when(property2.getType()).thenReturn(type2);
    when(property1.getName()).thenReturn("type");
    when(property2.getName()).thenReturn("name");
    when(type1.getName()).thenReturn("boolean");
    when(type2.getName()).thenReturn("String");

    when(slot1.getValues()).thenReturn(valueSpecifications1);
    when(slot2.getValues()).thenReturn(valueSpecifications2);
    when(valueSpecifications1.iterator()).thenReturn(
        valueSpecificationIter1);
    when(valueSpecifications2.iterator()).thenReturn(
        valueSpecificationIter2);
    when(valueSpecificationIter1.hasNext()).thenReturn(true).thenReturn(
        false);
    when(valueSpecificationIter2.hasNext()).thenReturn(true).thenReturn(
        false);
    when(valueSpecificationIter1.next()).thenReturn(valueSpecification1);
    when(valueSpecificationIter2.next()).thenReturn(valueSpecification2);
    when(valueSpecification1.booleanValue()).thenReturn(true);
    when(valueSpecification2.stringValue()).thenReturn("Lofi");

    ArrayList<String> constructorParameterNames = new ArrayList<String>();
    constructorParameterNames.add("type");
    constructorParameterNames.add("name");
    enumGenerator.setConstructorParameterNames(constructorParameterNames);

    enumGenerator.generateConstants(enumeration, ast, ed);

    assertEquals("public enum Company {HOME(true,\"Lofi\")}\n",
        ed.toString());
  }
View Full Code Here

  @Test
  public void testGenerateConstantsWithConstructorParameterNamesAndWithSlotNotFound() {
    // TODO
    AST ast = AST.newAST(AST.JLS3);
    CompilationUnit cu = ast.newCompilationUnit();
    EnumDeclaration ed = enumGenerator.generateEnum(clazz, ast, cu);

    Enumeration enumeration = mock(Enumeration.class);
    EList<EnumerationLiteral> enumLiterals = mock(EList.class);
    Iterator<EnumerationLiteral> enumIter = mock(Iterator.class);
    EnumerationLiteral enumLiteral = mock(EnumerationLiteral.class);

    EList<Slot> slots1 = mock(EList.class);
    EList<Slot> slots2 = mock(EList.class);
    Iterator<Slot> slotIter1 = mock(Iterator.class);
    Iterator<Slot> slotIter2 = mock(Iterator.class);
    Slot slot1 = mock(Slot.class);
    Slot slot2 = mock(Slot.class);

    Property property1 = mock(Property.class);
    Property property2 = mock(Property.class);
    Type type1 = mock(Type.class);
    Type type2 = mock(Type.class);

    EList<ValueSpecification> valueSpecifications1 = mock(EList.class);
    Iterator<ValueSpecification> valueSpecificationIter1 = mock(Iterator.class);
    EList<ValueSpecification> valueSpecifications2 = mock(EList.class);
    Iterator<ValueSpecification> valueSpecificationIter2 = mock(Iterator.class);
    ValueSpecification valueSpecification1 = mock(ValueSpecification.class);
    ValueSpecification valueSpecification2 = mock(ValueSpecification.class);

    when(enumeration.getOwnedLiterals()).thenReturn(enumLiterals);
    when(enumLiterals.iterator()).thenReturn(enumIter);
    when(enumIter.hasNext()).thenReturn(true).thenReturn(false);
    when(enumIter.next()).thenReturn(enumLiteral);
    when(enumLiteral.getName()).thenReturn("Home");

    when(enumLiteral.getSlots()).thenReturn(slots1).thenReturn(slots2);
    when(slots1.iterator()).thenReturn(slotIter1);
    when(slots2.iterator()).thenReturn(slotIter2);
    when(slotIter1.hasNext()).thenReturn(true).thenReturn(true)
        .thenReturn(false);
    when(slotIter2.hasNext()).thenReturn(true).thenReturn(true)
        .thenReturn(false);
    when(slotIter1.next()).thenReturn(slot1).thenReturn(slot2);
    when(slotIter2.next()).thenReturn(slot1).thenReturn(slot2);
    when(slot1.getDefiningFeature()).thenReturn(property1);
    when(slot2.getDefiningFeature()).thenReturn(property2);

    when(property1.getType()).thenReturn(type1);
    when(property2.getType()).thenReturn(type2);
    when(property1.getName()).thenReturn("type");
    when(property2.getName()).thenReturn("name");
    when(type1.getName()).thenReturn("boolean");
    when(type2.getName()).thenReturn("String");

    when(slot1.getValues()).thenReturn(valueSpecifications1);
    when(slot2.getValues()).thenReturn(valueSpecifications2);
    when(valueSpecifications1.iterator()).thenReturn(
        valueSpecificationIter1);
    when(valueSpecifications2.iterator()).thenReturn(
        valueSpecificationIter2);
    when(valueSpecificationIter1.hasNext()).thenReturn(true).thenReturn(
        false);
    when(valueSpecificationIter2.hasNext()).thenReturn(true).thenReturn(
        false);
    when(valueSpecificationIter1.next()).thenReturn(valueSpecification1);
    when(valueSpecificationIter2.next()).thenReturn(valueSpecification2);
    when(valueSpecification1.booleanValue()).thenReturn(true);
    when(valueSpecification2.stringValue()).thenReturn("Lofi");

    // Cannot find the parameter name of the constructor!
    ArrayList<String> constructorParameterNames = new ArrayList<String>();
    constructorParameterNames.add("typeX");
    constructorParameterNames.add("nameY");
    enumGenerator.setConstructorParameterNames(constructorParameterNames);

    enumGenerator.generateConstants(enumeration, ast, ed);

    assertEquals("public enum Company {HOME(true,\"Lofi\")}\n",
        ed.toString());
  }
View Full Code Here

                }
            }

            // process EnumDeclaration
            if (abstractTypeDeclaration instanceof EnumDeclaration) {
                EnumDeclaration enumDeclaration = (EnumDeclaration)abstractTypeDeclaration;

                // is a class top level type
                EnumMetadata enumMetadata = TypeMetadata.enumType(JavaMetadataUtil.getName(enumDeclaration.getName()));
                processModifiersOfTypeDeclaration(enumDeclaration, enumMetadata);

                // Store the enum values
                List<EnumConstantDeclaration> enumValues = enumDeclaration.enumConstants();
                for (EnumConstantDeclaration enumValue : enumValues) {
                    enumMetadata.getValues().add(enumValue.getName().getIdentifier());
                }

                // Enums don't have superclasses

                // detect the interfaces, if any
                for (Type superInterfaceType : (List<Type>)enumDeclaration.superInterfaceTypes()) {
                    enumMetadata.getInterfaceNames().add(getTypeName(superInterfaceType));
                }

                /*
                 * It would be nice to be able to reuse the convenience methods from AbstractTypeDeclaration,
                 * but they don't exist in EnumDeclaration.  So we improvise!
                 */

                List<BodyDeclaration> bodyDecls = enumDeclaration.bodyDeclarations();
                for (BodyDeclaration bodyDecl : bodyDecls) {
                    if (bodyDecl instanceof FieldDeclaration) {
                        // fields of the class top level type
                        FieldMetadata fieldMetadata = getFieldMetadataFrom((FieldDeclaration)bodyDecl);
                        enumMetadata.getFields().add(fieldMetadata);
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

            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

        : node.getAnonymousClassDeclaration().resolveBinding();

    hardDep(tb);
    print(" = new " + CName.qualified(tb, true));

    EnumDeclaration enumDeclaration = (EnumDeclaration) node.getParent();

    consArgs(null, node.arguments(), node.resolveConstructorBinding(), tb,
        CName.of(node.resolveVariable()), enumDeclaration
            .enumConstants().indexOf(node));

    println(";");

    if (node.getAnonymousClassDeclaration() != null) {
View Full Code Here

        ImplWriter iw = new ImplWriter(getRoot(unit), this, ui,
            makeTypeInfo(td));

        iw.write(td);
      } else if (type instanceof EnumDeclaration) {
        EnumDeclaration td = (EnumDeclaration) type;

        ImplWriter iw = new ImplWriter(getRoot(unit), this, ui,
            makeTypeInfo(td));

        iw.write(td);
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.