From 4c8a4d2d744194193b9c9aaa5c5980964ec29e6a Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Wed, 16 Jun 2010 12:27:16 +0000 Subject: [PATCH] Bug 162806: Deprecate IASTTranslationUnit.getParserLanguage(). --- .../org.eclipse.cdt.core/META-INF/MANIFEST.MF | 2 +- .../org/eclipse/cdt/core/dom/ILinkage.java | 4 +- .../cdt/core/dom/ast/IASTTranslationUnit.java | 8 ++- .../dom/parser/c/CASTTranslationUnit.java | 1 + .../dom/parser/cpp/CPPASTTranslationUnit.java | 3 +- .../ui/refactoring/NodeContainer.java | 65 +++++++------------ .../ExtractConstantRefactoring.java | 9 +-- .../ExtractFunctionRefactoring.java | 12 ++-- .../ExtractedFunctionConstructionHelper.java | 29 ++++----- 9 files changed, 62 insertions(+), 71 deletions(-) diff --git a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF index 93d2674b716..a1478ba6bac 100644 --- a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF +++ b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.cdt.core; singleton:=true -Bundle-Version: 5.2.0.qualifier +Bundle-Version: 5.2.100.qualifier Bundle-Activator: org.eclipse.cdt.core.CCorePlugin Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ILinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ILinkage.java index 91ef4bdeb73..05737e8fc7e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ILinkage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ILinkage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2009 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2010 Wind River Systems, Inc. and others. * 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 @@ -12,7 +12,7 @@ package org.eclipse.cdt.core.dom; /** - * Represents a linkage in the AST or the index. + * Represents a linkage under which bindings are stored in the index. * @since 4.0 * * @noextend This interface is not intended to be extended by clients. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTranslationUnit.java index 4baefecf25d..7bde01482cf 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTranslationUnit.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTranslationUnit.java @@ -230,8 +230,12 @@ public interface IASTTranslationUnit extends IASTDeclarationListOwner, IAdaptabl * @param offset */ public String getContainingFilename(int offset); - - public ParserLanguage getParserLanguage(); + + /** + * @deprecated don't use it. + */ + @Deprecated + public ParserLanguage getParserLanguage(); /** * Returns the Index associated with this translation unit. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java index 2c8ddd9cddb..022bb811452 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java @@ -87,6 +87,7 @@ public class CASTTranslationUnit extends ASTTranslationUnit implements IASTAmbig return CVisitor.getReferences(this, binding); } + @Deprecated public ParserLanguage getParserLanguage() { return ParserLanguage.C; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java index cdc0acc573d..94ee1d1f2b0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java @@ -14,11 +14,11 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IBasicType; +import org.eclipse.cdt.core.dom.ast.IBasicType.Kind; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IMacroBinding; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; -import org.eclipse.cdt.core.dom.ast.IBasicType.Kind; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType; @@ -131,6 +131,7 @@ public class CPPASTTranslationUnit extends ASTTranslationUnit implements ICPPAST return fBinding; } + @Deprecated public ParserLanguage getParserLanguage() { return ParserLanguage.CPP; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/NodeContainer.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/NodeContainer.java index 01aa60e9d99..5d60c082c4e 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/NodeContainer.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/NodeContainer.java @@ -33,22 +33,17 @@ import org.eclipse.cdt.core.dom.ast.IASTPointerOperator; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.INodeFactory; import org.eclipse.cdt.core.dom.ast.IVariable; import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTReferenceOperator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPNodeFactory; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter; -import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.ui.CUIPlugin; -import org.eclipse.cdt.internal.core.dom.parser.c.CASTPointer; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTArrayDeclarator; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTParameterDeclaration; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTReferenceOperator; import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ASTWriter; public class NodeContainer { @@ -130,58 +125,48 @@ public class NodeContainer { return getReferencesAfterSelection().size() > 0; } - public ICPPASTParameterDeclaration getICPPASTParameterDeclaration( - boolean isReference, ParserLanguage lang) { - ICPPASTParameterDeclaration para = new CPPASTParameterDeclaration(); - IASTDeclarator sourceDeclarator = (IASTDeclarator) getDeclaration() - .getParent(); + public IASTParameterDeclaration getParameterDeclaration(boolean isReference, + INodeFactory nodeFactory) { + IASTDeclarator sourceDeclarator = (IASTDeclarator) getDeclaration().getParent(); + IASTDeclSpecifier declSpec= null; + IASTDeclarator declarator= null; + if (sourceDeclarator.getParent() instanceof IASTSimpleDeclaration) { - IASTSimpleDeclaration decl = (IASTSimpleDeclaration) sourceDeclarator - .getParent(); - para.setDeclSpecifier(decl.getDeclSpecifier().copy()); + IASTSimpleDeclaration decl = (IASTSimpleDeclaration) sourceDeclarator.getParent(); + declSpec= decl.getDeclSpecifier().copy(); } else if (sourceDeclarator.getParent() instanceof IASTParameterDeclaration) { - IASTParameterDeclaration decl = (IASTParameterDeclaration) sourceDeclarator - .getParent(); - para.setDeclSpecifier(decl.getDeclSpecifier().copy()); + IASTParameterDeclaration decl = (IASTParameterDeclaration) sourceDeclarator.getParent(); + declSpec= decl.getDeclSpecifier().copy(); } - IASTDeclarator declarator; + IASTName name= nodeFactory.newName(getDeclaration().toCharArray()); if (sourceDeclarator instanceof IASTArrayDeclarator) { IASTArrayDeclarator arrDeclarator = (IASTArrayDeclarator) sourceDeclarator; - declarator = new CPPASTArrayDeclarator(); - IASTArrayModifier[] arrayModifiers = arrDeclarator - .getArrayModifiers(); + IASTArrayDeclarator arrayDtor = nodeFactory.newArrayDeclarator(name); + IASTArrayModifier[] arrayModifiers = arrDeclarator.getArrayModifiers(); for (IASTArrayModifier arrayModifier : arrayModifiers) { - ((IASTArrayDeclarator) declarator) - .addArrayModifier(arrayModifier.copy()); + arrayDtor.addArrayModifier(arrayModifier.copy()); } - + declarator= arrayDtor; } else { - declarator = new CPPASTDeclarator(); + declarator = nodeFactory.newDeclarator(name); } - declarator.setName(new CPPASTName(getDeclaration().toCharArray())); - for (IASTPointerOperator pointerOp : sourceDeclarator - .getPointerOperators()) { + for (IASTPointerOperator pointerOp : sourceDeclarator.getPointerOperators()) { declarator.addPointerOperator(pointerOp.copy()); } if (isReference && !hasReferenceOperartor(declarator)) { - switch (lang) { - case C: - declarator.addPointerOperator(new CASTPointer()); - break; - case CPP: - declarator.addPointerOperator(new CPPASTReferenceOperator(false)); - break; + if (nodeFactory instanceof ICPPNodeFactory) { + declarator.addPointerOperator(((ICPPNodeFactory) nodeFactory).newReferenceOperator(false)); + } else { + declarator.addPointerOperator(nodeFactory.newPointer()); } } - declarator.setNestedDeclarator(sourceDeclarator - .getNestedDeclarator()); - para.setDeclarator(declarator); + declarator.setNestedDeclarator(sourceDeclarator.getNestedDeclarator()); - return para; + return nodeFactory.newParameterDeclaration(declSpec, declarator); } public boolean hasReferenceOperartor(IASTDeclarator declarator) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/ExtractConstantRefactoring.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/ExtractConstantRefactoring.java index 41ee41e4d7a..8f8ddf15c58 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/ExtractConstantRefactoring.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/ExtractConstantRefactoring.java @@ -44,10 +44,12 @@ import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.INodeFactory; import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPNodeFactory; import org.eclipse.cdt.core.dom.rewrite.ASTRewrite; import org.eclipse.cdt.core.model.ICProject; @@ -56,7 +58,6 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTEqualsInitializer; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNamespaceDefinition; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclSpecifier; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclaration; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPMethod; @@ -407,9 +408,9 @@ public class ExtractConstantRefactoring extends CRefactoring { private IASTDeclaration getConstNodesGlobal(String newName){ IASTSimpleDeclaration simple = getConstNodes(newName); - if(unit.getParserLanguage().isCPP()){ - ICPPASTNamespaceDefinition namespace = new CPPASTNamespaceDefinition(); - namespace.setName(new CPPASTName()); + INodeFactory factory= unit.getASTNodeFactory(); + if (factory instanceof ICPPNodeFactory) { + ICPPASTNamespaceDefinition namespace = ((ICPPNodeFactory) factory).newNamespaceDefinition(new CPPASTName()); namespace.addDeclaration(simple); return namespace; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java index 364264b9c92..cb5b444f06e 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java @@ -16,8 +16,8 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.Vector; import java.util.Map.Entry; +import java.util.Vector; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.ResourcesPlugin; @@ -104,9 +104,9 @@ import org.eclipse.cdt.internal.ui.refactoring.CRefactoring; import org.eclipse.cdt.internal.ui.refactoring.CRefactoringDescription; import org.eclipse.cdt.internal.ui.refactoring.Container; import org.eclipse.cdt.internal.ui.refactoring.MethodContext; +import org.eclipse.cdt.internal.ui.refactoring.MethodContext.ContextType; import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector; import org.eclipse.cdt.internal.ui.refactoring.NodeContainer; -import org.eclipse.cdt.internal.ui.refactoring.MethodContext.ContextType; import org.eclipse.cdt.internal.ui.refactoring.NodeContainer.NameInformation; import org.eclipse.cdt.internal.ui.refactoring.utils.ASTHelper; import org.eclipse.cdt.internal.ui.refactoring.utils.CPPASTAllVisitor; @@ -660,7 +660,7 @@ public class ExtractFunctionRefactoring extends CRefactoring { IASTStandardFunctionDeclarator createdFunctionDeclarator = extractedFunctionConstructionHelper .createFunctionDeclarator(qname, info.getDeclarator(), info .getReturnVariable(), container.getNodesToWrite(), info - .getAllUsedNames(), unit.getParserLanguage()); + .getAllUsedNames(), unit.getASTNodeFactory()); func.setDeclarator(createdFunctionDeclarator); IASTCompoundStatement compound = new CPPASTCompoundStatement(); @@ -863,7 +863,7 @@ public class ExtractFunctionRefactoring extends CRefactoring { IASTStandardFunctionDeclarator declarator = extractedFunctionConstructionHelper .createFunctionDeclarator(name, info.getDeclarator(), info .getReturnVariable(), container.getNodesToWrite(), info - .getAllUsedNames(), unit.getParserLanguage()); + .getAllUsedNames(), unit.getASTNodeFactory()); simpleDecl.addDeclarator(declarator); return simpleDecl; } @@ -875,10 +875,10 @@ public class ExtractFunctionRefactoring extends CRefactoring { ((ICPPASTDeclSpecifier)declSpec).setVirtual(true); } simpleDecl.setParent(unit); - ICPPASTFunctionDeclarator declarator = extractedFunctionConstructionHelper + IASTStandardFunctionDeclarator declarator = extractedFunctionConstructionHelper .createFunctionDeclarator(name, info.getDeclarator(), info .getReturnVariable(), container.getNodesToWrite(), info - .getAllUsedNames(), unit.getParserLanguage()); + .getAllUsedNames(), unit.getASTNodeFactory()); simpleDecl.addDeclarator(declarator); return simpleDecl; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractedFunctionConstructionHelper.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractedFunctionConstructionHelper.java index 7e4d41b90bb..2da413aa814 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractedFunctionConstructionHelper.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractedFunctionConstructionHelper.java @@ -24,14 +24,12 @@ import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; import org.eclipse.cdt.core.dom.ast.IASTPointerOperator; +import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator; +import org.eclipse.cdt.core.dom.ast.INodeFactory; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration; import org.eclipse.cdt.core.dom.rewrite.ASTRewrite; -import org.eclipse.cdt.core.parser.ParserLanguage; - -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTPointer; import org.eclipse.cdt.internal.ui.refactoring.NodeContainer.NameInformation; @@ -59,12 +57,13 @@ public abstract class ExtractedFunctionConstructionHelper { return false; } - ICPPASTFunctionDeclarator createFunctionDeclarator(IASTName name, ICPPASTFunctionDeclarator functionDeclarator, NameInformation returnVariable, List nodesToWrite, Collection allUsedNames, ParserLanguage lang) { - ICPPASTFunctionDeclarator declarator = new CPPASTFunctionDeclarator(); - declarator.setName(name); + IASTStandardFunctionDeclarator createFunctionDeclarator(IASTName name, IASTStandardFunctionDeclarator functionDeclarator, NameInformation returnVariable, List nodesToWrite, Collection allUsedNames, INodeFactory nodeFactory) { + IASTStandardFunctionDeclarator declarator = nodeFactory.newFunctionDeclarator(name); - if(functionDeclarator != null && functionDeclarator.isConst()) { - declarator.setConst(true); + if (functionDeclarator instanceof ICPPASTFunctionDeclarator && declarator instanceof ICPPASTFunctionDeclarator) { + if (((ICPPASTFunctionDeclarator) functionDeclarator).isConst()) { + ((ICPPASTFunctionDeclarator) declarator).setConst(true); + } } if(returnVariable != null) { @@ -75,22 +74,22 @@ public abstract class ExtractedFunctionConstructionHelper { } } - for (ICPPASTParameterDeclaration param : getParameterDeclarations(allUsedNames, lang)) { + for (IASTParameterDeclaration param : getParameterDeclarations(allUsedNames, nodeFactory)) { declarator.addParameterDeclaration(param); } if(isReturnTypeAPointer(nodesToWrite.get(0))) { - declarator.addPointerOperator(new CPPASTPointer()); + declarator.addPointerOperator(nodeFactory.newPointer()); } return declarator; } - public Collection getParameterDeclarations(Collection allUsedNames, ParserLanguage lang) { - Collection result = new ArrayList(); + public Collection getParameterDeclarations(Collection allUsedNames, INodeFactory nodeFactory) { + Collection result = new ArrayList(); for (NameInformation name : allUsedNames) { if(!name.isDeclarationInScope()){ - result.add(name.getICPPASTParameterDeclaration(name.isUserSetIsReference(), lang)); + result.add(name.getParameterDeclaration(name.isUserSetIsReference(), nodeFactory)); } } return result;