diff options
author | Ansgar Radermacher | 2015-09-03 11:42:02 +0000 |
---|---|---|
committer | Ansgar Radermacher | 2015-09-03 11:45:53 +0000 |
commit | 4b44400db605ef44a6877c7287fe2ef31b12a585 (patch) | |
tree | 729ee5b4f20ce3a2728c13111590fb59eb5ed97a /extraplugins/codegen | |
parent | f2983ae60cc3e163befebda6ab79e383d0beff2c (diff) | |
download | org.eclipse.papyrus-4b44400db605ef44a6877c7287fe2ef31b12a585.tar.gz org.eclipse.papyrus-4b44400db605ef44a6877c7287fe2ef31b12a585.tar.xz org.eclipse.papyrus-4b44400db605ef44a6877c7287fe2ef31b12a585.zip |
474339 - [CDT integration] Synchronization of code to model requires additional information (fix NPE)
Diffstat (limited to 'extraplugins/codegen')
2 files changed, 88 insertions, 34 deletions
diff --git a/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/sync/ParameterModifiers.java b/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/sync/ParameterModifiers.java new file mode 100644 index 00000000000..8601ac73484 --- /dev/null +++ b/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/sync/ParameterModifiers.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * 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; + +/** + * Simple grouping of modifier related parameters + */ +public class ParameterModifiers { + public ParameterModifiers() { + isPointer = false; + isRef = false; + isRegister = false; + array = ""; //$NON-NLS-1$ + } + + /** + * true, if parameter is a pointer + */ + boolean isPointer; + + /** + * true, if parameter is a reference + */ + boolean isRef; + + /** + * true, if parameter is a register + */ + boolean isRegister; + + /** + * value of array modifiers (e.g. [2]) + */ + String array ; +} 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 53b5aa2c6ac..1a0d635b974 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 @@ -328,22 +328,19 @@ public class SyncCDTtoModel implements Runnable { IASTParameterDeclaration parameter = (IASTParameterDeclaration) declaratorChild; IASTName parameterName = parameter.getDeclarator().getName(); IASTDeclSpecifier parameterType = parameter.getDeclSpecifier(); - boolean isPointer = false; - boolean isRef = false; - boolean isRegister = false; - String array = ""; //$NON-NLS-1$ + ParameterModifiers modifiers = new ParameterModifiers(); String parameterTypeName = ""; //$NON-NLS-1$ try { IToken token = parameter.getDeclarator().getSyntax(); while (token != null) { String tokenStr = token.toString(); if (tokenStr.equals("*")) { //$NON-NLS-1$ - isPointer = true; + modifiers.isPointer = true; } else if (tokenStr.equals("&")) { //$NON-NLS-1$ - isRef = true; + modifiers.isRef = true; } else if (tokenStr.equals("[")) { //$NON-NLS-1$ while (token != null) { - array += token.toString(); + modifiers.array += token.toString(); token = token.getNext(); } if (token == null) { @@ -359,11 +356,11 @@ public class SyncCDTtoModel implements Runnable { if (tokenStr.equals("*")) { //$NON-NLS-1$ // TODO: check, if this can be called (depending on // * position with different semantics?) - isPointer = true; + modifiers.isPointer = true; } else if (tokenStr.equals("&")) { //$NON-NLS-1$ - isRef = true; + modifiers.isRef = true; } else if (tokenStr.equals(REGISTER)) { - isRegister = true; + modifiers.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 @@ -390,31 +387,10 @@ public class SyncCDTtoModel implements Runnable { Type paramType = namedElemParamType instanceof Type ? (Type) namedElemParamType : null; if (operation != null) { umlParameter = operation.createOwnedParameter(parameterName.toString(), paramType); + applyParameterModifiers(parameterType, umlParameter, modifiers); } - behavior.createOwnedParameter(parameterName.toString(), paramType); - if (parameterType.isConst()) { - StereotypeUtil.apply(umlParameter, Const.class); - } - 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) { - StereotypeUtil.apply(umlParameter, Ref.class); - } - if (array.length() > 0) { - Array arraySt = StereotypeUtil.applyApp(umlParameter, Array.class); - if (arraySt != null && !array.equals("[]") && (!array.equals("[ ]"))) { //$NON-NLS-1$//$NON-NLS-2$ - arraySt.setDefinition(array); - } - } + umlParameter = behavior.createOwnedParameter(parameterName.toString(), paramType); + applyParameterModifiers(parameterType, umlParameter, modifiers); } } @@ -447,6 +423,39 @@ public class SyncCDTtoModel implements Runnable { } /** + * Apply the modifiers for a parameter, notably the stereotypes of the C++ profile + * + * @param parameterType the CDT AST parameter specification + * @param umlParameter the UML parameter (to which a stereotype should be applied) + * @param modifiers the modifiers that should be applied (stored in an instance of class ParameterModifiers) + */ + public void applyParameterModifiers(IASTDeclSpecifier parameterType, Parameter umlParameter, ParameterModifiers modifiers) { + if (parameterType.isConst()) { + StereotypeUtil.apply(umlParameter, Const.class); + } + if (parameterType.isVolatile()) { + StereotypeUtil.apply(umlParameter, Volatile.class); + } + if (modifiers.isRegister) { + StorageClass sc = StereotypeUtil.applyApp(umlParameter, StorageClass.class); + if (sc != null) { + sc.setStorageClass(EStorageClass.REGISTER); + } + } + if (modifiers.isPointer) { + StereotypeUtil.apply(umlParameter, Ptr.class); + } else if (modifiers.isRef) { + StereotypeUtil.apply(umlParameter, Ref.class); + } + if (modifiers.array.length() > 0) { + Array arraySt = StereotypeUtil.applyApp(umlParameter, Array.class); + if (arraySt != null && !modifiers.array.equals("[]") && (!modifiers.array.equals("[ ]"))) { //$NON-NLS-1$//$NON-NLS-2$ + arraySt.setDefinition(modifiers.array); + } + } + } + + /** * Obtain an operation from the model by using the name of a CDT method. * If an operation of the given name does not exist, it might indicate that * the method has been renamed. |