diff options
Diffstat (limited to 'extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt')
5 files changed, 111 insertions, 34 deletions
diff --git a/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/editor/PapyrusCDTEditor.java b/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/editor/PapyrusCDTEditor.java index dee8abaf9cf..4ae37530cac 100644 --- a/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/editor/PapyrusCDTEditor.java +++ b/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/editor/PapyrusCDTEditor.java @@ -293,14 +293,11 @@ public class PapyrusCDTEditor extends CEditor { * @throws CoreException
*/
public void gotoElement(NamedElement element) {
- // IFile srcFile = SyncModelToCDT.syncModelToCDT((Classifier) pe);
- // ITranslationUnit itu2 = (ITranslationUnit) CoreModel.getDefault().create(srcFile);
-
ICElement ice = CDTUITools.getEditorInputCElement(m_input);
if (ice instanceof ITranslationUnit) {
ITranslationUnit itu = (ITranslationUnit) ice;
- ICElement icElement = ObtainICElement.getICElement(itu, element);
+ ICElement icElement = ObtainICElement.getICElement(syncCpp.getCodeGen(), itu, element);
if (icElement instanceof ISourceReference) {
try {
ISourceRange range = ((ISourceReference) icElement).getSourceRange();
@@ -386,9 +383,6 @@ public class PapyrusCDTEditor extends CEditor { protected IAction textUndo, textRedo;
- // TODO: remove, unused
- protected IActionBars gmfActionBars, textActionBars;
-
protected boolean oldDirty;
protected ISaveAndDirtyService saveAndDirtyService;
diff --git a/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/sync/FindTransition.java b/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/sync/FindTransition.java index 8db8ecfb4c0..e737e45abf3 100644 --- a/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/sync/FindTransition.java +++ b/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/sync/FindTransition.java @@ -1,3 +1,15 @@ +/******************************************************************************* + * Copyright (c) 2013 CEA LIST. + * 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: + * Ansgar Radermacher - ansgar.radermacher@cea.fr CEA LIST - initial API and implementation + * + *******************************************************************************/ + package org.eclipse.papyrus.texteditor.cdt.sync; import org.eclipse.uml2.uml.Behavior; @@ -6,6 +18,10 @@ import org.eclipse.uml2.uml.Element; import org.eclipse.uml2.uml.NamedElement; import org.eclipse.uml2.uml.Transition; +/** + * Find the behavior in the model from a given method in the code. Used during the + * back synchronization from code to model. + */ public class FindTransition { private static final String UNDERSCORE = "_"; //$NON-NLS-1$ diff --git a/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/sync/ObtainICElement.java b/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/sync/ObtainICElement.java index 0fdcf395ecb..e5457380c45 100644 --- a/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/sync/ObtainICElement.java +++ b/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/sync/ObtainICElement.java @@ -12,11 +12,17 @@ package org.eclipse.papyrus.texteditor.cdt.sync; +import java.util.Iterator; + import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.IFunctionDeclaration; import org.eclipse.cdt.core.model.IParent; import org.eclipse.core.runtime.CoreException; import org.eclipse.emf.common.util.EList; +import org.eclipse.papyrus.codegen.extensionpoints.ILangCodegen; +import org.eclipse.papyrus.codegen.extensionpoints.ILangCodegen2; +import org.eclipse.papyrus.codegen.extensionpoints.MethodInfo; +import org.eclipse.uml2.uml.Behavior; import org.eclipse.uml2.uml.NamedElement; import org.eclipse.uml2.uml.Operation; import org.eclipse.uml2.uml.Parameter; @@ -41,32 +47,61 @@ public class ObtainICElement { * A named UML element * @throws CoreException */ - public static ICElement getICElement(IParent parent, NamedElement element) { + public static ICElement getICElement(ILangCodegen codegen, IParent parent, NamedElement element) { + MethodInfo methodInfo = null; + NamedElement operationOrBehavior = element; + if (element instanceof Transition) { + operationOrBehavior = ((Transition) element).getEffect(); + } + + // no behavior found => not possible to locate element + if (operationOrBehavior == null) { + return null; + } + + if (codegen instanceof ILangCodegen2) { + // get generator specific method info. + methodInfo = ((ILangCodegen2) codegen).getMethodInfo(operationOrBehavior); + } + if (methodInfo == null) { + // use default behavior. + if (element instanceof Behavior) { + methodInfo = MethodInfo.fromBehavior((Behavior) operationOrBehavior); + } + else if (element instanceof Operation) { + methodInfo = MethodInfo.fromOperation((Operation) operationOrBehavior); + } + else { + return null; + } + } + try { for (ICElement child : parent.getChildren()) { if (child instanceof IParent) { - return getICElement((IParent) child, element); + return getICElement(codegen, (IParent) child, element); } if (child instanceof IFunctionDeclaration) { IFunctionDeclaration function = (IFunctionDeclaration) child; - - if (element instanceof Operation) { - if (child.getElementName().endsWith(NamedElement.SEPARATOR + element.getName())) { - // check, if number of parameter matches. TODO: this only handles a part of possible overloading cases - if (function.getNumberOfParameters() == countParameters(((Operation) element).getOwnedParameters())) { - return child; - } - } - } - else if (element instanceof Transition) { - Transition transition = (Transition) element; - if (transition.getEffect() != null) { - if (FindTransition.behaviorMatches(transition.getEffect(), child.getElementName())) { - - if (function.getNumberOfParameters() == countParameters(transition.getEffect().getOwnedParameters())) { - return child; + + // does the element name match? (CDT provides className::methodName information). Since we are in the scope of + // the class, we only verify the postfix part of the name + if (child.getElementName().endsWith(NamedElement.SEPARATOR + methodInfo.getName())) { + // check, if parameters match. This handles most common overloading cases (it does not handle functions that + // only differ with respect to the modifiers + Iterator<String> paramIter = methodInfo.getParameterTypes().iterator(); + boolean match = methodInfo.getParameterTypes().size() == function.getParameterTypes().length; + if (match) { + for (String cdtParamType : function.getParameterTypes()) { + String umlParamType = paramIter.next(); + if (!cdtParamType.equals(umlParamType)) { + match = false; + break; } } + if (match) { + return child; + } } } } diff --git a/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/sync/SyncCDTtoModel.java b/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/sync/SyncCDTtoModel.java index c25b00ef4b0..53b5aa2c6ac 100644 --- a/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/sync/SyncCDTtoModel.java +++ b/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/sync/SyncCDTtoModel.java @@ -44,11 +44,14 @@ import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.emf.common.util.EList; import org.eclipse.papyrus.C_Cpp.Array; import org.eclipse.papyrus.C_Cpp.Const; +import org.eclipse.papyrus.C_Cpp.EStorageClass; import org.eclipse.papyrus.C_Cpp.Include; import org.eclipse.papyrus.C_Cpp.Ptr; import org.eclipse.papyrus.C_Cpp.Ref; +import org.eclipse.papyrus.C_Cpp.StorageClass; import org.eclipse.papyrus.C_Cpp.Volatile; import org.eclipse.papyrus.codegen.extensionpoints.ILangCodegen; +import org.eclipse.papyrus.codegen.extensionpoints.ILangCodegen2; import org.eclipse.papyrus.codegen.extensionpoints.LanguageCodegen; import org.eclipse.papyrus.codegen.extensionpoints.SyncInformation; import org.eclipse.papyrus.cpp.codegen.Constants; @@ -75,6 +78,12 @@ import org.eclipse.uml2.uml.UMLPackage; public class SyncCDTtoModel implements Runnable { + public static final String REGISTER = "register"; //$NON-NLS-1$ + + public static final String CONST = "const"; //$NON-NLS-1$ + + public static final String VOLATILE = "volatile"; //$NON-NLS-1$ + public static final String sAtParam = "@param"; //$NON-NLS-1$ public static final String ansiCLib = "AnsiCLibrary"; //$NON-NLS-1$ @@ -171,9 +180,13 @@ public class SyncCDTtoModel implements Runnable { if (node instanceof IASTFunctionDefinition) { IASTFunctionDefinition definition = (IASTFunctionDefinition) node; IASTFunctionDeclarator declarator = definition.getDeclarator(); - String body = getBody(itu, definition); + String unfilteredBody = getBody(itu, definition); // get additional information about method synchronization from generator - SyncInformation syncInfo = m_codegen.getSyncInformation(name, body); + SyncInformation syncInfo = null; + if (m_codegen instanceof ILangCodegen2) { + syncInfo = ((ILangCodegen2) m_codegen).getSyncInformation(name, unfilteredBody); + } + String body = Utils.removeGenerated(unfilteredBody); if (syncInfo == null || !syncInfo.isGenerated) { // only update method, if it is not generated NamedElement ne = updateMethod(position, parent, name, body, declarator, syncInfo); @@ -317,6 +330,7 @@ public class SyncCDTtoModel implements Runnable { IASTDeclSpecifier parameterType = parameter.getDeclSpecifier(); boolean isPointer = false; boolean isRef = false; + boolean isRegister = false; String array = ""; //$NON-NLS-1$ String parameterTypeName = ""; //$NON-NLS-1$ try { @@ -348,9 +362,10 @@ public class SyncCDTtoModel implements Runnable { isPointer = true; } else if (tokenStr.equals("&")) { //$NON-NLS-1$ isRef = true; - } else if (tokenStr.equals("const")) { //$NON-NLS-1$ - // do nothing (use isConst() operation of - // parameterType) + } else if (tokenStr.equals(REGISTER)) { + isRegister = true; + } else if (tokenStr.equals(CONST) || tokenStr.equals(VOLATILE)) { + // do nothing (use isConst() or isVolatile() operation of parameterType) // is not part of parameter type } else { if (parameterTypeName.length() > 0) { @@ -383,6 +398,12 @@ public class SyncCDTtoModel implements Runnable { if (parameterType.isVolatile()) { StereotypeUtil.apply(umlParameter, Volatile.class); } + if (isRegister) { + StorageClass sc = StereotypeUtil.applyApp(umlParameter, StorageClass.class); + if (sc != null) { + sc.setStorageClass(EStorageClass.REGISTER); + } + } if (isPointer) { StereotypeUtil.apply(umlParameter, Ptr.class); } else if (isRef) { @@ -394,7 +415,6 @@ public class SyncCDTtoModel implements Runnable { arraySt.setDefinition(array); } } - } } @@ -481,8 +501,7 @@ public class SyncCDTtoModel implements Runnable { // cannot use the // first and last statement, since leading and trailing comments are // not part of the AST tree. - String bodyStr = Utils.decreaseIndent(contents, start + 2, end - 2); - return Utils.removeGenerated(bodyStr); + return Utils.decreaseIndent(contents, start + 2, end - 2); } return ""; //$NON-NLS-1$ } @@ -578,6 +597,14 @@ public class SyncCDTtoModel implements Runnable { } /** + * Accessor + * @return value of codegen attribute + */ + public ILangCodegen getCodeGen() { + return m_codegen; + } + + /** * input of the CDT editor. Used to obtain code within editor. */ protected IEditorInput m_input; diff --git a/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/sync/SyncModelToCDT.java b/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/sync/SyncModelToCDT.java index 50a2af1c0ff..207dfa013c9 100644 --- a/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/sync/SyncModelToCDT.java +++ b/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/sync/SyncModelToCDT.java @@ -20,6 +20,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.Path; import org.eclipse.papyrus.codegen.extensionpoints.ILangCodegen; import org.eclipse.papyrus.codegen.extensionpoints.ILangCodegen.FILE_KIND; +import org.eclipse.papyrus.codegen.extensionpoints.ILangCodegen2; import org.eclipse.papyrus.codegen.extensionpoints.LanguageCodegen; import org.eclipse.papyrus.cpp.codegen.Constants; import org.eclipse.papyrus.infra.core.Activator; @@ -34,6 +35,7 @@ import org.eclipse.uml2.uml.Classifier; */ public class SyncModelToCDT { + private static final String CPP_SUFFIX = "cpp"; //$NON-NLS-1$ /** * set to true, if a synchronization from an CDT editor to the model is active */ @@ -56,7 +58,10 @@ public class SyncModelToCDT { try { codegen.generateCode(modelProject, classifier, null); // need listener for sync in both directions! - cppFile = modelProject.getFile(new Path(codegen.getFileName(modelProject, classifier) + Constants.DOT + codegen.getSuffix(FILE_KIND.BODY))); + String suffix = (codegen instanceof ILangCodegen2) ? + suffix = ((ILangCodegen2) codegen).getSuffix(FILE_KIND.BODY) : CPP_SUFFIX; + + cppFile = modelProject.getFile(new Path(codegen.getFileName(modelProject, classifier) + Constants.DOT + suffix)); // IStorage storage = new TextStorage(string); } finally { |