public static Consumer<TypeDeclaration> asInterface(final boolean value) { return td -> td.setInterface(value); }
/** * Creates an unparented class declaration node owned by this AST. * The name of the class is an unspecified, but legal, name; * no modifiers; no doc comment; no superclass or superinterfaces; * and an empty class body. * <p> * To create an interface, use this method and then call * <code>TypeDeclaration.setInterface(true)</code>. * </p> * * @return a new unparented type declaration node */ public TypeDeclaration newTypeDeclaration() { TypeDeclaration result = new TypeDeclaration(this); result.setInterface(false); return result; }
/** * Creates an unparented class declaration node owned by this AST. * The name of the class is an unspecified, but legal, name; * no modifiers; no doc comment; no superclass or superinterfaces; * and an empty class body. * <p> * To create an interface, use this method and then call * <code>TypeDeclaration.setInterface(true)</code>. * </p> * * @return a new unparented type declaration node */ public TypeDeclaration newTypeDeclaration() { TypeDeclaration result = new TypeDeclaration(this); result.setInterface(false); return result; }
/** * Creates an unparented class declaration node owned by this AST. * The name of the class is an unspecified, but legal, name; * no modifiers; no doc comment; no superclass or superinterfaces; * and an empty class body. * <p> * To create an interface, use this method and then call * <code>TypeDeclaration.setInterface(true)</code>. * </p> * * @return a new unparented type declaration node */ public TypeDeclaration newTypeDeclaration() { TypeDeclaration result = new TypeDeclaration(this); result.setInterface(false); return result; }
/** * Creates an unparented class declaration node owned by this AST. * The name of the class is an unspecified, but legal, name; * no modifiers; no doc comment; no superclass or superinterfaces; * and an empty class body. * <p> * To create an interface, use this method and then call * <code>TypeDeclaration.setInterface(true)</code>. * </p> * * @return a new unparented type declaration node */ public TypeDeclaration newTypeDeclaration() { TypeDeclaration result = new TypeDeclaration(this); result.setInterface(false); return result; }
/** * Creates an unparented class declaration node owned by this AST. * The name of the class is an unspecified, but legal, name; * no modifiers; no doc comment; no superclass or superinterfaces; * and an empty class body. * <p> * To create an interface, use this method and then call * <code>TypeDeclaration.setInterface(true)</code>. * </p> * * @return a new unparented type declaration node */ public TypeDeclaration newTypeDeclaration() { TypeDeclaration result = new TypeDeclaration(this); result.setInterface(false); return result; }
/** * Creates an unparented class declaration node owned by this AST. * The name of the class is an unspecified, but legal, name; * no modifiers; no doc comment; no superclass or superinterfaces; * and an empty class body. * <p> * To create an interface, use this method and then call * <code>TypeDeclaration.setInterface(true)</code>. * </p> * * @return a new unparented type declaration node */ public TypeDeclaration newTypeDeclaration() { TypeDeclaration result = new TypeDeclaration(this); result.setInterface(false); return result; }
final boolean internalGetSetBooleanProperty(SimplePropertyDescriptor property, boolean get, boolean value) { if (property == INTERFACE_PROPERTY) { if (get) { return isInterface(); } else { setInterface(value); return false; } } // allow default implementation to flag the error return super.internalGetSetBooleanProperty(property, get, value); }
final boolean internalGetSetBooleanProperty(SimplePropertyDescriptor property, boolean get, boolean value) { if (property == INTERFACE_PROPERTY) { if (get) { return isInterface(); } else { setInterface(value); return false; } } // allow default implementation to flag the error return super.internalGetSetBooleanProperty(property, get, value); }
final boolean internalGetSetBooleanProperty(SimplePropertyDescriptor property, boolean get, boolean value) { if (property == INTERFACE_PROPERTY) { if (get) { return isInterface(); } else { setInterface(value); return false; } } // allow default implementation to flag the error return super.internalGetSetBooleanProperty(property, get, value); }
final boolean internalGetSetBooleanProperty(SimplePropertyDescriptor property, boolean get, boolean value) { if (property == INTERFACE_PROPERTY) { if (get) { return isInterface(); } else { setInterface(value); return false; } } // allow default implementation to flag the error return super.internalGetSetBooleanProperty(property, get, value); }
final boolean internalGetSetBooleanProperty(SimplePropertyDescriptor property, boolean get, boolean value) { if (property == INTERFACE_PROPERTY) { if (get) { return isInterface(); } else { setInterface(value); return false; } } // allow default implementation to flag the error return super.internalGetSetBooleanProperty(property, get, value); }
@Override final boolean internalGetSetBooleanProperty(SimplePropertyDescriptor property, boolean get, boolean value) { if (property == INTERFACE_PROPERTY) { if (get) { return isInterface(); } else { setInterface(value); return false; } } // allow default implementation to flag the error return super.internalGetSetBooleanProperty(property, get, value); }
/** * Create a type declaration. * * @param cname class name * @param isenum Java 5 enum class flag * @return type declaration */ private AbstractTypeDeclaration createClass(String cname, boolean isenum) { AbstractTypeDeclaration abstype; if (isenum) { abstype = m_ast.newEnumDeclaration(); } else { TypeDeclaration type = m_ast.newTypeDeclaration(); type.setInterface(false); abstype = type; } abstype.modifiers().add(m_ast.newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD)); abstype.setName(m_ast.newSimpleName(cname)); return abstype; }
/** * Generate the Exception Class. * * @param clazz * the UML class * @param ast * the JDT Java AST * @param cu * the generated Java compilation unit * @return TypeDeclaration JDT */ @SuppressWarnings("unchecked") public TypeDeclaration generateClass(Classifier clazz, AST ast, CompilationUnit cu) { String className = getClassName(clazz); TypeDeclaration td = ast.newTypeDeclaration(); td.setInterface(false); td.modifiers().add( ast.newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD)); td.setName(ast.newSimpleName(className)); // Add inheritance generateClassInheritance(clazz, ast, td); // Add template params generateClassTemplateParams(clazz, ast, td); cu.types().add(td); return td; }
@SuppressWarnings("unchecked") @Test public void testGenerateClassWithTemplate() { TemplateSignature templateSignature = mock(TemplateSignature.class); EList<TemplateParameter> templateParameters = mock(EList.class, Answers.RETURNS_DEEP_STUBS.get()); when(clazz.getOwnedTemplateSignature()).thenReturn(templateSignature); when(templateSignature.getParameters()).thenReturn(templateParameters); AST ast = AST.newAST(AST.JLS3); CompilationUnit cu = ast.newCompilationUnit(); TypeDeclaration td = ast.newTypeDeclaration(); td.setInterface(true); Modifier modifier = ast .newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD); td.modifiers().add(modifier); td.setName(ast.newSimpleName("Company")); TypeDeclaration typeDeclaration = interfaceGenerator.generateClass( clazz, ast, cu); assertEquals(typeDeclaration.toString(), td.toString()); }
@SuppressWarnings("unchecked") @Test public void testGenerateAssociationEndUpperCardinalityMultiplesIsUnique() { AST ast = AST.newAST(AST.JLS3); ast.newCompilationUnit(); TypeDeclaration td = ast.newTypeDeclaration(); td.setInterface(true); Modifier modifier = ast .newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD); td.modifiers().add(modifier); td.setName(ast.newSimpleName("Company")); Property property = mock(Property.class); MethodDeclaration mdGetter = ast.newMethodDeclaration(); mdGetter.setName(ast.newSimpleName("getCompanies")); String umlQualifiedTypeName = "test.de.Company"; String umlTypeName = "Company"; when(property.isOrdered()).thenReturn(false); when(property.isUnique()).thenReturn(true); interfaceGenerator.generateAssociationEndUpperCardinalityMultiples(ast, td, property, mdGetter, umlTypeName, umlQualifiedTypeName); assertEquals("java.util.Set<test.de.Company>", mdGetter .getReturnType2().toString()); }
@SuppressWarnings("unchecked") @Test public void testGenerateAssociationEndUpperCardinalityMultiplesIsUniqueAndIsOrdered() { AST ast = AST.newAST(AST.JLS3); ast.newCompilationUnit(); TypeDeclaration td = ast.newTypeDeclaration(); td.setInterface(true); Modifier modifier = ast .newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD); td.modifiers().add(modifier); td.setName(ast.newSimpleName("Company")); Property property = mock(Property.class); MethodDeclaration mdGetter = ast.newMethodDeclaration(); mdGetter.setName(ast.newSimpleName("getCompanies")); String umlQualifiedTypeName = "test.de.Company"; String umlTypeName = "Company"; when(property.isOrdered()).thenReturn(true); when(property.isUnique()).thenReturn(true); interfaceGenerator.generateAssociationEndUpperCardinalityMultiples(ast, td, property, mdGetter, umlTypeName, umlQualifiedTypeName); assertEquals("java.util.SortedSet<test.de.Company>", mdGetter .getReturnType2().toString()); }
@SuppressWarnings("unchecked") @Test public void testGenerateClass() { AST ast = AST.newAST(AST.JLS3); CompilationUnit cu = ast.newCompilationUnit(); TypeDeclaration td = ast.newTypeDeclaration(); td.setInterface(true); Modifier modifier = ast .newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD); td.modifiers().add(modifier); td.setName(ast.newSimpleName("Company")); TypeDeclaration typeDeclaration = interfaceGenerator.generateClass( clazz, ast, cu); assertEquals(typeDeclaration.toString(), td.toString()); }
AST ast = AST.newAST(AST.JLS3); CompilationUnit unit = ast.newCompilationUnit(); PackageDeclaration packageDeclaration = ast.newPackageDeclaration(); packageDeclaration.setName(ast.newSimpleName("example")); unit.setPackage(packageDeclaration); ImportDeclaration importDeclaration = ast.newImportDeclaration(); QualifiedName name = ast.newQualifiedName( ast.newSimpleName("java"), ast.newSimpleName("util")); importDeclaration.setName(name); importDeclaration.setOnDemand(true); unit.imports().add(importDeclaration); TypeDeclaration type = ast.newTypeDeclaration(); type.setInterface(false); type.modifiers().add(ast.newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD)); type.setName(ast.newSimpleName("HelloWorld")); // ....