List of usage examples for org.eclipse.jdt.core.dom TypeDeclaration setInterface
public void setInterface(boolean isInterface)
From source file:com.crispico.flower.mp.codesync.code.java.adapter.JavaTypeModelAdapter.java
License:Open Source License
public static Object createCorrespondingModelElement(AST ast, CodeSyncElement cse) { ASTNode child = null;/* ww w .j a va2s . co m*/ if (JavaAttributeModelAdapter.ATTRIBUTE.equals(cse.getType())) { VariableDeclarationFragment fragment = ast.newVariableDeclarationFragment(); FieldDeclaration field = ast.newFieldDeclaration(fragment); child = field; } if (JavaOperationModelAdapter.OPERATION.equals(cse.getType())) { child = ast.newMethodDeclaration(); } if (CLASS.equals(cse.getType())) { child = ast.newTypeDeclaration(); } if (INTERFACE.equals(cse.getType())) { TypeDeclaration type = ast.newTypeDeclaration(); type.setInterface(true); child = type; } if (ENUM.equals(cse.getType())) { child = ast.newEnumDeclaration(); } if (ANNOTATION.equals(cse.getType())) { child = ast.newAnnotationTypeDeclaration(); } return child; }
From source file:com.crispico.flower.mp.metamodel.codesyncjava.algorithm.forward.ForwardJavaSrcDir_Files.java
License:Open Source License
/** * @flowerModelElementId _IEIN7-rfEd6QaI9daHlzjA *//* ww w . j a v a 2s . c om*/ @SuppressWarnings("unchecked") @Override protected CompilationUnit createAndAddNewASTElement(Type modelElement, IContainer parentAstElement) { ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setKind(ASTParser.K_COMPILATION_UNIT); parser.setSource("".toCharArray()); CompilationUnit compUnit = (CompilationUnit) parser.createAST(null); AST ast = compUnit.getAST(); compUnit.recordModifications(); TypeDeclaration typeDeclaration = ast.newTypeDeclaration(); typeDeclaration.modifiers().add(ast.newModifier(ModifierKeyword.PUBLIC_KEYWORD)); compUnit.types().add(typeDeclaration); if (modelElement instanceof Class) typeDeclaration.setInterface(false); else if (modelElement instanceof Interface) typeDeclaration.setInterface(true); else throw new IllegalArgumentException("could not recognize instance of " + modelElement); return compUnit; }
From source file:com.idega.eclipse.ejbwizards.BeanCreator.java
License:Open Source License
protected TypeDeclaration getTypeDeclaration(AST ast, String name, boolean isInterface, String superClass, String[] interfaces, Set imports) { TypeDeclaration classType = ast.newTypeDeclaration(); classType.setInterface(isInterface); classType.modifiers().addAll(ast.newModifiers(Modifier.PUBLIC)); classType.setName(ast.newSimpleName(name)); if (isInterface) { classType.superInterfaceTypes().add(ast.newSimpleType(ast.newSimpleName(superClass))); } else {/*from w w w . j a va2s . c om*/ classType.setSuperclassType(ast.newSimpleType(ast.newSimpleName(superClass))); } if (interfaces != null) { for (int i = 0; i < interfaces.length; i++) { if (!Signature.getSignatureSimpleName(interfaces[i]).equals(name)) { classType.superInterfaceTypes().add( ast.newSimpleType(ast.newSimpleName(Signature.getSignatureSimpleName(interfaces[i])))); imports.add(getImportSignature(Signature.toString(interfaces[i]))); } } } return classType; }
From source file:de.crowdcode.kissmda.cartridges.simplejava.ExceptionGenerator.java
License:Apache License
/** * Generate the Exception Class./*from w w w . j ava 2 s . co m*/ * * @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; }
From source file:de.crowdcode.kissmda.cartridges.simplejava.InterfaceGenerator.java
License:Apache License
/** * Generate the Interface./*from w ww .j a v a 2 s .com*/ * * @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(true); 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); // Add Javadoc generateClassJavadoc(clazz, ast, td); cu.types().add(td); return td; }
From source file:de.crowdcode.kissmda.cartridges.simplejava.InterfaceGeneratorMethodParamsTest.java
License:Apache License
@SuppressWarnings("unchecked") @Test/* www . ja v a2s . c o m*/ public void testGenerateMethodParamsWithParameter() { 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")); MethodDeclaration md = ast.newMethodDeclaration(); md.setName(ast.newSimpleName("calculateAge")); Operation operation = mock(Operation.class, Answers.RETURNS_DEEP_STUBS.get()); EList<Parameter> params = mock(EList.class, Answers.RETURNS_DEEP_STUBS.get()); Iterator<Parameter> paramIterator = mock(Iterator.class); Parameter parameter = mock(Parameter.class, Answers.RETURNS_DEEP_STUBS.get()); Type type = mock(Type.class, Answers.RETURNS_DEEP_STUBS.get()); Map<String, String> types = new HashMap<String, String>(); types.put("umlTypeName", "Collection<de::test::Company>"); types.put("umlQualifiedTypeName", "Data::datatype::Collection<de::test::Company>"); when(operation.getOwnedParameters()).thenReturn(params); when(params.iterator()).thenReturn(paramIterator); when(paramIterator.hasNext()).thenReturn(true, false); when(paramIterator.next()).thenReturn(parameter); when(parameter.getDirection()).thenReturn(ParameterDirectionKind.get(ParameterDirectionKind.IN)); when(parameter.getType()).thenReturn(type); when(parameter.getName()).thenReturn("companies"); when(type.getName()).thenReturn("Collection<Company>"); when(type.getQualifiedName()).thenReturn("Data::datatype::Collection<Company>"); when(dataTypeUtils.isParameterizedType(Mockito.anyString())).thenReturn(true); when(umlHelper.checkParameterizedTypeForTemplateParameterSubstitution(type)).thenReturn(types); doNothing().when(jdtHelper).createParameterTypes(ast, td, md, "Collection<de::test::Company>", "Data::datatype::Collection<de::test::Company>", "companies", null); interfaceGenerator.generateMethodParams(ast, td, operation, md); verify(jdtHelper, times(1)).createParameterTypes(ast, td, md, "Collection<de::test::Company>", "Data::datatype::Collection<de::test::Company>", "companies", null); }
From source file:de.crowdcode.kissmda.cartridges.simplejava.InterfaceGeneratorTest.java
License:Apache License
@SuppressWarnings("unchecked") @Test/*from ww w.jav a 2s. co m*/ 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()); }
From source file:de.crowdcode.kissmda.cartridges.simplejava.InterfaceGeneratorTest.java
License:Apache License
@SuppressWarnings("unchecked") @Test/*ww w .j a v a2 s . c om*/ public void testGenerateClassWithInheritance() { EList<Generalization> generalizations = new UniqueEList<Generalization>(); Generalization generalization = mock(Generalization.class); Class clazzGeneralization = mock(Class.class); generalizations.add(generalization); when(generalization.getGeneral()).thenReturn(clazzGeneralization); when(clazzGeneralization.getQualifiedName()).thenReturn("de::test::SuperCompany"); when(clazz.getGeneralizations()).thenReturn(generalizations); 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")); Name name = ast.newName("de.test.SuperCompany"); SimpleType simpleType = ast.newSimpleType(name); td.superInterfaceTypes().add(simpleType); TypeDeclaration typeDeclaration = interfaceGenerator.generateClass(clazz, ast, cu); assertEquals(typeDeclaration.toString(), td.toString()); }
From source file:de.crowdcode.kissmda.cartridges.simplejava.InterfaceGeneratorTest.java
License:Apache License
@SuppressWarnings("unchecked") @Test/*from w w w .j a v a 2 s . c om*/ 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()); }
From source file:de.crowdcode.kissmda.cartridges.simplejava.InterfaceGeneratorTest.java
License:Apache License
@SuppressWarnings("unchecked") @Test/*from w w w. j a va2s. c o m*/ public void testGenerateMethods() { 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")); EList<Operation> operations = mock(EList.class, Answers.RETURNS_DEEP_STUBS.get()); Operation operation = mock(Operation.class, Answers.RETURNS_DEEP_STUBS.get()); Type operationType = mock(Type.class, Answers.RETURNS_DEEP_STUBS.get()); Iterator<Operation> iteratorOperation = mock(Iterator.class); EList<Type> raisedExceptions = mock(EList.class, Answers.RETURNS_DEEP_STUBS.get()); Iterator<Type> iteratorException = mock(Iterator.class); Type exceptionType = mock(Type.class, Answers.RETURNS_DEEP_STUBS.get()); when(clazz.getOperations()).thenReturn(operations); when(operations.iterator()).thenReturn(iteratorOperation); when(iteratorOperation.hasNext()).thenReturn(true, false); when(iteratorOperation.next()).thenReturn(operation); when(operation.getName()).thenReturn("calculateMe"); when(operation.getType()).thenReturn(operationType); when(operation.getRaisedExceptions()).thenReturn(raisedExceptions); when(raisedExceptions.iterator()).thenReturn(iteratorException); when(iteratorException.hasNext()).thenReturn(true, false); when(iteratorException.next()).thenReturn(exceptionType); when(exceptionType.getQualifiedName()).thenReturn("de::test::CalculatorException"); when(operationType.getQualifiedName()).thenReturn("de::test::Calculator"); when(operationType.getName()).thenReturn("Calculator"); interfaceGenerator.generateMethods(clazz, ast, td); assertEquals( "public interface Company {\n de.test.Calculator calculateMe() throws de.test.CalculatorException ;\n}\n", td.toString()); }