From cfb67719299c596a8044688658e2c182cca7de5e Mon Sep 17 00:00:00 2001 From: Alain Magloire Date: Fri, 30 Jul 2004 19:10:49 +0000 Subject: [PATCH] 2004-07-30 Alain Magloire Add the Using-{directive,declaration} part of the Core Model. * model/org/eclipse/cdt/core/model/IUsing.java * model/org/eclipse/cdt/internal/core/model/CElement.java * model/org/eclipse/cdt/internal/core/model/CModelBuilder.java * model/org/eclipse/cdt/internal/core/model/Using.java --- core/org.eclipse.cdt.core/ChangeLog | 9 ++++ .../org/eclipse/cdt/core/model/IUsing.java | 2 + .../cdt/internal/core/model/CElement.java | 4 ++ .../internal/core/model/CModelBuilder.java | 44 +++++++++++++++++++ .../cdt/internal/core/model/Using.java | 14 +++++- 5 files changed, 71 insertions(+), 2 deletions(-) diff --git a/core/org.eclipse.cdt.core/ChangeLog b/core/org.eclipse.cdt.core/ChangeLog index 7b26cb38913..f067b00fcd9 100644 --- a/core/org.eclipse.cdt.core/ChangeLog +++ b/core/org.eclipse.cdt.core/ChangeLog @@ -1,3 +1,12 @@ +2004-07-30 Alain Magloire + + Add the Using-{directive,declaration} part of the Core Model. + + * model/org/eclipse/cdt/core/model/IUsing.java + * model/org/eclipse/cdt/internal/core/model/CElement.java + * model/org/eclipse/cdt/internal/core/model/CModelBuilder.java + * model/org/eclipse/cdt/internal/core/model/Using.java + 2004-07-28 Tanya Wolff Fix for PR 70161: Assembly untranslated in C++ File Types diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IUsing.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IUsing.java index 2002f55a0e0..43e04fa524a 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IUsing.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IUsing.java @@ -13,4 +13,6 @@ public interface IUsing extends ICElement, ISourceManipulation, ISourceReference * This is a handle-only method. */ String getElementName(); + + boolean isDirective(); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElement.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElement.java index a6db20a0936..318cdd8f1f2 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElement.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElement.java @@ -330,6 +330,10 @@ public abstract class CElement extends PlatformObject implements ICElement { return "C_FIELD"; //$NON-NLS-1$ case C_METHOD: return "C_METHOD"; //$NON-NLS-1$ + case C_NAMESPACE: + return "C_NAMESPACE"; //$NON-NLS-1$ + case C_USING: + return "C_USING"; //$NON-NLS-1$ default: return "UNKNOWN"; //$NON-NLS-1$ } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java index 813796c0946..92b67c6d833 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java @@ -58,6 +58,8 @@ import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration; import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier; import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifierOwner; import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; +import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration; +import org.eclipse.cdt.core.parser.ast.IASTUsingDirective; import org.eclipse.cdt.core.parser.ast.IASTVariable; import org.eclipse.cdt.internal.core.parser.ParserException; import org.eclipse.cdt.internal.core.parser.StructuralParseCallback; @@ -270,6 +272,14 @@ public class CModelBuilder { if(declaration instanceof IASTLinkageSpecification) { generateModelElements(parent, (IASTLinkageSpecification)declaration); } + + if (declaration instanceof IASTUsingDirective) { + createUsingDirective(parent, (IASTUsingDirective)declaration); + } + + if (declaration instanceof IASTUsingDeclaration) { + createUsingDeclaration(parent, (IASTUsingDeclaration)declaration); + } createSimpleElement(parent, declaration, false); } @@ -734,6 +744,40 @@ public class CModelBuilder { return element; } + private Using createUsingDirective(Parent parent, IASTUsingDirective usingDirDeclaration) throws CModelException{ + // create the element + String name = usingDirDeclaration.getNamespaceName(); + + Using element = new Using( parent, name, true ); + + // add to parent + parent.addChild(element); + + // set positions + //element.setIdPos(usingDirDeclaration.getNameOffset(), (usingDirective.getNameEndOffset() - usingDirDeclaration.getNameOffset())); + element.setPos(usingDirDeclaration.getStartingOffset(), usingDirDeclaration.getEndingOffset() - usingDirDeclaration.getStartingOffset()); + element.setLines(usingDirDeclaration.getStartingLine(), usingDirDeclaration.getEndingLine() ); + this.newElements.put(element, element.getElementInfo()); + return element; + } + + private Using createUsingDeclaration(Parent parent, IASTUsingDeclaration usingDeclaration) throws CModelException{ + // create the element + String name = usingDeclaration.usingTypeName(); + + Using element = new Using(parent, name, false); + + // add to parent + parent.addChild(element); + + // set positions + //element.setIdPos(usingDeclaration.getNameOffset(), (usingDeclaration.getNameEndOffset() - usingDeclaration.getNameOffset())); + element.setPos(usingDeclaration.getStartingOffset(), usingDeclaration.getEndingOffset() - usingDeclaration.getStartingOffset()); + element.setLines(usingDeclaration.getStartingLine(), usingDeclaration.getEndingLine() ); + this.newElements.put(element, element.getElementInfo()); + return element; + } + /** * @return Returns the newElements. */ diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Using.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Using.java index a7add0cad3c..01d0f9ccdd8 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Using.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Using.java @@ -14,14 +14,24 @@ package org.eclipse.cdt.internal.core.model; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.IUsing; -public class Using extends SourceManipulation implements IUsing{ +public class Using extends SourceManipulation implements IUsing { - public Using(ICElement parent, String name) { + boolean directive; + + public Using(ICElement parent, String name, boolean isDirective) { super(parent, name, CElement.C_USING); + directive = isDirective; } protected CElementInfo createElementInfo () { return new SourceManipulationInfo(this); } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.model.IUsing#isDirective() + */ + public boolean isDirective() { + return directive; + } + }