Package org.eclipse.jdt.core.dom

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


   */
  @SuppressWarnings("unchecked")
  public EnumDeclaration generateEnum(Classifier clazz, AST ast,
      CompilationUnit cu) {
    String className = getClassName(clazz);
    EnumDeclaration ed = ast.newEnumDeclaration();
    ed.modifiers().add(
        ast.newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD));
    ed.setName(ast.newSimpleName(className));
    cu.types().add(ed);
    return ed;
  }
View Full Code Here


  @SuppressWarnings("unchecked")
  @Test
  public void testGenerateConstantsIntegerWithNoParamNames() {
    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 slot = mock(Slot.class);

    Property property = mock(Property.class);
    Type type = mock(Type.class);

    EList<ValueSpecification> valueSpecifications = mock(EList.class);
    Iterator<ValueSpecification> valueSpecificationIter = mock(Iterator.class);
    ValueSpecification valueSpecification = 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(false);
    when(slotIter.next()).thenReturn(slot);
    when(slot.getDefiningFeature()).thenReturn(property);

    when(property.getType()).thenReturn(type);
    when(type.getName()).thenReturn("Integer");

    when(slot.getValues()).thenReturn(valueSpecifications);
    when(valueSpecifications.iterator()).thenReturn(valueSpecificationIter);
    when(valueSpecificationIter.hasNext()).thenReturn(true).thenReturn(
        false);
    when(valueSpecificationIter.next()).thenReturn(valueSpecification);
    when(valueSpecification.integerValue()).thenReturn(0);

    enumGenerator.generateConstants(enumeration, ast, ed);

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

  @SuppressWarnings("unchecked")
  @Test
  public void testGenerateConstantsStringWithNoParamNames() {
    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 slot = mock(Slot.class);

    Property property = mock(Property.class);
    Type type = mock(Type.class);

    EList<ValueSpecification> valueSpecifications = mock(EList.class);
    Iterator<ValueSpecification> valueSpecificationIter = mock(Iterator.class);
    ValueSpecification valueSpecification = 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(false);
    when(slotIter.next()).thenReturn(slot);
    when(slot.getDefiningFeature()).thenReturn(property);

    when(property.getType()).thenReturn(type);
    when(type.getName()).thenReturn("String");

    when(slot.getValues()).thenReturn(valueSpecifications);
    when(valueSpecifications.iterator()).thenReturn(valueSpecificationIter);
    when(valueSpecificationIter.hasNext()).thenReturn(true).thenReturn(
        false);
    when(valueSpecificationIter.next()).thenReturn(valueSpecification);
    when(valueSpecification.stringValue()).thenReturn("Home");

    enumGenerator.generateConstants(enumeration, ast, ed);

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

  @SuppressWarnings("unchecked")
  @Test
  public void testGenerateConstantsLongWithNoParamNames() {
    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 slot = mock(Slot.class);

    Property property = mock(Property.class);
    Type type = mock(Type.class);

    EList<ValueSpecification> valueSpecifications = mock(EList.class);
    Iterator<ValueSpecification> valueSpecificationIter = mock(Iterator.class);
    ValueSpecification valueSpecification = 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(false);
    when(slotIter.next()).thenReturn(slot);
    when(slot.getDefiningFeature()).thenReturn(property);

    when(property.getType()).thenReturn(type);
    when(type.getName()).thenReturn("Long");

    when(slot.getValues()).thenReturn(valueSpecifications);
    when(valueSpecifications.iterator()).thenReturn(valueSpecificationIter);
    when(valueSpecificationIter.hasNext()).thenReturn(true).thenReturn(
        false);
    when(valueSpecificationIter.next()).thenReturn(valueSpecification);
    when(valueSpecification.integerValue()).thenReturn(1);

    enumGenerator.generateConstants(enumeration, ast, ed);

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

  @SuppressWarnings("unchecked")
  @Test
  public void testGenerateConstantsBooleanWithNoParamNames() {
    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 slot = mock(Slot.class);

    Property property = mock(Property.class);
    Type type = mock(Type.class);

    EList<ValueSpecification> valueSpecifications = mock(EList.class);
    Iterator<ValueSpecification> valueSpecificationIter = mock(Iterator.class);
    ValueSpecification valueSpecification = 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(false);
    when(slotIter.next()).thenReturn(slot);
    when(slot.getDefiningFeature()).thenReturn(property);

    when(property.getType()).thenReturn(type);
    when(type.getName()).thenReturn("boolean");

    when(slot.getValues()).thenReturn(valueSpecifications);
    when(valueSpecifications.iterator()).thenReturn(valueSpecificationIter);
    when(valueSpecificationIter.hasNext()).thenReturn(true).thenReturn(
        false);
    when(valueSpecificationIter.next()).thenReturn(valueSpecification);
    when(valueSpecification.booleanValue()).thenReturn(true);

    enumGenerator.generateConstants(enumeration, ast, ed);

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

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

    EList<Property> properties = mock(EList.class);
    Iterator<Property> propertyIter = mock(Iterator.class);
    Property property = mock(Property.class);
    Type type = mock(Type.class);
View Full Code Here

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

    EList<Property> properties = mock(EList.class);
    Iterator<Property> propertyIter = mock(Iterator.class);
    Property property = mock(Property.class);
    Type type = mock(Type.class);
View Full Code Here

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

    EList<Property> properties = mock(EList.class);
    Iterator<Property> propertyIter = mock(Iterator.class);
    Property property = mock(Property.class);
    Type type = mock(Type.class);
View Full Code Here

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

    EList<Property> properties = mock(EList.class);
    Iterator<Property> propertyIter = mock(Iterator.class);
    Property property = mock(Property.class);
    Type type = mock(Type.class);
View Full Code Here

  @SuppressWarnings("unchecked")
  @Test
  public void testGenerateConstructorWithOneParameter() {
    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

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.