Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus')
-rw-r--r--extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/GeneratorPreference.java77
-rw-r--r--extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/RunGenerator.java228
-rw-r--r--extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchJDTCommentable.java161
-rw-r--r--extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchJDTCompilationUnit.java95
-rw-r--r--extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchJDTField.java217
-rw-r--r--extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchJDTGetterSetter.java168
-rw-r--r--extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchJDTJavaModel.java73
-rw-r--r--extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchJDTJavaProject.java145
-rw-r--r--extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchJDTMethod.java387
-rw-r--r--extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchJDTPackageFragment.java112
-rw-r--r--extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchJDTPackageFragmentRoot.java120
-rw-r--r--extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchJDTType.java435
-rw-r--r--extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchTools.java325
13 files changed, 0 insertions, 2543 deletions
diff --git a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/GeneratorPreference.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/GeneratorPreference.java
deleted file mode 100644
index 56af682c908..00000000000
--- a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/GeneratorPreference.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2011 Nicolas Deblock & Manuel Giles.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Nicolas Deblock nico.deblock@gmail.com - Initial API and implementation
- * Manuel Giles giles.manu@live.fr - Initial API and implementation
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Idea of the java generator project & help for the conception
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.java.generator.jdtsynchronizer;
-
-public interface GeneratorPreference {
-
- /**
- * indicate if methods of inherits interfaces must be implement in a class
- *
- * @return
- */
- public boolean implementMethodsOfIntefaces();
-
- /**
- * indicate if methods of inherit abstract class must be implement in a class
- *
- * @return
- */
- public boolean implementMethodsOfAbstractClass();
-
- /**
- * indicate if getters must be create
- *
- * @return
- */
- public boolean generateGetters();
-
- /**
- * indicate if setters must be create
- *
- * @return
- */
- public boolean generateSetters();
-
- /**
- * indicate if a package must be generate
- *
- * @param packageQualifiedName
- * package to generate
- * @return
- */
- public boolean isPackageToGenerate(String packageQualifiedName);
-
- /**
- *
- * @return generic class to use for the association * (multi-value)
- */
- public String genericClassForMultiValue();
-
- /**
- * Return true if we want to stop on first error, false if we want to continue anyway.
- *
- * @return
- */
- public boolean stopOnFirstError();
-
- /**
- *
- * @return the default source folder name where the generator have to generate Java files and packages.
- */
- public String defaultSourceFolderName();
-
-}
diff --git a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/RunGenerator.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/RunGenerator.java
deleted file mode 100644
index 4ff03a7e505..00000000000
--- a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/RunGenerator.java
+++ /dev/null
@@ -1,228 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2011 Nicolas Deblock & Manuel Giles.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Nicolas Deblock nico.deblock@gmail.com - Initial API and implementation
- * Manuel Giles giles.manu@live.fr - Initial API and implementation
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Idea of the java generator project & help for the conception
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.java.generator.jdtsynchronizer;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.util.List;
-
-import org.eclipse.emf.common.util.BasicEList;
-import org.eclipse.emf.common.util.Diagnostic;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.impl.EPackageRegistryImpl;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.ecore.resource.URIConverter;
-import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
-import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
-import org.eclipse.m2m.qvt.oml.BasicModelExtent;
-import org.eclipse.m2m.qvt.oml.ExecutionContextImpl;
-import org.eclipse.m2m.qvt.oml.ExecutionDiagnostic;
-import org.eclipse.m2m.qvt.oml.ModelExtent;
-import org.eclipse.m2m.qvt.oml.TransformationExecutor;
-import org.eclipse.papyrus.java.generator.jdtsynchronizer.impl.SynchJDTJavaModel;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.generatoroptionsmm.GeneratoroptionsmmFactory;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.generatoroptionsmm.Options;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.JDTJavaElement;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.JDTJavaModel;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.JdtmmPackage;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.visitor.JDTVisitor;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.visitor.JDTVisitorException;
-import org.eclipse.papyrus.java.generator.transfo.umltojdt.UmltojdtActivator;
-import org.eclipse.uml2.uml.UMLPackage;
-import org.eclipse.uml2.uml.resource.UMLResource;
-
-/**
- * Class to Run the QVT Transformation, and then the Java generation
- */
-public class RunGenerator {
-
- /**
- * This is the metamodele
- */
- private EList<EObject> inObjects;
-
- /**
- * Constructor of RunGenerator using .uml file
- *
- * @param UMLFileUrl
- * the '.uml' file's url
- * @throws FileNotFoundException
- */
- public RunGenerator(String umlFileUrl) throws FileNotFoundException {
-
- // charge the model of the '.uml' file
- inObjects = loadUmlModel(umlFileUrl);
- }
-
- /**
- * Constructor of RunGenerator using EList<EObject> metamodel
- *
- * @param UMLFileUrl
- * the '.uml' file's url
- */
- public RunGenerator(EList<EObject> inObjects) {
- this.inObjects = inObjects;
- }
-
- /**
- * run code generation using QVTo transformation
- *
- * @throws JDTVisitorException
- */
- public void runGeneration(GeneratorPreference preference) throws JDTVisitorException {
- // Create an options model using the Eclipse Preferences
- EList<EObject> inOptions = createOptionModelFromEclipsePreferences(preference);
-
- // Refer to an existing transformation via URI
- final URI scriptUri =
- URI.createURI("platform:/plugin/" + UmltojdtActivator.PLUGIN_ID + UmltojdtActivator.PATH_QVT_FILE);
-
- List<EObject> outObjects = runTransformation(scriptUri, inObjects, inOptions);
-
- if (outObjects.size() == 0) {
- throw new JDTVisitorException("No classes or packages produced from the transformation. Nothing is generated.");
- }
-
- if (outObjects.size() > 1) {
- System.err.println("Warning, JDT modele has more than one root. Found root:");
- for (EObject el : outObjects) {
- System.err.println(((JDTJavaElement) el).getElementName());
- }
- System.err.println("-------");
- }
-
- // finally, we synchronize the JDT model with org.eclipse.jdt.core
- if (outObjects.size() > 0) {
- /*
- * TODO : if metamodel have some root node, we make a loop
- * JDTJavaElement proj = (JDTJavaElement) outObjects.get(0);
- *
- * JDTVisitor visitor = new SynchJDTJavaModel();
- * proj.accept(visitor);
- */
- for (Object o : outObjects) {
- if (o instanceof JDTJavaModel) {
- JDTJavaElement proj = (JDTJavaElement) o;
- JDTVisitor visitor = new SynchJDTJavaModel(preference);
- proj.accept(visitor);
- }
-
- }
- }
- }
-
- /**
- * Create a new GeneratorOptions model and inject eclipse preferences on it.
- *
- * @param preference
- * eclipse preferences
- * @return a new instance of Options, where options.defaultSourceFolder have been initialized.
- */
- private EList<EObject> createOptionModelFromEclipsePreferences(GeneratorPreference preference) {
- GeneratoroptionsmmFactory optionsFactory = GeneratoroptionsmmFactory.eINSTANCE;
-
- // Create a new Options object and inject the default source folder name from Eclipse preferences
- Options options = optionsFactory.createOptions();
- options.setDefaultSourceFolder(preference.defaultSourceFolderName());
-
- // Add options to the model
- EList<EObject> optionsContents = new BasicEList<EObject>(1);
- optionsContents.add(options);
-
- return optionsContents;
- }
-
- /**
- * Run QVTo transformation using the scriptUri and the inObjects model
- *
- * @param scriptUri
- * The script QVTo
- * @param inObjects
- * The entry model
- * @param inOptions2
- * @return The output model
- */
- private List<EObject> runTransformation(URI scriptUri, EList<EObject> inObjects, EList<EObject> inOptions) {
- // initialize the transformation
- // First, you need to instantiate a Registry:
- EPackage.Registry registry = new EPackageRegistryImpl(EPackage.Registry.INSTANCE);
-
- // which is used to register the meta-models in E:\workspace\modelesUML\org.eclipse.papyrus.java.javagen.mmJDT\metaModel
-
- JdtmmPackage mm1 = JdtmmPackage.eINSTANCE;
- registry.put(mm1.getNsURI(), mm1);
-
- // class which allow to execute the transformation
- TransformationExecutor t = new TransformationExecutor(scriptUri, registry);
- ExecutionContextImpl executionContext = new ExecutionContextImpl();
-
- // allow to contains the model uml
- ModelExtent input = new BasicModelExtent(inObjects);
- ModelExtent inputOptions = new BasicModelExtent(inOptions);
- ModelExtent output = new BasicModelExtent();
- // make the transformation
- ExecutionDiagnostic executionDiagnostic = t.execute(executionContext, input, inputOptions, output);
-
- // the errors
- System.out.println(executionDiagnostic.getMessage());
- for (Diagnostic d : executionDiagnostic.getChildren()) {
- System.out.println(d.getMessage());
- }
-
-
- // we take the out JDT model in a list
- return output.getContents();
- }
-
-
- /**
- * Allow to charge the uml model in a list
- *
- * @param url
- * the '.uml' file's url
- * @return the charge model
- * @throws FileNotFoundException
- */
- private EList<EObject> loadUmlModel(String url) throws FileNotFoundException {
-
- ResourceSet resourceSet = new ResourceSetImpl();
-
- // charge the metamodel util for read the model
- resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
- resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
- // Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "uml", new UMLResourceFactoryImpl());
-
- Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl());
- URIConverter.URI_MAP.put(URI.createURI("pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml"), URI.createFileURI(System.getProperty("user.dir") + "/Model_Libs/UMLPrimitiveTypes.library.uml"));
-
- // the '.uml' file's url
- File file = new File(url);
- if (!file.exists()) {
- throw new FileNotFoundException("File " + new File(url).getAbsolutePath() + " not found");
- }
- URI fileURI = URI.createFileURI(new File(url).getAbsolutePath());
-
- // demand load the resource for this file.
- Resource resource = resourceSet.getResource(fileURI, true);
-
- return resource.getContents();
- }
-}
diff --git a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchJDTCommentable.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchJDTCommentable.java
deleted file mode 100644
index 5a196a155b0..00000000000
--- a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchJDTCommentable.java
+++ /dev/null
@@ -1,161 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2011 Nicolas Deblock & Manuel Giles.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Nicolas Deblock nico.deblock@gmail.com - Initial API and implementation
- * Manuel Giles giles.manu@live.fr - Initial API and implementation
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Idea of the java generator project & help for the conception
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.java.generator.jdtsynchronizer.impl;
-
-import java.util.List;
-
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.IJavaElement;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.core.dom.AST;
-import org.eclipse.jdt.core.dom.ASTParser;
-import org.eclipse.jdt.core.dom.BodyDeclaration;
-import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.eclipse.jdt.core.dom.Javadoc;
-import org.eclipse.jdt.core.dom.TagElement;
-import org.eclipse.jdt.core.dom.TextElement;
-import org.eclipse.jdt.core.dom.TypeDeclaration;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.Document;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.visitor.JDTVisitor;
-import org.eclipse.text.edits.MalformedTreeException;
-import org.eclipse.text.edits.TextEdit;
-
-/**
- * Useful for class who have to generate Javadoc comment.
- *
- * @author Deblock Nicolas & Manuel Giles
- *
- */
-public abstract class SynchJDTCommentable implements JDTVisitor {
-
-
- /**
- * search the element to insert the Javadoc in compilation unit
- *
- * @param cu
- * @param typeName
- * @return
- */
- protected abstract BodyDeclaration searchElementToInsert(CompilationUnit cu, IJavaElement elementName);
-
- /**
- * return javaDoc tag to add. Call in function createJavaDocFor()
- *
- * @return javaDoc tag to add in a List<String> with String = "@tag comment"
- */
- protected abstract List<String> getJavadocTags();
-
- /**
- * Reads a ICompilationUnit and creates the AST DOM for manipulating the
- * Java source file
- *
- * @param unit
- * @return
- */
- private static CompilationUnit parse(ICompilationUnit unit) {
- ASTParser parser = ASTParser.newParser(AST.JLS3);
- parser.setKind(ASTParser.K_COMPILATION_UNIT);
- parser.setSource(unit);
- parser.setResolveBindings(true);
- return (CompilationUnit) parser.createAST(null); // parse
- }
-
-
- /**
- * Create a JavaDoc for a a objet who extends IJavaElement and IMethod
- * (IType or IMethod by example)
- *
- * @param ielement
- * the element you want add javadoc
- * @param icu
- * the compilation unit of ielement
- * @param comment
- * body of the comment
- * @param auteur
- * author of the compilation unit
- * @throws JavaModelException
- * @throws BadLocationException
- * @throws MalformedTreeException
- */
- protected <U extends IJavaElement> void createJavaDocFor(U ielement, ICompilationUnit icu, String comment, String author) throws JavaModelException, MalformedTreeException, BadLocationException {
-
- CompilationUnit cu = parse(icu);
- // Authorize modification
- cu.recordModifications();
- // create document
- Document document = new Document(icu.getBuffer().getContents());
-
- // Creating the new JavaDoc node
- AST ast = cu.getAST();
- Javadoc jc = ast.newJavadoc();
-
- TagElement tag = ast.newTagElement();
- if (comment != null) {
- TextElement te = ast.newTextElement();
- tag.fragments().add(te);
- te.setText(comment);
- }
- jc.tags().add(tag);
-
- List<String> javadocTags = getJavadocTags();
- if (javadocTags != null) {
- for (String s : javadocTags) {
- tag = ast.newTagElement();
- tag.setTagName(s);
- jc.tags().add(tag);
- }
- }
- // add javadoc to type
- BodyDeclaration classType = searchElementToInsert(cu, ielement);
- if (classType != null) {
- classType.setJavadoc(jc);
- }
-
- // Applying changes
- TextEdit text = cu.rewrite(document, icu.getJavaProject().getOptions(true));
- text.apply(document);
-
- // set buffer of compilation unit
- icu.getBuffer().setContents(document.get());
-
- }
-
- /**
- * search type in type declaration
- *
- * @param classType
- * type declaration
- * @param typeName
- * typeName type name research
- * @return
- */
- protected TypeDeclaration searchType(TypeDeclaration classType, String typeName) {
- if (classType.getName().toString().equals(typeName)) {
- return classType;
- }
-
- for (Object objct : classType.getTypes()) {
- TypeDeclaration ct = (TypeDeclaration) objct;
- if (ct.getName().toString().equals(typeName)) {
- return ct;
- }
- searchType(ct, typeName);
- }
- return null;
- }
-}
diff --git a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchJDTCompilationUnit.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchJDTCompilationUnit.java
deleted file mode 100644
index 1e6f34fb515..00000000000
--- a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchJDTCompilationUnit.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2011 Nicolas Deblock & Manuel Giles.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Nicolas Deblock nico.deblock@gmail.com - Initial API and implementation
- * Manuel Giles giles.manu@live.fr - Initial API and implementation
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Idea of the java generator project & help for the conception
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.java.generator.jdtsynchronizer.impl;
-
-import org.eclipse.emf.ecore.impl.EObjectImpl;
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.IPackageFragment;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.papyrus.java.generator.jdtsynchronizer.GeneratorPreference;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.JDTCompilationUnit;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.JDTJavaElement;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.JDTType;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.visitor.JDTVisitor;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.visitor.JDTVisitorException;
-
-/**
- * Allow to generate compilation Unit
- *
- * @author Deblock Nicolas & Manuel Giles
- *
- */
-public class SynchJDTCompilationUnit extends EObjectImpl implements JDTVisitor {
-
- private IPackageFragment ipack;
-
- private GeneratorPreference preference;
-
- /**
- * Constructor
- *
- * @param ipack
- * the IPackageFragment parent
- */
- public SynchJDTCompilationUnit(IPackageFragment ipack, GeneratorPreference preference) {
- super();
- this.ipack = ipack;
- this.preference = preference;
- }
-
- @Override
- public void visit(JDTJavaElement element) throws JDTVisitorException {
- // if element can't be generated, we stop all
- if (!element.isGenerated()) {
- return;
- }
- if (SynchTools.isPrimiveType(element.getElementName()) && !element.getElementName().equals("String")) {
- return;
- }
-
- JDTCompilationUnit cu = (JDTCompilationUnit) element;
- try {
- ICompilationUnit icu = SynchTools.searchIJavaElement(ipack.getCompilationUnits(), cu.getElementName() + ".java");
-
- if (icu == null) {
- icu = ipack.createCompilationUnit(cu.getElementName() + ".java", "", true, null);
- if (!ipack.getElementName().equals(IPackageFragment.DEFAULT_PACKAGE_NAME)) {
- icu.createPackageDeclaration(ipack.getElementName(), null);
- }
- }
-
- // call the children JDTType
- JDTVisitor visitor = new SynchJDTType(icu, preference);
-
- for (JDTType type : cu.getTypes()) {
- type.accept(visitor);
- }
-
- // save the compilation unit
- icu.save(null, true);
- } catch (JavaModelException e) {
- e.printStackTrace();
- throw new JDTVisitorException(e.getMessage(), e.getCause());
- } catch (Exception e) {
- e.printStackTrace();
- throw new JDTVisitorException(e.getMessage(), e.getCause());
- }
-
-
- }
-
-}
diff --git a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchJDTField.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchJDTField.java
deleted file mode 100644
index 485ef9ce603..00000000000
--- a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchJDTField.java
+++ /dev/null
@@ -1,217 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2011 Nicolas Deblock & Manuel Giles.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Nicolas Deblock nico.deblock@gmail.com - Initial API and implementation
- * Manuel Giles giles.manu@live.fr - Initial API and implementation
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Idea of the java generator project & help for the conception
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.java.generator.jdtsynchronizer.impl;
-
-import java.util.List;
-
-import org.eclipse.jdt.core.IField;
-import org.eclipse.jdt.core.IJavaElement;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.core.dom.BodyDeclaration;
-import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.eclipse.jdt.core.dom.FieldDeclaration;
-import org.eclipse.jdt.core.dom.TypeDeclaration;
-import org.eclipse.papyrus.java.generator.jdtsynchronizer.GeneratorPreference;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.JDTField;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.JDTJavaElement;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.JDTType;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.visitor.JDTVisitorException;
-
-/**
- * Allow to generate field in a type
- *
- * @author Deblock Nicolas & Manuel Giles
- *
- */
-public class SynchJDTField extends SynchJDTCommentable {
-
- private IType itype;
-
- private JDTField field;
-
- private GeneratorPreference preference;
-
- /**
- * Constructor
- *
- * @param itype
- * the type parent
- */
- public SynchJDTField(IType itype, GeneratorPreference preference) {
- super();
- this.itype = itype;
- this.preference = preference;
- }
-
- @Override
- public void visit(JDTJavaElement element) throws JDTVisitorException {
- // if element can't be generated, we stop all
- if (!element.isGenerated()) {
- return;
- }
-
- field = (JDTField) element;
-
- StringBuffer buffer = new StringBuffer();
- try {
- IField ifield = SynchTools.searchIJavaElement(itype.getFields(), field.getElementName());
- if (ifield == null && field.getType() != null) {
- // first : find the import package
- // create import when it's not a primitive type
- SynchTools.createImport(itype, field.getOwner(), field.getType());
-
-
- // visibility
- buffer.append("\n" + SynchTools.getVisibility(field).toString());
-
- // // if it's an association *
- if (field.isMultiValued()) {
- buffer.append(SynchTools.getMultiValued(itype, field.getType().getElementName(), preference));
- } else {
- buffer.append(field.getType().getElementName());
- }
-
-
- // create type
- buffer.append(" " + field.getElementName());
-
- if (field.getValue() != null) {
- buffer.append(" = ");
- if (field.getType().getElementName().equals("char")) {
- buffer.append("'" + field.getValue().toString() + "'");
- } else if (field.getType().getElementName().equals("String")) {
- buffer.append("\"" + field.getValue().toString() + "\"");
- } else {
- buffer.append(field.getValue().toString());
- }
- }
-
- buffer.append(";");
-
- // create type
- ifield = itype.createField(buffer.toString(), null, true, null);
-
- // add javadoc to method
- createJavaDocFor(ifield, ifield.getCompilationUnit(), field.getComment(), "");
- }
- else if (field.getType() == null) {
- System.err.println("No type specified for "
- + field.getOwner().getQualifiedName()
- + "." + field.getElementName());
- }
-
-
- // Generate explicit imports
- generateExplicitImports(field, itype);
-
- } catch (JavaModelException e) {
- // e.printStackTrace();
- String msg = "Can't generate field (class='"
- + field.getOwner().getQualifiedName()
- + "', msg= " + e.getMessage()
- + ", buffer=" + buffer.toString()
- + ")";
- // System.err.println(msg);
- // throw new JDTVisitorException( msg, e.getCause());
- propagateException(msg, e);
- } catch (Exception e) {
- // e.printStackTrace();
- // throw new JDTVisitorException(e.getMessage(), e.getCause());
- propagateException(e.getMessage(), e);
- }
- }
-
- /**
- * Propagate a {@link JDTVisitorException} if the flag is not set
- *
- * @param msg
- * @param e
- * @throws JDTVisitorException
- */
- private void propagateException(String msg, Throwable e) throws JDTVisitorException {
-
- if (preference.stopOnFirstError()) {
- throw new JDTVisitorException(msg, e.getCause());
- }
- else {
- // Show error
- System.err.println(msg);
- e.printStackTrace();
- }
- }
-
- @Override
- protected BodyDeclaration searchElementToInsert(CompilationUnit cu,
- IJavaElement field) {
-
- // search Itype parent
- if (field.getParent() instanceof IType) {
- IType itype = (IType) field.getParent();
- // find the good type
- TypeDeclaration type = searchType((TypeDeclaration) cu.types().get(0), itype.getElementName());
-
- // search the method. Fortunately, there are no method getSignature() for the type FieldDeclaration.
- // So, we search manually
- for (FieldDeclaration fs : type.getFields()) {
- if (fs.toString().contains((field.getElementName()))) {
- return fs;
- }
- }
- }
- return null;
- }
-
- @Override
- protected List<String> getJavadocTags() {
- // any javadoc tag
- return null;
- }
-
- /**
- * Generate imports that are explicitly declared in the type
- *
- * @param field2
- * The src type to be transformed
- * @param destType
- * The jdt dest type to be generated
- * @throws JavaModelException
- * @throws JDTVisitorException
- */
- private void generateExplicitImports(JDTField field2, IType destType) throws JDTVisitorException {
-
-
- // Add explicit type
- for (JDTType anImport : field2.getExplicitRequiredImports()) {
- try {
- destType.getCompilationUnit().createImport(anImport.getQualifiedName(), null, null);
- } catch (Exception e) {
- propagateException(destType.getFullyQualifiedName() + "Can't add explicit import " + anImport.getQualifiedName(), e);
- }
- }
-
- // Add explicit plain text types
- for (String anImport : field2.getExplicitPlainTextRequiredImports()) {
- try {
- destType.getCompilationUnit().createImport(anImport, null, null);
- } catch (JavaModelException e) {
- propagateException(destType.getFullyQualifiedName() + "Can't add explicit plain text import " + anImport, e);
- }
- }
-
- }
-}
diff --git a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchJDTGetterSetter.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchJDTGetterSetter.java
deleted file mode 100644
index b1939423c7c..00000000000
--- a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchJDTGetterSetter.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2011 Nicolas Deblock & Manuel Giles.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Nicolas Deblock nico.deblock@gmail.com - Initial API and implementation
- * Manuel Giles giles.manu@live.fr - Initial API and implementation
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Idea of the java generator project & help for the conception
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.java.generator.jdtsynchronizer.impl;
-
-import org.eclipse.jdt.core.IJavaElement;
-import org.eclipse.jdt.core.IMethod;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.core.dom.BodyDeclaration;
-import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.eclipse.jdt.core.dom.MethodDeclaration;
-import org.eclipse.jdt.core.dom.TypeDeclaration;
-import org.eclipse.papyrus.java.generator.jdtsynchronizer.GeneratorPreference;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.JDTField;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.JDTJavaElement;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.TrueFalseDefault;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.visitor.JDTVisitorException;
-
-public class SynchJDTGetterSetter extends SynchJDTMethod {
-
- private JDTField field;
-
- private GeneratorPreference preference;
-
- public SynchJDTGetterSetter(IType it, GeneratorPreference preference) {
- super(it, preference);
- this.preference = preference;
- }
-
-
- @Override
- public void visit(JDTJavaElement element) throws JDTVisitorException {
- this.field = (JDTField) element;
- // error if field.getType() == null. indicate in console only
- if (field.getType() == null) {
- System.err.println("l31 SunchJDTGetterSetter : field.getType() est null pour " + field.getElementName() + " dans " + field.getOwner().getElementName());
- return;
- }
-
-
- try {
- // name of field
- String fieldNameCap = field.getElementName().replaceFirst(".", (field.getElementName().charAt(0) + "").toUpperCase());
-
- // generate getter
- if (field.getGenerateGetter() == TrueFalseDefault.TRUE || // user demand generate getter
- field.getGenerateGetter() == TrueFalseDefault.DEFAULT && preference.generateGetters()) { // or no demand, look at preferences
- StringBuffer bufferGet = new StringBuffer();
-
- bufferGet.append("public ");
-
- // handle MultiValued
- if (field.isMultiValued()) {
- bufferGet.append(SynchTools.getMultiValued(itype, field.getType().getElementName(), preference));
- } else {
- bufferGet.append(field.getType().getElementName());
- }
-
-
- bufferGet.append(" get" + fieldNameCap + "() {\n "
- + "\t return " + field.getElementName() + "; \n} \n");
-
-
-
-
- IMethod imethod = SynchTools.searchIJavaElement(itype.getMethods(), "get" + fieldNameCap);
- if (imethod == null) {
- IMethod methodGet = itype.createMethod(bufferGet.toString(), null, true, null);
- createJavaDocFor(methodGet, itype.getCompilationUnit(), "Getter of " + field.getElementName(), "");
- }
- }
-
-
- // generate setter
- if (field.getGenerateSetter() == TrueFalseDefault.TRUE || // user demand generate setter
- field.getGenerateSetter() == TrueFalseDefault.DEFAULT && preference.generateSetters()) { // or no demand, look at preferences
- StringBuffer bufferSet = new StringBuffer();
-
- bufferSet.append("public void set" + fieldNameCap + "(");
-
- // handle MultiValued
- if (field.isMultiValued()) {
- bufferSet.append(SynchTools.getMultiValued(itype, field.getType().getElementName(), preference));
- } else {
- bufferSet.append(field.getType().getElementName());
- }
-
- bufferSet.append(" " + field.getElementName() + ") { \n"
- + "\t this." + field.getElementName() + " = " + field.getElementName() + "; \n} \n ");
-
-
-
-
- IMethod imethod = SynchTools.searchIJavaElement(itype.getMethods(), "set" + fieldNameCap);
- if (imethod == null) {
- IMethod methodSet = itype.createMethod(bufferSet.toString(), null, true, null);
- createJavaDocFor(methodSet, itype.getCompilationUnit(), "Setter of " + field.getElementName(), "");
- }
- }
- } catch (JavaModelException e) {
- e.printStackTrace();
- throw new JDTVisitorException(e.getMessage(), e.getCause());
- } catch (Exception e) {
- e.printStackTrace();
- throw new JDTVisitorException(e.getMessage(), e.getCause());
- }
- }
-
-
- @Override
- // search the method to insert Javadoc
- protected BodyDeclaration searchElementToInsert(CompilationUnit cu,
- IJavaElement method) {
-
- // search Itype parent
- if (method.getParent() instanceof IType) {
- IType itype = (IType) method.getParent();
- // find the good type
- TypeDeclaration type = searchType((TypeDeclaration) cu.types().get(0), itype.getElementName());
-
- // search the method. Fortunately, there are no method getSignature() for the type MethodDeclaration.
- // So, we search manually
- for (MethodDeclaration m : type.getMethods()) {
- if (m.getName().toString().equals(method.getElementName())) {
- // verify the signature
- return m;
- /*
- * TODO
- * if(m.parameters() !=null && m.parameters().size() == 0 && this.method.getParameters().size() == 0)
- * return m;
- * if(m.parameters().size() == this.method.getParameters().size()) {
- * int numParam = 0;
- * boolean goodSignature = true;
- * for(Object paramObj : m.parameters()) {
- * if(paramObj instanceof SingleVariableDeclaration) {
- * SingleVariableDeclaration param = (SingleVariableDeclaration) paramObj;
- * if(!param.getType().toString().equals(this.method.getParameters().get(numParam).getType().getElementName()))
- * goodSignature = false;
- *
- * numParam++;
- * }
- * }
- * if(goodSignature)
- * return m;
- * }
- */
- }
- }
- }
-
- return null;
- }
-
-}
diff --git a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchJDTJavaModel.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchJDTJavaModel.java
deleted file mode 100644
index 7dc71d9ccef..00000000000
--- a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchJDTJavaModel.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2011 Nicolas Deblock & Manuel Giles.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Nicolas Deblock nico.deblock@gmail.com - Initial API and implementation
- * Manuel Giles giles.manu@live.fr - Initial API and implementation
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Idea of the java generator project & help for the conception
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.java.generator.jdtsynchronizer.impl;
-
-
-import org.eclipse.core.resources.IWorkspaceRoot;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.jdt.core.IJavaModel;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.papyrus.java.generator.jdtsynchronizer.GeneratorPreference;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.JDTJavaElement;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.JDTJavaModel;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.JDTJavaProject;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.visitor.JDTVisitor;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.visitor.JDTVisitorException;
-
-/**
- * Allow to generate Code thanks to a JDT model
- *
- * @author Deblock Nicolas & Manuel Giles
- *
- */
-public class SynchJDTJavaModel implements JDTVisitor {
-
- private GeneratorPreference preference;
-
- /**
- * Constructor
- *
- * @param modelJDT
- * the model JDT to generate
- */
- public SynchJDTJavaModel(GeneratorPreference preference) {
- this.preference = preference;
- }
-
- @Override
- public void visit(JDTJavaElement element) throws JDTVisitorException {
- // if element can't be generated, we stop all
- // if(!element.isGenerated()) return ;
-
- if (!(element instanceof JDTJavaModel)) {
- return;
- }
- // cast element to JDTJavaModel
- JDTJavaModel model = (JDTJavaModel) element;
-
- // research the IJavaModel
- IWorkspaceRoot iroot = ResourcesPlugin.getWorkspace().getRoot();
- IJavaModel ijm = JavaCore.create(iroot);
-
-
- // browse all JDTJavaProject and call the visit
- JDTVisitor visitor = new SynchJDTJavaProject(ijm, iroot, preference);
- for (JDTJavaProject root : model.getJavaProject()) {
- root.accept(visitor);
- }
- }
-}
diff --git a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchJDTJavaProject.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchJDTJavaProject.java
deleted file mode 100644
index fa545843b69..00000000000
--- a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchJDTJavaProject.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2011 Nicolas Deblock & Manuel Giles.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Nicolas Deblock nico.deblock@gmail.com - Initial API and implementation
- * Manuel Giles giles.manu@live.fr - Initial API and implementation
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Idea of the java generator project & help for the conception
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.java.generator.jdtsynchronizer.impl;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IProjectDescription;
-import org.eclipse.core.resources.IWorkspaceRoot;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.jdt.core.IClasspathEntry;
-import org.eclipse.jdt.core.IJavaModel;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.launching.IVMInstall;
-import org.eclipse.jdt.launching.JavaRuntime;
-import org.eclipse.papyrus.java.generator.jdtsynchronizer.GeneratorPreference;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.JDTJavaElement;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.JDTJavaProject;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.JDTPackageFragmentRoot;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.util.JdtmmPreference;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.visitor.JDTVisitor;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.visitor.JDTVisitorException;
-
-/**
- * Allow to generate Code thanks to a JDT model
- *
- * @author Deblock Nicolas & Manuel Giles
- *
- */
-public class SynchJDTJavaProject implements JDTVisitor {
-
- private IJavaModel ijm;
-
- private IWorkspaceRoot iroot;
-
- private GeneratorPreference preference;
-
- /**
- * Constructor
- *
- * @param modelJDT
- * the model JDT to generate
- */
- public SynchJDTJavaProject(IJavaModel ijm, IWorkspaceRoot iroot, GeneratorPreference preference) {
- this.ijm = ijm;
- this.iroot = iroot;
- this.preference = preference;
- }
-
-
- @Override
- public void visit(JDTJavaElement element) throws JDTVisitorException {
- // if element can't be generated, we stop all
- if (!element.isGenerated()) {
- return;
- }
-
- if (!(element instanceof JDTJavaProject)) {
- return;
- }
- // cast element to JDTJavaProject
- JDTJavaProject project = (JDTJavaProject) element;
-
- // set the multi-value for the metamodel
- JdtmmPreference.setClassMultiValue(preference.genericClassForMultiValue().substring(preference.genericClassForMultiValue().lastIndexOf(".") + 1));
-
-
- // search IJavaProject
- // IProject projet = iroot.getProject(project.getElementName());
- IJavaProject ijavaProjet = ijm.getJavaProject(project.getElementName());
- IProject proj;
-
- // if ijavaProjet don't exist, create this!
- if (!ijavaProjet.exists()) {
- try {
- proj = iroot.getProject(project.getElementName());
- if (!proj.exists()) {
- proj.create(null);
- proj.open(null);
- } else if (!proj.isOpen()) {
- proj.open(null);
- }
-
- // Specifies type of project
- IProjectDescription description = proj.getDescription();
- description.setNatureIds(new String[] { JavaCore.NATURE_ID });
- proj.setDescription(description, null);
- } catch (CoreException e) {
- e.printStackTrace();
- throw new JDTVisitorException(e.getMessage());
- }
-
- ijavaProjet = JavaCore.create(proj);
- }
-
- // include the default JRE library if don't exist
- List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>();
- IVMInstall vmInstall = JavaRuntime.getDefaultVMInstall();
- boolean creerJRE = true;
-
-
- try {
- // take libs to project class path
- for (IClasspathEntry elem : ijavaProjet.getRawClasspath()) {
- if (elem.getPath().toString().contains(JavaRuntime.JRE_CONTAINER)) {
- creerJRE = false;
- }
- entries.add(elem);
- }
- // if jre don't exist, we add it to classpath
- if (creerJRE) {
- entries.add(JavaCore.newContainerEntry(JavaRuntime.newJREContainerPath(vmInstall)));
- ijavaProjet.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), null);
- }
- } catch (JavaModelException e) {
- e.printStackTrace();
- throw new JDTVisitorException(e.getMessage(), e.getCause());
- }
-
-
-
- // browse all PackageFragmentRoot and call the visit
- JDTVisitor visitor = new SynchJDTPackageFragmentRoot(ijavaProjet, preference);
- for (JDTPackageFragmentRoot root : project.getPackageFragmentRoots()) {
- root.accept(visitor);
- }
- }
-}
diff --git a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchJDTMethod.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchJDTMethod.java
deleted file mode 100644
index f7b07b36d9c..00000000000
--- a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchJDTMethod.java
+++ /dev/null
@@ -1,387 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2011 Nicolas Deblock & Manuel Giles.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Nicolas Deblock nico.deblock@gmail.com - Initial API and implementation
- * Manuel Giles giles.manu@live.fr - Initial API and implementation
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Idea of the java generator project & help for the conception
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.java.generator.jdtsynchronizer.impl;
-
-
-import java.util.LinkedList;
-import java.util.List;
-
-import org.eclipse.jdt.core.Flags;
-import org.eclipse.jdt.core.IJavaElement;
-import org.eclipse.jdt.core.IMethod;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.core.dom.BodyDeclaration;
-import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.eclipse.jdt.core.dom.MethodDeclaration;
-import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
-import org.eclipse.jdt.core.dom.TagElement;
-import org.eclipse.jdt.core.dom.TypeDeclaration;
-import org.eclipse.papyrus.java.generator.jdtsynchronizer.GeneratorPreference;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.JDTJavaElement;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.JDTMethod;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.JDTMethodBody;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.JDTParameter;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.JDTType;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.visitor.JDTVisitorException;
-
-
-/**
- * Allow to generate Method in a IType
- *
- * @author Deblock Nicolas & Manuel Giles
- *
- */
-public class SynchJDTMethod extends SynchJDTCommentable {
-
- protected IType itype;
-
- private JDTMethod method;
-
- private GeneratorPreference preference;
-
- /**
- * Constructor
- *
- * @param itype
- * the type parent
- */
- public SynchJDTMethod(IType itype, GeneratorPreference preference) {
- super();
- this.itype = itype;
- this.preference = preference;
- }
-
-
-
- @Override
- public void visit(JDTJavaElement element) throws JDTVisitorException {
- // if element can't be generated, we stop all
- if (!element.isGenerated()) {
- return;
- }
-
- method = (JDTMethod) element;
- // IntroduceParameterObjectDescript
- IMethod imethod = null;
-
- try {
- // See if the method exist
- boolean createMethod = true;
-
- for (IMethod m : itype.getMethods()) {
- // if it's the same name, and the same parameterTypes, the method exist
- if (m.getElementName().equals(method.getElementName()) && m.getSignature().equals(method.getJDTSignature())) {
- // stop all
- createMethod = false;
- imethod = m;
- break;
- }
- }
-
- if (createMethod) {
- StringBuffer methodStr = new StringBuffer("\n");
-
- // visibility
- if (itype.isInterface()) {
- methodStr.append("public ");
- } else {
- methodStr.append(SynchTools.getVisibility(method).toString());
- }
-
- // if method is a constructor, no return Type, and name is class name
- if (method.isConstructor()) {
- methodStr.append(itype.getElementName() + "(");
- }
- else {
- // return type
- if (method.getReturnType() != null) {
- // Compute the type, taken into account multivalue
- String type = getTypeAsString(method.getReturnType());
- // put the import package
- SynchTools.createImport(itype, method.getOwner(), method.getReturnType().getType());
-
- methodStr.append(type + " ");
- }
- else {
- methodStr.append("void ");
- }
- // method name
- methodStr.append(method.getElementName() + "(");
- }
- // parameters
- // System.out.println(method.getParam() + " " + method.getParameterTypes());
- int nbParam = 0;
- for (JDTParameter p : method.getParameters()) {
- String typeName = p.getElementName();
- String type = "Undefined";
- if (p.getType() != null) {
- // Compute the type, taken into account multivalue
- type = getTypeAsString(p);
- // put the import package
- SynchTools.createImport(itype, method.getOwner(), p.getType());
- }
-
-
- if (nbParam > 0) {
- methodStr.append(", ");
- }
- methodStr.append(type + " " + typeName);
- nbParam++;
- }
-
- // close
- methodStr.append(")");
-
- // throws
- if (method.getExceptions() != null && method.getExceptions().size() > 0) {
- methodStr.append(" throws ");
- int nbExc = 0;
- for (JDTType exception : method.getExceptions()) {
- if (nbExc > 0) {
- methodStr.append(", ");
- }
- methodStr.append(exception.getElementName());
- if (!SynchTools.isPrimiveType(exception.getQualifiedName()) && exception.getQualifiedName().contains(".")) {
- itype.getCompilationUnit().createImport(exception.getQualifiedName(), null, null);
- }
- nbExc++;
- }
- }
-
-
- // Do we need a body ?
- if (itype.isInterface() || Flags.isAbstract(method.getFlags())) {
- methodStr.append(";");
- }
- else {
- // Generate Body. Open the body
- methodStr.append(" {");
- // If there is a declared body, use it. Otherwise, use the default body.
- if (method.getBodies().size() > 0) {
-
- for (JDTMethodBody body : method.getBodies()) {
- methodStr.append("\n\t");
- methodStr.append(body.asText());
- }
- // methodStr.append("\n");
- }
- else {
- // Default body
- methodStr.append(" \n\t// TODO Auto-generated method");
- if (method.getReturnType() != null) {
- methodStr.append("\n\treturn " + SynchTools.defaultReturn(method.getReturnType().getType().getElementName()) + ";");
- }
-
- }
- // Close the body
- methodStr.append("\n }");
- }
-
- // create the method
- imethod = itype.createMethod(methodStr.toString(), null, true, null);
- }
-
- // add javadoc to method
- createJavaDocFor(imethod, imethod.getCompilationUnit(), method.getComment(), "");
- // Add explicit imports
- generateExplicitImports(method, itype);
- } catch (JavaModelException e) {
- // e.printStackTrace();
- // throw new JDTVisitorException(e.getMessage(), e.getCause());
- propagateException(e.getMessage(), e);
- } catch (Exception e) {
- // e.printStackTrace();
- // throw new JDTVisitorException(e.getMessage(), e.getCause());
- propagateException(e.getMessage(), e);
- }
-
-
- }
-
-
- /**
- * Get the type of the parameter as a String. Take into account the multivalue setting.
- *
- * @param p
- * @return
- * @throws JavaModelException
- */
- private String getTypeAsString(JDTParameter p) throws JavaModelException {
- String type;
- if (p.isMultiValued()) {
- type = SynchTools.getMultiValued(itype, p.getType().getElementName(), preference);
- } else {
- type = p.getType().getElementName();
- }
- return type;
- }
-
-
-
-
-
- /** *************** methods override by SynchJDTCommentable ************** */
-
-
- @Override
- /**
- * search the method to insert Javadoc
- *
- * @see org.eclipse.papyrus.java.generator.jdtsynchronizer.impl.SynchJDTCommentable#searchElementToInsert(org.eclipse.jdt.core.dom.CompilationUnit, org.eclipse.jdt.core.IJavaElement)
- *
- * @param cu
- * @param method
- * @return
- */
- protected BodyDeclaration searchElementToInsert(CompilationUnit cu, IJavaElement method) {
-
- // search Itype parent
- if (method.getParent() instanceof IType) {
- IType itype = (IType) method.getParent();
- // find the good type
- TypeDeclaration type = searchType((TypeDeclaration) cu.types().get(0), itype.getElementName());
-
- // search the method. Fortunately, there are no method getSignature() for the type MethodDeclaration.
- // So, we search manually
- for (MethodDeclaration m : type.getMethods()) {
- if (m.getName().toString().equals(method.getElementName())) {
- // verify the signature
- if (m.parameters() != null && m.parameters().size() == 0 && this.method.getParameters().size() == 0) {
- return m;
- }
- if (m.parameters().size() == this.method.getParameters().size()) {
- int numParam = 0;
- boolean goodSignature = true;
- for (Object paramObj : m.parameters()) {
- if (paramObj instanceof SingleVariableDeclaration) {
- SingleVariableDeclaration param = (SingleVariableDeclaration) paramObj;
- if (!param.getType().toString().equals(this.method.getParameters().get(numParam).getType().getElementName())) {
- goodSignature = false;
- }
-
- numParam++;
- }
- }
- if (goodSignature) {
- return m;
- }
- }
- }
- }
- }
-
- return null;
- }
-
- @Override
- protected List<String> getJavadocTags() {
- List<String> lst = new LinkedList<String>();
- if (method == null) {
- return lst;
- }
-
- // parameters
- for (JDTParameter param : method.getParameters()) {
- String comment = param.getComment();
- if (comment == null) {
- comment = "";
- }
- lst.add(TagElement.TAG_PARAM + " " + param.getElementName() + " " + comment);
- }
-
- // return
- if (method.getReturnType() != null) {
- String comment = method.getReturnType().getComment();
- if (comment == null) {
- comment = "";
- }
- lst.add(TagElement.TAG_RETURN + " " + comment);
- }
-
- // exception
- // TODO prendre en compte notion de commentaire
- if (method.getExceptions() != null) {
- for (JDTType exception : method.getExceptions()) {
- // String comment = exception.getComment();
- // if(comment == null) comment = "";
- lst.add(TagElement.TAG_THROWS + " " + exception.getElementName());
- }
- }
-
-
-
- return lst;
- }
-
-
-
- /**
- * Propagate a {@link JDTVisitorException} if the flag is not set
- *
- * @param msg
- * @param e
- * @throws JDTVisitorException
- */
- private void propagateException(String msg, Throwable e) throws JDTVisitorException {
-
- if (preference.stopOnFirstError()) {
- throw new JDTVisitorException(msg, e.getCause());
- }
- else {
- // Show error
- System.err.println(msg);
- e.printStackTrace();
- }
- }
-
-
-
- /**
- * Generate imports that are explicitly declared in the type
- *
- * @param srcType
- * The src type to be transformed
- * @param destType
- * The jdt dest type to be generated
- * @throws JavaModelException
- * @throws JDTVisitorException
- */
- private void generateExplicitImports(JDTMethod srcType, IType destType) throws JDTVisitorException {
-
-
- // Add explicit type
- for (JDTType anImport : srcType.getExplicitRequiredImports()) {
- try {
- destType.getCompilationUnit().createImport(anImport.getQualifiedName(), null, null);
- } catch (Exception e) {
- propagateException(destType.getFullyQualifiedName() + "Can't add explicit import " + anImport.getQualifiedName(), e);
- }
- }
-
- // Add explicit plain text types
- for (String anImport : srcType.getExplicitPlainTextRequiredImports()) {
- try {
- destType.getCompilationUnit().createImport(anImport, null, null);
- } catch (JavaModelException e) {
- propagateException(destType.getFullyQualifiedName() + "Can't add explicit plain text import " + anImport, e);
- }
- }
-
- }
-
-}
diff --git a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchJDTPackageFragment.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchJDTPackageFragment.java
deleted file mode 100644
index 7426838392c..00000000000
--- a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchJDTPackageFragment.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2011 Nicolas Deblock & Manuel Giles.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Nicolas Deblock nico.deblock@gmail.com - Initial API and implementation
- * Manuel Giles giles.manu@live.fr - Initial API and implementation
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Idea of the java generator project & help for the conception
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.java.generator.jdtsynchronizer.impl;
-
-import org.eclipse.emf.ecore.impl.EObjectImpl;
-import org.eclipse.jdt.core.IJavaElement;
-import org.eclipse.jdt.core.IPackageFragment;
-import org.eclipse.jdt.core.IPackageFragmentRoot;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.papyrus.java.generator.jdtsynchronizer.GeneratorPreference;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.JDTCompilationUnit;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.JDTJavaElement;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.JDTPackageFragment;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.visitor.JDTVisitor;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.visitor.JDTVisitorException;
-
-
-/**
- * allow to generate package fragment
- *
- * @author Deblock Nicolas & Manuel Giles
- *
- */
-public class SynchJDTPackageFragment extends EObjectImpl implements JDTVisitor {
-
- public IPackageFragmentRoot iroot;
-
- private GeneratorPreference preference;
-
- /**
- * Constructor
- *
- * @param iroot
- * the IPackageFragmentRoot parent
- */
- public SynchJDTPackageFragment(IPackageFragmentRoot iroot, GeneratorPreference preference) {
- super();
- this.iroot = iroot;
- this.preference = preference;
- }
-
-
- @Override
- public void visit(JDTJavaElement element) throws JDTVisitorException {
- // if element can't be generated, we stop all
- if (!element.isGenerated()) {
- return;
- }
- if (!preference.isPackageToGenerate(element.getElementName())) {
- return;
- }
-
- JDTPackageFragment packag = (JDTPackageFragment) element;
-
- try {
- // search the package
- IJavaElement tmp = null;
- IPackageFragment ipack = null;
-
-
- if ((tmp = SynchTools.searchIJavaElement(iroot.getChildren(), packag.getElementName())) != null &&
- tmp instanceof IPackageFragment) {
- ipack = (IPackageFragment) tmp;
- }
-
- // if name=null, it's the default package
- if (packag.getQualifiedName() == null) {
- // generate Compilation unit without package
- IJavaElement defaultPackageElement = SynchTools.searchIJavaElement(iroot.getChildren(), IPackageFragment.DEFAULT_PACKAGE_NAME);
- if (defaultPackageElement != null) {
- ipack = (IPackageFragment) defaultPackageElement;
- }
- }
-
- // if the package don't exist, we create it!
- if (ipack == null) {
-
- // find the name of the package
- ipack = iroot.createPackageFragment(packag.getQualifiedName(), true, null);
-
- }
-
- // call the children compilationUnit
- JDTVisitor visitor = new SynchJDTCompilationUnit(ipack, preference);
- for (JDTCompilationUnit cu : packag.getCompilationUnits()) {
- cu.accept(visitor);
- }
-
- } catch (JavaModelException e) {
- e.printStackTrace();
- throw new JDTVisitorException(e.getMessage(), e.getCause());
- } catch (Exception e) {
- e.printStackTrace();
- throw new JDTVisitorException(e.getMessage(), e.getCause());
- }
- }
-
-}
diff --git a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchJDTPackageFragmentRoot.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchJDTPackageFragmentRoot.java
deleted file mode 100644
index cf023088416..00000000000
--- a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchJDTPackageFragmentRoot.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2011 Nicolas Deblock & Manuel Giles.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Nicolas Deblock nico.deblock@gmail.com - Initial API and implementation
- * Manuel Giles giles.manu@live.fr - Initial API and implementation
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Idea of the java generator project & help for the conception
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.java.generator.jdtsynchronizer.impl;
-
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.jdt.core.IClasspathEntry;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.IPackageFragmentRoot;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.papyrus.java.generator.jdtsynchronizer.GeneratorPreference;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.JDTJavaElement;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.JDTPackageFragment;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.JDTPackageFragmentRoot;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.visitor.JDTVisitor;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.visitor.JDTVisitorException;
-
-
-/**
- * allow to generate package fragment root
- *
- * @author Deblock Nicolas & Manuel Giles
- *
- */
-public class SynchJDTPackageFragmentRoot implements JDTVisitor {
-
- private IJavaProject iprojet;
-
- private GeneratorPreference preference;
-
- /**
- * Constructor
- *
- * @param iprojet
- * the project parent
- */
- public SynchJDTPackageFragmentRoot(IJavaProject iprojet, GeneratorPreference preference) {
- super();
- this.iprojet = iprojet;
- this.preference = preference;
- }
-
-
-
- @Override
- public void visit(JDTJavaElement element) throws JDTVisitorException {
- // if element can't be generated, we stop all
- if (!element.isGenerated()) {
- return;
- }
-
- JDTPackageFragmentRoot root = (JDTPackageFragmentRoot) element;
-
- try {
- // research JDTPackageFragmentRoot
- IPackageFragmentRoot iroot = SynchTools.searchIJavaElement(iprojet.getAllPackageFragmentRoots(), root.getElementName());
-
- // if IPackageFragmentRoot don't exist, we create this
- if (iroot == null) {
- // create the folder
- IFolder sourceFolder = iprojet.getProject().getFolder(root.getElementName());
- try {
- sourceFolder.create(false, true, null);
- } catch (CoreException e) {
- // folder already exist
- }
-
- iroot = iprojet.getPackageFragmentRoot(sourceFolder);
- IClasspathEntry[] oldEntries = iprojet.getRawClasspath();
- List<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>();
-
- // copy the old entries in new entries
- for (int i = 0; i < oldEntries.length; i++) {
- // don't take the /projectName, else an exception are throw
- if (oldEntries[i] != null && !oldEntries[i].getPath().toString().equals("/" + iprojet.getElementName())) {
- newEntries.add(oldEntries[i]);
- }
- }
-
- // add the new packageFragmentRoot
- newEntries.add(JavaCore.newSourceEntry(iroot.getPath()));
-
- IClasspathEntry[] newEntriesArray = new IClasspathEntry[newEntries.size()];
- newEntries.toArray(newEntriesArray);
-
- iprojet.setRawClasspath(newEntriesArray, null);
-
- }
-
- // call children
- JDTVisitor visitPackageFragment = new SynchJDTPackageFragment(iroot, preference);
- for (JDTPackageFragment ipack : root.getPackageFragments()) {
- ipack.accept(visitPackageFragment);
- }
-
- } catch (JavaModelException e) {
- e.printStackTrace();
- throw new JDTVisitorException(e.getMessage(), e.getCause());
- }
- }
-}
diff --git a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchJDTType.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchJDTType.java
deleted file mode 100644
index 7d9560f1cc7..00000000000
--- a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchJDTType.java
+++ /dev/null
@@ -1,435 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2011 Nicolas Deblock & Manuel Giles.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Nicolas Deblock nico.deblock@gmail.com - Initial API and implementation
- * Manuel Giles giles.manu@live.fr - Initial API and implementation
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Idea of the java generator project & help for the conception
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.java.generator.jdtsynchronizer.impl;
-
-
-import java.util.LinkedList;
-import java.util.List;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jdt.core.Flags;
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.IJavaElement;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.eclipse.jdt.core.dom.TagElement;
-import org.eclipse.jdt.core.dom.TypeDeclaration;
-import org.eclipse.papyrus.java.generator.jdtsynchronizer.GeneratorPreference;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.JDTField;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.JDTJavaElement;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.JDTMethod;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.JDTType;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.visitor.JDTVisitor;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.visitor.JDTVisitorException;
-
-
-/**
- * Synchronize a JDTType with JDT.
- * Can create a type to a ICompilationUnit or to a IType (useful for intern class).
- *
- * @author Deblock Nicolas & Giles Manuel
- *
- */
-public class SynchJDTType extends SynchJDTCommentable {
-
- /**
- * Useful to create a type in a ICompilationUnit
- * If icu is null, itype can't be null
- */
- private ICompilationUnit icu;
-
- private GeneratorPreference preference;
-
- /**
- * Useful to create a type in a IType
- * If itype is null, icu can't be null
- */
- private IType itype;
-
- /**
- * Create a type to a ICompilationUnit
- *
- * @param icu
- */
- public SynchJDTType(ICompilationUnit icu, GeneratorPreference preference) {
- super();
- this.icu = icu;
- this.preference = preference;
- }
-
- /**
- * Create a type to a IType (useful for intern class)
- *
- * @param itype
- */
- public SynchJDTType(IType itype, GeneratorPreference preference) {
- super();
- this.itype = itype;
- this.preference = preference;
- }
-
-
-
- @Override
- public void visit(JDTJavaElement element) throws JDTVisitorException {
- // if element can't be generated, we stop all
- if (!element.isGenerated()) {
- return;
- }
- if (SynchTools.isPrimiveType(element.getElementName()) && !element.getElementName().equals("String")) {
- return;
- }
-
- JDTType type = (JDTType) element;
-
- try {
- IType it = SynchTools.searchIJavaElement(getTypes(), type.getElementName());
-
- // generate type
- if (it == null) {
- StringBuffer buffer = new StringBuffer();
-
- buffer.append(SynchTools.getVisibility(type));
-
- // System.out.println("\n\n \t \t ####### " + type.isEnum());
-
- if (type.isClass()) {
- buffer.append("class ");
- } else if (type.isInterface()) {
- buffer.append("interface ");
- } else if (type.isEnum()) {
-
- // System.out.println( type.getFields());
-
- // generate the field
- StringBuffer fieldStr = new StringBuffer();
- int i = 0;
- for (JDTField field : type.getFields()) {
- if (i > 0) {
- fieldStr.append(",\n");
- }
- fieldStr.append("\t" + field.getElementName());
- i++;
- }
- if (!type.getFields().isEmpty()) {
- fieldStr.append(";\n\n");
- }
-
- it = createType("public enum " + type.getElementName() + " { \n" + fieldStr + " \n } ", null, true, null);
- return;
- /*
- * it = createType("public enum " + type.getElementName() + " { \n" +
- * fieldStr +
- * "\tprivate final int value;\n\n"+
- *
- * "\tprivate "+ type.getElementName() +"(int value) {\n"+
- * "\t\tthis.value = value;\n"+
- * "\t}\n\n"+
- *
- * "\tpublic int getValue() {\n" +
- * "\t\treturn this.value;\n" +
- * "\t}\n" +
- * "\n}", null, true, null);
- * return;
- */
-
- }
- // else, generate nothing
- else {
- return;
- }
-
- buffer.append(type.getElementName());
-
- if (type.getSuperClass() != null) {
- buffer.append(" extends ");
- buffer.append(type.getSuperClass().getElementName());
-
- }
-
- if (type.getSuperInterfaces() != null && type.getSuperInterfaces().size() > 0) {
- if (type.isInterface()) {
- buffer.append(" extends ");
- } else {
- buffer.append(" implements ");
- }
-
- int i = 0;
- for (JDTType superInterface : type.getSuperInterfaces()) {
- if (i != 0) {
- buffer.append(", ");
- }
- buffer.append(superInterface.getElementName());
- i++;
- }
- }
-
- it = createType(buffer.toString() + " { \n\n}", null, true, null);
- }
-
- // add imports
- if (type.getSuperClass() != null) {
- SynchTools.createImport(it, type, type.getSuperClass());
- }
-
- if (type.getSuperInterfaces() != null) {
- for (JDTType superInterface : type.getSuperInterfaces()) {
- SynchTools.createImport(it, type, superInterface);
- }
- }
-
-
-
- // add javaDoc comment
- if (type.getComment() != null && !type.getComment().isEmpty()) {
- createJavaDocFor(it, it.getCompilationUnit(), type.getComment(), "");
- }
-
-
- // generate field
- if (!type.isEnum()) {
- JDTVisitor visitor = new SynchJDTField(it, preference);
- for (JDTField field : type.getFields()) {
- field.accept(visitor);
- }
- }
-
- // generate getters and setters
- JDTVisitor vgettersetter = new SynchJDTGetterSetter(it, preference);
- if (type.isClass()) {
- for (JDTField field : type.getFields()) {
- field.accept(vgettersetter);
- }
- }
-
-
- // generate method
- JDTVisitor vmethod = new SynchJDTMethod(it, preference);
- for (JDTMethod method : type.getMethods()) {
- method.accept(vmethod);
- }
-
- // The class implements interface methods only if it's not an abstract class
- if (!Flags.isAbstract(type.getFlags())) {
-
- // recover the superclass
- JDTType superClass = type.getSuperClass();
-
- // recover the interfaces
- List<JDTType> allSuperInterfaces = getAllSuperInterfaces(type);
-
- // Implement the abstract methods of the superClass (recursive method)
- if (preference.implementMethodsOfAbstractClass()) {
- implementSuperClassAbstractMethods(it, superClass);
- }
-
- // implements interfaces methods of the super-interfaces
- if (preference.implementMethodsOfIntefaces()) {
- for (JDTType superInterface : allSuperInterfaces) {
- for (JDTMethod superInterfaceMethod : superInterface.getMethods()) {
- superInterfaceMethod.accept(vmethod);
- }
- }
- }
- }
-
-
- // generate nested class
- JDTVisitor vClass = new SynchJDTType(it, preference);
- for (JDTType child : type.getTypes()) {
- child.accept(vClass);
- }
-
- // Generate explicit imports
- generateExplicitImports(type, it);
-
- } catch (JavaModelException e) {
- e.printStackTrace();
- throw new JDTVisitorException(e.getMessage(), e.getCause());
- } catch (Exception e) {
- e.printStackTrace();
- throw new JDTVisitorException(e.getMessage(), e.getCause());
- }
-
-
- }
-
- /**
- * Generate imports that are explicitly declared in the type
- *
- * @param it
- * The jdt type to be generated
- * @throws JavaModelException
- * @throws JDTVisitorException
- */
- private void generateExplicitImports(JDTType containerType, IType it) throws JDTVisitorException {
-
-
- // Add explicit type
- for (JDTType anImport : containerType.getExplicitRequiredImports()) {
- try {
- it.getCompilationUnit().createImport(anImport.getQualifiedName(), null, null);
- } catch (Exception e) {
- propagateException(it.getFullyQualifiedName() + "Can't add explicit import " + anImport.getQualifiedName(), e);
- }
- }
-
- // Add explicit plain text types
- for (String anImport : containerType.getExplicitPlainTextRequiredImports()) {
- try {
- it.getCompilationUnit().createImport(anImport, null, null);
- } catch (JavaModelException e) {
- propagateException(it.getFullyQualifiedName() + "Can't add explicit plain text import " + anImport, e);
- }
- }
-
- }
-
- /**
- * get current type
- *
- * @return
- * @throws JavaModelException
- */
- private IType[] getTypes() throws JavaModelException {
- if (icu != null) {
- return icu.getTypes();
- }
- return itype.getTypes();
- }
-
- /**
- * create type for a element 'sibling'
- *
- * @param contents
- * the source contents of the type declaration to add
- * @param sibling
- * the existing element which the type will be inserted immediately before (if null, then this type will be inserted as the last type
- * declaration
- * @param force
- * a flag in case the same name already exists in this type
- * @param monitor
- * the progress monitor to notify
- * @return the newly inserted type
- * @throws JavaModelException
- */
- private IType createType(String contents, IJavaElement sibling, boolean force, IProgressMonitor monitor) throws JavaModelException
- {
- if (icu != null) {
- return icu.createType(contents, sibling, force, monitor);
- }
-
- return itype.createType(contents, sibling, force, monitor);
- }
-
-
- @Override
- protected TypeDeclaration searchElementToInsert(CompilationUnit cu, IJavaElement typeName) {
- if (!(cu.types().get(0) instanceof TypeDeclaration)) {
- return null;
- }
- TypeDeclaration classType = (TypeDeclaration) cu.types().get(0);
- return searchType(classType, typeName.getElementName());
-
- }
-
- @Override
- protected List<String> getJavadocTags() {
- List<String> lst = new LinkedList<String>();
- lst.add(TagElement.TAG_AUTHOR);
- return lst;
- }
-
- /**
- * Collect all super interfaces from the super class and the super interfaces (JDTType). Recursive method.
- *
- * @param superClass
- * @return List of all super interfaces
- */
- public List<JDTType> getAllSuperInterfaces(JDTType _type) {
- List<JDTType> superInterfaces = new LinkedList<JDTType>();
-
- // recover its own interfaces
- superInterfaces.addAll(_type.getSuperInterfaces());
-
- // add interfaces of the super class if it's abstract
- if (_type.getSuperClass() != null && _type.getSuperClass().isAbstract()) {
- superInterfaces.addAll(getAllSuperInterfaces(_type.getSuperClass()));
- }
-
- // add interfaces of the super interfaces
- for (JDTType superInterface : _type.getSuperInterfaces()) {
- superInterfaces.addAll(getAllSuperInterfaces(superInterface));
- }
-
- return superInterfaces;
- }
-
- /**
- * Implement the abstract methods of the superClass if the superClass is abstract. It's a recursive method on the super class of the super class.
- *
- * @param it
- * @param superClass
- * @throws JDTVisitorException
- */
- public void implementSuperClassAbstractMethods(IType it, JDTType superClass) throws JDTVisitorException {
- if (superClass == null) {
- return;
- }
-
- JDTVisitor vmethod = new SynchJDTMethod(it, preference);
-
- if (Flags.isAbstract(superClass.getFlags())) {
- for (JDTMethod superClassAbstractMethod : superClass.getMethods()) {
- // Skip if method is not abstract
- if (!superClassAbstractMethod.isAbstract()) {
- continue;
- }
- // Remove the abstract flag to not generate the method with the keyword "abstract"
- superClassAbstractMethod.setAbstract(false);
- superClassAbstractMethod.accept(vmethod);
- superClassAbstractMethod.setAbstract(true);
- }
-
- // Recursive call on the super class of superClass
- JDTType superClassSuperClass = superClass.getSuperClass();
- if (superClassSuperClass != null) {
- implementSuperClassAbstractMethods(it, superClassSuperClass);
- }
- }
- }
-
- /**
- * Propagate a {@link JDTVisitorException} if the flag is not set
- *
- * @param msg
- * @param e
- * @throws JDTVisitorException
- */
- private void propagateException(String msg, Throwable e) throws JDTVisitorException {
-
- if (preference.stopOnFirstError()) {
- throw new JDTVisitorException(msg, e.getCause());
- }
- else {
- // Show error
- System.err.println(msg);
- e.printStackTrace();
- }
- }
-}
diff --git a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchTools.java b/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchTools.java
deleted file mode 100644
index 89a4d4a586d..00000000000
--- a/extraplugins/qompass/codegen/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/impl/SynchTools.java
+++ /dev/null
@@ -1,325 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2011 Nicolas Deblock & Manuel Giles.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Nicolas Deblock nico.deblock@gmail.com - Initial API and implementation
- * Manuel Giles giles.manu@live.fr - Initial API and implementation
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Idea of the java generator project & help for the conception
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.java.generator.jdtsynchronizer.impl;
-
-
-
-import org.eclipse.jdt.core.Flags;
-import org.eclipse.jdt.core.IJavaElement;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.papyrus.java.generator.jdtsynchronizer.GeneratorPreference;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.JDTMember;
-import org.eclipse.papyrus.java.generator.metamodel.jdt.jdtmm.JDTType;
-
-/**
- * gathers all the util function to synchronize with JDT
- *
- * @author Nicolas Deblock and Manuel Giles
- *
- */
-public class SynchTools {
-
-
- /**
- * Find a IJavaElement in a list of IJavaElement
- * It's util to search a children of a IJavaElement
- *
- * @param <U>
- * a IJavaElement
- * @param lstElement
- * list of IJavaElement
- * @param elementName
- * name of IJavaElement which is search
- * @return the element who is search, null if there is no element find
- */
- public static <U extends IJavaElement> U searchIJavaElement(U[] lstElement, String elementName) {
- for (U e : lstElement) {
- if (e.getElementName().equals(elementName)) {
- return e;
- }
- }
- return null;
- }
-
- /**
- * return the visibility of jdtMember :
- * public or private or protected, abstract, static, final, synchronized
- *
- * @param jdtMember
- * @return visibility of jdtMember
- */
- public static String getVisibility(JDTMember jdtMember) {
- StringBuffer buffer = new StringBuffer();
-
- if (Flags.isPublic(jdtMember.getFlags())) {
- buffer.append("public ");
- }
- if (Flags.isPrivate(jdtMember.getFlags())) {
- buffer.append("private ");
- }
- if (Flags.isProtected(jdtMember.getFlags())) {
- buffer.append("protected ");
- }
-
- if (Flags.isAbstract(jdtMember.getFlags())) {
- buffer.append("abstract ");
- }
-
- if (Flags.isStatic(jdtMember.getFlags())) {
- buffer.append("static ");
- }
- if (Flags.isFinal(jdtMember.getFlags())) {
- buffer.append("final ");
- }
- if (Flags.isSynchronized(jdtMember.getFlags())) {
- buffer.append("synchronized ");
- }
- return buffer.toString();
- }
-
- /**
- * allow to know if a type is primitive
- *
- * @param typename
- * @return true if typename is a primive type
- */
- public static boolean isPrimiveType(String typename) {
- if (typename.equals("byte")) {
- return true;
- }
- if (typename.equals("char")) {
- return true;
- }
- if (typename.equals("double")) {
- return true;
- }
- if (typename.equals("float")) {
- return true;
- }
- if (typename.equals("int")) {
- return true;
- }
- if (typename.equals("long")) {
- return true;
- }
- if (typename.equals("short")) {
- return true;
- }
- if (typename.equals("boolean")) {
- return true;
- }
- if (typename.equals("String")) {
- return true;
- }
- return false;
- }
-
- /**
- * Check if a name represents a pure Java primitive type.
- * Pure Java primitive type are Java primitive types that are keywords and not Classes (ie excluding String).
- *
- *
- * @param typename
- * @return true if typename is a primive type
- */
- public static boolean isPureJavaPrimiveType(String typename) {
- if (typename.equals("byte")) {
- return true;
- }
- if (typename.equals("char")) {
- return true;
- }
- if (typename.equals("double")) {
- return true;
- }
- if (typename.equals("float")) {
- return true;
- }
- if (typename.equals("int")) {
- return true;
- }
- if (typename.equals("long")) {
- return true;
- }
- if (typename.equals("short")) {
- return true;
- }
- if (typename.equals("boolean")) {
- return true;
- }
- if (typename.equals("String")) {
- return true;
- }
- return false;
- }
-
- /**
- * return the default return of a type (ex: 0 for a int, false for a boolean, null for a class,...)
- *
- * @param typename
- * @return true if typename is a primive type
- */
- public static String defaultReturn(String typename) {
- if (typename.equals("byte")) {
- return "0";
- }
- if (typename.equals("char")) {
- return "0";
- }
- if (typename.equals("double")) {
- return "0";
- }
- if (typename.equals("float")) {
- return "0";
- }
- if (typename.equals("int")) {
- return "0";
- }
- if (typename.equals("long")) {
- return "0";
- }
- if (typename.equals("short")) {
- return "0";
- }
- if (typename.equals("boolean")) {
- return "false";
- }
-
- return "null";
- }
-
- /**
- * return the Class of a primitive type (ex : int => Integer)
- *
- * @param typename
- * @return true if typename is a primive type
- */
- private static String getPrimiveTypeClass(String typename) {
- if (typename.equals("byte")) {
- return "Byte";
- }
- if (typename.equals("char")) {
- return "Character";
- }
- if (typename.equals("double")) {
- return "Double";
- }
- if (typename.equals("float")) {
- return "Float";
- }
- if (typename.equals("int")) {
- return "Integer";
- }
- if (typename.equals("long")) {
- return "Long";
- }
- if (typename.equals("short")) {
- return "Short";
- }
- if (typename.equals("boolean")) {
- return "Boolean";
- }
- return typename;
- }
-
-
- public static String getPackageFragment(JDTType type) {
- try {
- if (type.getCompilationUnit() != null) {
- return type.getCompilationUnit().getPackageFragment().getQualifiedName();
- } else {
- return getPackageFragment(type.getOwner());
- }
- } catch (NullPointerException e) {
- // id null pointer exception, we return null
- return null;
- }
- }
-
- public static void createImport(IType itype, JDTType currentType, JDTType importType) throws JavaModelException {
- String packageCurrentType = getPackageFragment(currentType);
- String packageImportType = getPackageFragment(importType);
-
- // if no package to import, stop
- if (packageImportType == null) {
- return;
- }
-
-
- // if they have the same package, and if it is not a nested class, we stop
- if (packageCurrentType != null && importType.getCompilationUnit() != null && packageCurrentType.equals(packageImportType)) {
- return;
- }
-
- // Check if the last segment name is not a primitive name.
- // Stop if it is the case (otherwise createImport() throw an exception)
- if( isPureJavaPrimiveType(importType.getElementName())) {
- return;
- }
-
- String _import = importType.getQualifiedName();
- if (!SynchTools.isPrimiveType(_import) && _import.contains(".")) {
- itype.getCompilationUnit().createImport(_import, null, null);
- }
- }
-
- /**
- * Get the multivalued declaration for the specified typeName.
- *
- * @param type
- * The enclosing type that will contains the declaration. Requested to ajust import.
- * @param typeName
- * The type for wich a multivalued statement is requested
- * @param preference
- * The preferences
- * @return The multivalued statement for the specified typeName.
- *
- * @throws JavaModelException
- */
- public static String getMultiValued(IType type, String typeName, GeneratorPreference preference) throws JavaModelException {
- // create the import
- String _classQualifiedName = preference.genericClassForMultiValue();
- String _class = _classQualifiedName.substring(_classQualifiedName.lastIndexOf(".") + 1);
-
- type.getCompilationUnit().createImport(_classQualifiedName, null, null);
- return _class + "<" + getPrimiveTypeClass(typeName) + ">";
- }
-
- /**
- * Get the multivalued declaration for the specified typeName.
- *
- * @param type
- * The enclosing type that will contains the declaration. Requested to ajust import.
- * @param typeName
- * The type for wich a multivalued statement is requested
- * @param preference
- * The preferences
- * @return The multivalued statement for the specified typeName.
- *
- * @throws JavaModelException
- */
- public static String getMultiValued(IType type, JDTType valueType, GeneratorPreference preference) throws JavaModelException {
- // create the import
- String _classQualifiedName = preference.genericClassForMultiValue();
- String _class = _classQualifiedName.substring(_classQualifiedName.lastIndexOf(".") + 1);
-
- type.getCompilationUnit().createImport(_classQualifiedName, null, null);
- return _class + "<" + getPrimiveTypeClass(valueType.getElementName()) + ">";
- }
-
-}

Back to the top