diff options
author | Ansgar Radermacher | 2015-09-09 13:35:17 +0000 |
---|---|---|
committer | Ansgar Radermacher | 2015-09-09 13:36:59 +0000 |
commit | 1a1bf568488e02d8102a2bb469950437e54ec1e7 (patch) | |
tree | 8baea0e3cf5a6f1d2d112b09d8e4a6b2c44e6ee2 | |
parent | fa39899e0ca25d3762151f48f68ec9e61f064ee3 (diff) | |
download | org.eclipse.papyrus-bugs/476559-expand-performance.tar.gz org.eclipse.papyrus-bugs/476559-expand-performance.tar.xz org.eclipse.papyrus-bugs/476559-expand-performance.zip |
474339 - [CDT integration] Synchronization of code to model requires additional information (element based eligibility filtering)bugs/476559-expand-performance
4 files changed, 64 insertions, 37 deletions
diff --git a/extraplugins/codegen/org.eclipse.papyrus.codegen.extensionpoints/src/org/eclipse/papyrus/codegen/extensionpoints/ILangCodegen2.java b/extraplugins/codegen/org.eclipse.papyrus.codegen.extensionpoints/src/org/eclipse/papyrus/codegen/extensionpoints/ILangCodegen2.java index f75d7de8b20..1cf48b4455a 100644 --- a/extraplugins/codegen/org.eclipse.papyrus.codegen.extensionpoints/src/org/eclipse/papyrus/codegen/extensionpoints/ILangCodegen2.java +++ b/extraplugins/codegen/org.eclipse.papyrus.codegen.extensionpoints/src/org/eclipse/papyrus/codegen/extensionpoints/ILangCodegen2.java @@ -1,7 +1,7 @@ package org.eclipse.papyrus.codegen.extensionpoints; +import org.eclipse.uml2.uml.Element; import org.eclipse.uml2.uml.NamedElement; -import org.eclipse.uml2.uml.Package; public interface ILangCodegen2 extends ILangCodegen { @@ -11,28 +11,32 @@ public interface ILangCodegen2 extends ILangCodegen { public String getDescription(); /** - * Some code generators use a non-trivial mapping from behaviors to methods in the generated code or - * add methods that are not part of a existing behavior in the model. - * This is a problem for code synchronization (update of model from code) as done for instance - * with the CDT editor integration. + * Some code generators use a non-trivial mapping from behaviors to methods + * in the generated code or add methods that are not part of a existing + * behavior in the model. This is a problem for code synchronization (update + * of model from code) as done for instance with the CDT editor integration. * - * @param methodName the name of the method as in the code - * @param body the body - * @return the associated synchronization information. Null indicates that a default mapping is used + * @param methodName + * the name of the method as in the code + * @param body + * the body + * @return the associated synchronization information. Null indicates that a + * default mapping is used */ public SyncInformation getSyncInformation(String methodName, String body); - + /** - * Return true, if the generator is eligible for a certain type of model. - * The method may check for instance whether a certain profile (such as - * UML-RT) has been applied. Generators are allowed to return true for all - * models, if they do not have specific (profile related) requirements. + * Return true, if the generator is eligible for a certain element within a + * model. The code generator may check the element itself, but also for + * instance whether a certain profile (such as UML-RT) has been applied. + * Generators are allowed to return true for all models, if they do not have + * specific (profile related) requirements. * * @param modelRoot * the root of a UML model (for which code should be generated) * @return true, iff the generator is eligible for this model */ - public boolean isEligible(Package modelRoot); + public boolean isEligible(Element modelElement); /** * Return the suffix of a code generator. Some languages use different @@ -44,10 +48,11 @@ public interface ILangCodegen2 extends ILangCodegen { * @return */ public String getSuffix(FILE_KIND fileKind); - + /** - * return additional information about the method that has been generated for a UML behavior. - * This information is used by the CDT editor integration to locate the method in the code. + * return additional information about the method that has been generated + * for a UML behavior. This information is used by the CDT editor + * integration to locate the method in the code. */ public MethodInfo getMethodInfo(NamedElement operationOrBehavior); } diff --git a/extraplugins/codegen/org.eclipse.papyrus.codegen.extensionpoints/src/org/eclipse/papyrus/codegen/extensionpoints/LanguageCodegen.java b/extraplugins/codegen/org.eclipse.papyrus.codegen.extensionpoints/src/org/eclipse/papyrus/codegen/extensionpoints/LanguageCodegen.java index 1ae6609dbf0..2bb0796017c 100644 --- a/extraplugins/codegen/org.eclipse.papyrus.codegen.extensionpoints/src/org/eclipse/papyrus/codegen/extensionpoints/LanguageCodegen.java +++ b/extraplugins/codegen/org.eclipse.papyrus.codegen.extensionpoints/src/org/eclipse/papyrus/codegen/extensionpoints/LanguageCodegen.java @@ -24,11 +24,9 @@ import org.eclipse.core.runtime.IExtensionRegistry; import org.eclipse.core.runtime.Platform; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.papyrus.uml.tools.utils.PackageUtil; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.uml2.uml.Classifier; -import org.eclipse.uml2.uml.Package; /** * Common interface to generate code. Supports for multiple target languages via @@ -132,11 +130,9 @@ public class LanguageCodegen { */ public static List<ILangCodegen> getEligibleGeneratorList(Pattern languagePattern, Classifier classifier) { List<ILangCodegen> eligibleGenerators = new ArrayList<ILangCodegen>(); - Package modelRoot = PackageUtil.getRootPackage(classifier); - for (ILangCodegen generator : getCodegenList(languagePattern)) { if (generator instanceof ILangCodegen2) { - if (((ILangCodegen2) generator).isEligible(modelRoot)) { + if (((ILangCodegen2) generator).isEligible(classifier)) { eligibleGenerators.add(generator); } } diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/CppLangCodegen.java b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/CppLangCodegen.java index b5395d3f019..a9467bc3191 100644 --- a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/CppLangCodegen.java +++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/CppLangCodegen.java @@ -24,6 +24,7 @@ import org.eclipse.papyrus.cpp.codegen.transformation.CppModelElementsCreator; import org.eclipse.papyrus.cpp.codegen.utils.LocateCppProject; import org.eclipse.papyrus.cpp.codegen.xtend.CppParameter; import org.eclipse.uml2.uml.Behavior; +import org.eclipse.uml2.uml.Classifier; import org.eclipse.uml2.uml.Element; import org.eclipse.uml2.uml.NamedElement; import org.eclipse.uml2.uml.Operation; @@ -31,6 +32,7 @@ import org.eclipse.uml2.uml.Package; import org.eclipse.uml2.uml.PackageableElement; import org.eclipse.uml2.uml.Parameter; import org.eclipse.uml2.uml.ParameterDirectionKind; +import org.eclipse.uml2.uml.Profile; /** * C++ language support @@ -44,27 +46,40 @@ public class CppLangCodegen implements ILangCodegen2 { @Override public String getDescription() { - return Messages.C_CppLangCodegen_GeneratorDesc; + return Messages.C_CppLangCodegen_GeneratorDesc; } + /** + * Check whether the code generator is able to produce code for the passed element: + * it must be a classifier and the C++ profile must be applied. + */ @Override - public boolean isEligible(Package modelRoot) { - return (modelRoot.getAppliedProfile(C_CppPackage.eINSTANCE.getName()) != null); + public boolean isEligible(Element modelElement) { + if (modelElement instanceof Classifier) { + Package nearestPackage = modelElement.getNearestPackage(); + if (nearestPackage != null) { + // check whether the C++ profile is applied + for (Profile profile : nearestPackage.getAllAppliedProfiles()) { + if (profile.getName().equals(C_CppPackage.eINSTANCE.getName())) { + return true; + } + } + } + } + return false; } - + @Override public String getSuffix(FILE_KIND fileKind) { if (fileKind == FILE_KIND.BODY) { return CppCodeGenUtils.getBodySuffix(); - } - else { + } else { return CppCodeGenUtils.getHeaderSuffix(); } } - + @Override - public void generateCode(IProject project, PackageableElement element, IProgressMonitor monitor) - { + public void generateCode(IProject project, PackageableElement element, IProgressMonitor monitor) { manageCreator(project, element); creator.createPackageableElement(element, monitor); } @@ -85,7 +100,7 @@ public class CppLangCodegen implements ILangCodegen2 { public IProject getTargetProject(PackageableElement pe, boolean createIfMissing) { return LocateCppProject.getTargetProject(pe, createIfMissing); } - + protected void manageCreator(IProject project, Element element) { if ((project == null) && (element instanceof PackageableElement)) { project = getTargetProject((PackageableElement) element, false); @@ -106,12 +121,11 @@ public class CppLangCodegen implements ILangCodegen2 { MethodInfo mi = new MethodInfo(operationOrBehavior.getName()); EList<Parameter> parameters = null; if (operationOrBehavior instanceof Operation) { - parameters = ((Operation) operationOrBehavior).getOwnedParameters(); + parameters = ((Operation) operationOrBehavior).getOwnedParameters(); + } else if (operationOrBehavior instanceof Behavior) { + parameters = ((Behavior) operationOrBehavior).getOwnedParameters(); } - else if (operationOrBehavior instanceof Behavior) { - parameters = ((Behavior) operationOrBehavior).getOwnedParameters(); - } - + if (parameters != null) { for (Parameter parameter : parameters) { if (parameter.getDirection() != ParameterDirectionKind.RETURN_LITERAL) { diff --git a/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/handler/PapyrusCDTEditorHandler.java b/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/handler/PapyrusCDTEditorHandler.java index 191147e0c6e..7d6df1edfc4 100644 --- a/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/handler/PapyrusCDTEditorHandler.java +++ b/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/handler/PapyrusCDTEditorHandler.java @@ -54,6 +54,7 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.uml2.uml.Behavior;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Classifier;
+import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Operation;
import org.eclipse.uml2.uml.Transition;
import org.eclipse.uml2.uml.UMLPackage;
@@ -77,6 +78,7 @@ public class PapyrusCDTEditorHandler extends CmdHandler { @Override
public boolean isEnabled() {
updateSelectedEObject();
+ // Filter Classes (including Behaviors, since Behavior inherits from Class), Operation and Transition
if (selectedEObject instanceof Class ||
selectedEObject instanceof Operation ||
selectedEObject instanceof Transition)
@@ -251,6 +253,16 @@ public class PapyrusCDTEditorHandler extends CmdHandler { else if (selectedEObject instanceof Transition) {
return ((Transition) selectedEObject).getContainer().getStateMachine().getContext();
}
+ else if (selectedEObject instanceof Behavior) {
+ Element owner = (Behavior) selectedEObject;
+ while (owner != null) {
+ owner = owner.getOwner();
+ if ((owner instanceof Classifier) && !(owner instanceof Behavior)) {
+ return (Classifier) owner;
+ }
+ }
+ return null;
+ }
else if (selectedEObject instanceof Classifier) {
// must be class or datatype
return (Classifier) selectedEObject;
|