From d68ed8353d18fcab69211c3fa074fcaa5963cc1e Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Wed, 29 Sep 2010 12:57:42 +0000 Subject: [PATCH] Bug 326372: Enhancing CElementHandles by Patrick Hofer. --- .../internal/core/model/ext/CElementHandle.java | 4 ---- .../cdt/internal/core/model/ext/FieldHandle.java | 15 +++++++++++++++ .../core/model/ext/FunctionDeclarationHandle.java | 9 ++++++++- .../core/model/ext/MethodDeclarationHandle.java | 7 +++++++ .../internal/core/model/ext/VariableHandle.java | 15 +++++++++++++++ 5 files changed, 45 insertions(+), 5 deletions(-) diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ext/CElementHandle.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ext/CElementHandle.java index 8702443d89e..91bce3b1b1a 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ext/CElementHandle.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ext/CElementHandle.java @@ -213,10 +213,6 @@ abstract class CElementHandle implements ICElementHandle, ISourceReference { return ""; //$NON-NLS-1$ } - public String getReturnType() { - return ""; //$NON-NLS-1$ - } - public boolean isConst() { return false; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ext/FieldHandle.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ext/FieldHandle.java index 7eba6051567..3af4b29a178 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ext/FieldHandle.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ext/FieldHandle.java @@ -10,6 +10,9 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.model.ext; +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IField; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ICElement; @@ -18,14 +21,26 @@ import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; public class FieldHandle extends CElementHandle implements org.eclipse.cdt.core.model.IField { private ASTAccessVisibility fVisibility; + private String fTypeName; private boolean fIsStatic; public FieldHandle(ICElement parent, IField field) { super(parent, ICElement.C_FIELD, field.getName()); + try { + fTypeName= ASTTypeUtil.getType(field.getType(), false); + } catch (DOMException e) { + CCorePlugin.log(e); + fTypeName= ""; //$NON-NLS-1$ + } fVisibility= getVisibility(field); fIsStatic= field.isStatic(); } + @Override + public String getTypeName() { + return fTypeName; + } + public ASTAccessVisibility getVisibility() throws CModelException { return fVisibility; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ext/FunctionDeclarationHandle.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ext/FunctionDeclarationHandle.java index d809f02c529..befa799fb40 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ext/FunctionDeclarationHandle.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ext/FunctionDeclarationHandle.java @@ -11,6 +11,7 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.model.ext; +import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IFunction; import org.eclipse.cdt.core.model.CModelException; @@ -18,9 +19,10 @@ import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.IFunctionDeclaration; import org.eclipse.cdt.internal.core.model.FunctionDeclaration; -public class FunctionDeclarationHandle extends CElementHandle implements org.eclipse.cdt.core.model.IFunctionDeclaration { +public class FunctionDeclarationHandle extends CElementHandle implements IFunctionDeclaration { private String[] fParameterTypes; + private String fReturnType; private boolean fIsStatic; public FunctionDeclarationHandle(ICElement parent, IFunction func) throws DOMException { @@ -30,6 +32,7 @@ public class FunctionDeclarationHandle extends CElementHandle implements org.ecl protected FunctionDeclarationHandle(ICElement parent, int type, IFunction func) throws DOMException { super(parent, type, func.getName()); fParameterTypes= extractParameterTypes(func); + fReturnType= ASTTypeUtil.getType(func.getType().getReturnType(), false); fIsStatic= func.isStatic(); } @@ -49,6 +52,10 @@ public class FunctionDeclarationHandle extends CElementHandle implements org.ecl return fParameterTypes; } + public String getReturnType() { + return fReturnType; + } + public String getSignature() throws CModelException { return FunctionDeclaration.getSignature(this); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ext/MethodDeclarationHandle.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ext/MethodDeclarationHandle.java index aade00913da..3ebad84b37c 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ext/MethodDeclarationHandle.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ext/MethodDeclarationHandle.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.model.ext; +import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; @@ -22,6 +23,7 @@ import org.eclipse.cdt.internal.core.model.MethodDeclaration; public class MethodDeclarationHandle extends CElementHandle implements IMethodDeclaration { private String[] fParameterTypes; + private String fReturnType; private ASTAccessVisibility fVisibility; private boolean fIsStatic; private boolean fIsConstructor; @@ -34,6 +36,7 @@ public class MethodDeclarationHandle extends CElementHandle implements IMethodDe protected MethodDeclarationHandle(ICElement parent, int type, ICPPMethod method) throws DOMException { super(parent, type, method.getName()); fParameterTypes= extractParameterTypes(method); + fReturnType= ASTTypeUtil.getType(method.getType().getReturnType(), false); fVisibility= getVisibility(method); fIsStatic= method.isStatic(); fIsConstructor= method instanceof ICPPConstructor; @@ -58,6 +61,10 @@ public class MethodDeclarationHandle extends CElementHandle implements IMethodDe return fParameterTypes; } + public String getReturnType() { + return fReturnType; + } + public String getSignature() throws CModelException { return FunctionDeclaration.getSignature(this); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ext/VariableHandle.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ext/VariableHandle.java index e243ad600d8..d254669e59f 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ext/VariableHandle.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ext/VariableHandle.java @@ -10,18 +10,33 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.model.ext; +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IVariable; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ICElement; public class VariableHandle extends CElementHandle implements org.eclipse.cdt.core.model.IVariable { + private String fTypeName; private boolean fIsStatic; public VariableHandle(ICElement parent, IVariable var) { super(parent, ICElement.C_VARIABLE, var.getName()); + try { + fTypeName= ASTTypeUtil.getType(var.getType(), false); + } catch (DOMException e) { + CCorePlugin.log(e); + fTypeName= ""; //$NON-NLS-1$ + } fIsStatic= var.isStatic(); } + @Override + public String getTypeName() { + return fTypeName; + } + public boolean isStatic() throws CModelException { return fIsStatic; }