From b88109c7f4181a9eb18f942f90eb591d3488a628 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Wed, 7 May 2014 18:28:05 -0700 Subject: [PATCH] Cosmetics. --- ...processorFunctionStyleMacroDefinition.java | 19 +++++----- ...reprocessorObjectStyleMacroDefinition.java | 12 +++--- .../parser/scanner/ASTPreprocessorNode.java | 23 ++---------- .../ui/refactoring/rename/ASTNameVisitor.java | 37 +++++++++---------- .../rename/ASTSpecificNameVisitor.java | 7 ++-- 5 files changed, 40 insertions(+), 58 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTPreprocessorFunctionStyleMacroDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTPreprocessorFunctionStyleMacroDefinition.java index 3f8c9bcb5b8..4c0c83b44a6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTPreprocessorFunctionStyleMacroDefinition.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTPreprocessorFunctionStyleMacroDefinition.java @@ -6,22 +6,23 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * John Camelon (IBM) - Initial API and implementation + * John Camelon (IBM) - Initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.dom.ast; /** * This interface represent a preprocessor function-style macro definition. e.g. - * #define ABC( def ) GHI - * - * Note: macros that are expanded as parameters to function style macros are not captured in this abstraction. + *
+ * #define ABC(def) GHI
+ * 
+ * Note: macros that are expanded as parameters to function style macros are not captured in this + * abstraction. * * @noextend This interface is not intended to be extended by clients. * @noimplement This interface is not intended to be implemented by clients. */ public interface IASTPreprocessorFunctionStyleMacroDefinition extends IASTPreprocessorMacroDefinition { - /** * This property represents the relationship between a function style macro * definition and one of its parameters. @@ -30,18 +31,16 @@ public interface IASTPreprocessorFunctionStyleMacroDefinition extends "IASTPreprocessorFunctionStyleMacroDefinition.PARAMETER - Function Macro Parameter"); //$NON-NLS-1$ /** - * Get the macro parameters. + * Returns the macro parameters. * * @return IASTFunctionStyleMacroParameter[] parameters */ public IASTFunctionStyleMacroParameter[] getParameters(); /** - * Add a function-style macro parameter. + * Adds a function-style macro parameter. * - * @param parm - * IASTFunctionStyleMacroParameter + * @param parm the parameter to add */ public void addParameter(IASTFunctionStyleMacroParameter parm); - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTPreprocessorObjectStyleMacroDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTPreprocessorObjectStyleMacroDefinition.java index e66597e4c6e..d4828d0a18d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTPreprocessorObjectStyleMacroDefinition.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTPreprocessorObjectStyleMacroDefinition.java @@ -6,18 +6,18 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * John Camelon (IBM) - Initial API and implementation + * John Camelon (IBM) - Initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.dom.ast; /** - * This interface represents an object-style macro definition. e.g. #define - * ONE_TWO_THREE 123 + * This interface represents an object-style macro definition. e.g. + *
+ * #define ONE_TWO_THREE 123
+ * 
* * @noextend This interface is not intended to be extended by clients. * @noimplement This interface is not intended to be implemented by clients. */ -public interface IASTPreprocessorObjectStyleMacroDefinition extends - IASTPreprocessorMacroDefinition { - +public interface IASTPreprocessorObjectStyleMacroDefinition extends IASTPreprocessorMacroDefinition { } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ASTPreprocessorNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ASTPreprocessorNode.java index 869f18c9774..0c173dee241 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ASTPreprocessorNode.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ASTPreprocessorNode.java @@ -125,7 +125,7 @@ class ASTComment extends ASTPreprocessorNode implements IASTComment { @Override public int getOffset() { if (fFilePath != null) { - // Perform lazy conversion to sequence number + // Perform lazy conversion to sequence number. ILocationResolver lr= (ILocationResolver) getTranslationUnit().getAdapter(ILocationResolver.class); if (lr != null) { setOffset(lr.getSequenceNumberForFileOffset(fFilePath, super.getOffset())); @@ -192,6 +192,7 @@ class ASTElse extends ASTPreprocessorNode implements IASTPreprocessorElseStateme super(parent, IASTTranslationUnit.PREPROCESSOR_STATEMENT, startNumber, endNumber); fTaken= taken; } + @Override public boolean taken() { return fTaken; @@ -207,9 +208,7 @@ class ASTIfndef extends ASTDirectiveWithCondition implements IASTPreprocessorIfn fMacroRef= new ASTMacroReferenceName(this, IASTPreprocessorStatement.MACRO_NAME, condNumber, condEndNumber, macro, null); } } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IASTPreprocessorIfdefStatement#getMacroReference() - */ + @Override public ASTPreprocessorName getMacroReference() { return fMacroRef; @@ -224,9 +223,7 @@ class ASTIfdef extends ASTDirectiveWithCondition implements IASTPreprocessorIfde fMacroRef= new ASTMacroReferenceName(this, IASTPreprocessorStatement.MACRO_NAME, condNumber, condEndNumber, macro, null); } } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IASTPreprocessorIfdefStatement#getMacroReference() - */ + @Override public ASTPreprocessorName getMacroReference() { return fMacroRef; @@ -816,25 +813,16 @@ class ASTMacroExpansion extends ASTPreprocessorNode implements IASTPreprocessorM fContext= expansionCtx; } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroExpansion#getName() - */ @Override public ASTMacroReferenceName getMacroReference() { return fContext.getMacroReference(); } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroExpansion#getMacroDefinition() - */ @Override public IASTPreprocessorMacroDefinition getMacroDefinition() { return fContext.getMacroDefinition(); } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroExpansion#getNestedExpansions() - */ @Override public ASTPreprocessorName[] getNestedMacroReferences() { return fContext.getNestedMacroReferences(); @@ -857,9 +845,6 @@ class ASTMacroExpansionLocation implements IASTMacroExpansionLocation, org.eclip fLength= length; } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IASTMacroExpansionLocation#getExpansion() - */ @Override public IASTPreprocessorMacroExpansion getExpansion() { return fContext.getExpansion(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/ASTNameVisitor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/ASTNameVisitor.java index 1685568bd5f..49a739a0d19 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/ASTNameVisitor.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/ASTNameVisitor.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation ******************************************************************************/ package org.eclipse.cdt.internal.ui.refactoring.rename; @@ -22,9 +22,9 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; * Visitor to prefer simple ASTNames over the qualified ones. This is different * to the strategy used within the dom-package. */ -abstract public class ASTNameVisitor extends ASTVisitor { - private int fOffset= -1; - private String fFileName; +public abstract class ASTNameVisitor extends ASTVisitor { + private final int fOffset; + private final String fFileName; public ASTNameVisitor(String fileName) { this(fileName, -1); @@ -33,20 +33,21 @@ abstract public class ASTNameVisitor extends ASTVisitor { public ASTNameVisitor(String fileName, int offset) { fFileName= fileName; fOffset= offset; - shouldVisitNames=true; + shouldVisitNames = true; } abstract protected int visitName(IASTName name); @Override - final public int visit(IASTName name) { + public final int visit(IASTName name) { if (name instanceof ICPPASTQualifiedName) { ICPPASTQualifiedName qn= (ICPPASTQualifiedName) name; - ICPPASTNameSpecifier[] segments= qn.getAllSegments(); + ICPPASTNameSpecifier[] segments= qn.getQualifier(); boolean visited= false; - for (int i = 0; i < segments.length; i++) { - if (segments[i] instanceof IASTName && checkLocation(segments[i])) { - if (visitName((IASTName) segments[i]) == PROCESS_ABORT) { + for (int i = 0; i <= segments.length; i++) { + IASTNode segment = i < segments.length ? segments[i] : qn.getLastName(); + if (segment instanceof IASTName && checkLocation(segment)) { + if (visitName((IASTName) segment) == PROCESS_ABORT) { return PROCESS_ABORT; } visited= true; @@ -57,15 +58,14 @@ abstract public class ASTNameVisitor extends ASTVisitor { return visitName(name.getLastName()); } } - } - else if (checkLocation(name)) { + } else if (checkLocation(name)) { return visitName(name); } return PROCESS_CONTINUE; } private boolean checkLocation(IASTNode node) { - if (fFileName==null) { + if (fFileName == null) { return true; } if (!fFileName.equals(node.getContainingFilename())) { @@ -74,23 +74,22 @@ abstract public class ASTNameVisitor extends ASTVisitor { IASTFileLocation loc= null; if (node instanceof IASTName) { loc= ASTManager.getImageFileLocation((IASTName) node); - } - else { + } else { IASTNodeLocation[] locs= node.getNodeLocations(); - if (locs!=null && locs.length==1) { + if (locs != null && locs.length == 1) { if (locs[0] instanceof IASTFileLocation) { loc= (IASTFileLocation) locs[0]; } } } - if (loc==null) { + if (loc == null) { return false; } - if (fOffset==-1) { + if (fOffset == -1) { return true; } int off= loc.getNodeOffset(); int len = loc.getNodeLength(); - return off <= fOffset && fOffset < off+len; + return off <= fOffset && fOffset < off + len; } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/ASTSpecificNameVisitor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/ASTSpecificNameVisitor.java index 19bc167c2c2..9123d0a0546 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/ASTSpecificNameVisitor.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/ASTSpecificNameVisitor.java @@ -6,9 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation ******************************************************************************/ - package org.eclipse.cdt.internal.ui.refactoring.rename; import org.eclipse.cdt.core.dom.ast.ASTVisitor; @@ -17,7 +16,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId; public abstract class ASTSpecificNameVisitor extends ASTNameVisitor { - private String fSearchForName; + private final String fSearchForName; public ASTSpecificNameVisitor(String name) { super(null); @@ -25,7 +24,7 @@ public abstract class ASTSpecificNameVisitor extends ASTNameVisitor { } @Override - final public int visitName(IASTName name) { + public final int visitName(IASTName name) { if (name instanceof ICPPASTTemplateId || name instanceof ICPPASTQualifiedName) return PROCESS_CONTINUE;