diff options
author | Sergey Prigogin | 2012-02-04 02:32:59 +0000 |
---|---|---|
committer | Sergey Prigogin | 2012-02-04 02:32:59 +0000 |
commit | fa13b42c51a646487bb29aa5b353914606223cc3 (patch) | |
tree | af687db0747ae828e42fd1a67bc705c66fcf34f2 /core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom | |
parent | 0d4d66ec6e22720d9e567944293b8f05ca008be0 (diff) | |
download | org.eclipse.cdt-fa13b42c51a646487bb29aa5b353914606223cc3.tar.gz org.eclipse.cdt-fa13b42c51a646487bb29aa5b353914606223cc3.tar.xz org.eclipse.cdt-fa13b42c51a646487bb29aa5b353914606223cc3.zip |
New UI and other improvements for Extract Function refactoring .
Diffstat (limited to 'core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom')
4 files changed, 37 insertions, 11 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java index fb6a0564da6..f6c3e0b65ec 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java @@ -13,7 +13,11 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; -import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.*; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.ALLCVQ; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.CVTYPE; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.getNestedType; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.getUltimateTypeUptoPointers; import java.util.ArrayList; import java.util.Collections; @@ -1864,6 +1868,8 @@ public class CPPVisitor extends ASTQueries { boolean isPackExpansion= false; if (parent instanceof IASTSimpleDeclaration) { declSpec = ((IASTSimpleDeclaration) parent).getDeclSpecifier(); + } else if (parent instanceof IASTParameterDeclaration) { + declSpec = ((IASTParameterDeclaration) parent).getDeclSpecifier(); } else if (parent instanceof IASTFunctionDefinition) { declSpec = ((IASTFunctionDefinition) parent).getDeclSpecifier(); } else if (parent instanceof ICPPASTTypeId) { @@ -2506,4 +2512,21 @@ public class CPPVisitor extends ASTQueries { public static ICPPASTDeclarator findInnermostDeclarator(ICPPASTDeclarator dtor) { return (ICPPASTDeclarator) ASTQueries.findInnermostDeclarator(dtor); } + + /** + * Traverses parent chain of the given node and returns the first node of the given type. + * @param node the start node + * @param type the type to look for + * @return the node itself or its closest ancestor that has the given type, or {@code null} + * if no such node is found. + */ + @SuppressWarnings("unchecked") + public static <T extends IASTNode> T findAncestorWithType(IASTNode node, Class<T> type) { + do { + if (type.isInstance(node)) { + return (T) node; + } + } while ((node = node.getParent()) != null); + return null; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/DeclarationGeneratorImpl.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/DeclarationGeneratorImpl.java index ee4c9d86257..4718e1e11ac 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/DeclarationGeneratorImpl.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/DeclarationGeneratorImpl.java @@ -105,13 +105,13 @@ public class DeclarationGeneratorImpl extends DeclarationGenerator { returnedDeclSpec = declSpec; } else if (type instanceof ICPPTemplateInstance) { returnedDeclSpec = getDeclSpecForTemplate((ICPPTemplateInstance) type); - } else if (type instanceof IBinding) { /* ITypedef, ICompositeType... */ // BTW - we need to distinguish (and fail explicitly) on literal composites like: // struct { } aSingleInstance; returnedDeclSpec = getDeclSpecForBinding((IBinding) type); } + // TODO(sprigogin): Be honest and return null instead of void. // Fallback... if (returnedDeclSpec == null) { IASTSimpleDeclSpecifier specifier = factory.newSimpleDeclSpecifier(); @@ -129,7 +129,7 @@ public class DeclarationGeneratorImpl extends DeclarationGenerator { // Addition of pointer operators has to be in reverse order, so it's deferred until the end Map<IASTDeclarator, LinkedList<IASTPointerOperator>> pointerOperatorMap = new HashMap<IASTDeclarator, LinkedList<IASTPointerOperator>>(); - IASTName newName = (name != null) ? factory.newName(name) : factory.newName(); + IASTName newName = name != null ? factory.newName(name) : factory.newName(); // If the type is an array of something, create a declaration of a pointer to something instead // (to allow assignment, etc) @@ -311,8 +311,8 @@ public class DeclarationGeneratorImpl extends DeclarationGenerator { ICPPNodeFactory cppFactory = (ICPPNodeFactory) factory; ICPPASTTemplateId tempId = cppFactory.newTemplateId(templateName.copy()); for (ICPPTemplateArgument arg : type.getTemplateArguments()) { - IASTDeclSpecifier argDeclSpec = createDeclSpecFromType(arg.isTypeValue() ? arg - .getTypeValue() : arg.getTypeOfNonTypeValue()); + IASTDeclSpecifier argDeclSpec = createDeclSpecFromType(arg.isTypeValue() ? + arg.getTypeValue() : arg.getTypeOfNonTypeValue()); IASTTypeId typeId = cppFactory.newTypeId(argDeclSpec, null); tempId.addTemplateArgument(typeId); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ASTWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ASTWriter.java index 83dd18fdf43..f9992e2c681 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ASTWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ASTWriter.java @@ -39,7 +39,7 @@ import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap; * @author Emanuel Graf */ public class ASTWriter { - private ASTModificationStore modificationStore = new ASTModificationStore(); + private final ASTModificationStore modificationStore = new ASTModificationStore(); /** * Creates a <code>ASTWriter</code>. @@ -63,7 +63,7 @@ public class ASTWriter { * Generates the source code representing this node including comments. * * @param rootNode Node to write. - * @param commentMap Node Comment Map <code>ASTCommenter</code> + * @param commentMap comments for the translation unit * @return A <code>String</code> representing the source code for the node. * @throws ProblemRuntimeException if the node or one of it's children is * an <code>IASTProblemNode</code>. @@ -79,10 +79,6 @@ public class ASTWriter { return writer.toString(); } - public void setModificationStore(ASTModificationStore modificationStore) { - this.modificationStore = modificationStore; - } - /** * Returns <code>true</code> if the node should be separated by a blank line from the node * before it. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ASTWriterVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ASTWriterVisitor.java index cd1e5c363d9..ef08a0ba868 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ASTWriterVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ASTWriterVisitor.java @@ -80,6 +80,13 @@ public class ASTWriterVisitor extends ASTVisitor { shouldVisitTypeIds = true; } + /** + * Creates a writer with an empty comment map. + */ + public ASTWriterVisitor() { + this(new NodeCommentMap()); + } + public ASTWriterVisitor(NodeCommentMap commentMap) { super(); init(commentMap); |