From 30081f07d5dfb50767abb7d1618b8183268a52ac Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Tue, 2 Apr 2013 20:10:22 -0700 Subject: [PATCH] Cosmetics. --- .../cdt/core/dom/ast/IASTImplicitName.java | 3 +- .../core/dom/parser/ASTNodeSelector.java | 35 +++++++++++-------- .../core/dom/parser/ASTNodeSpecification.java | 31 ++++++++-------- 3 files changed, 38 insertions(+), 31 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTImplicitName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTImplicitName.java index 1f22ba47f6a..d239176555b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTImplicitName.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTImplicitName.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Mike Kucera (IBM) - Initial API and implementation + * Mike Kucera (IBM) - Initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.dom.ast; @@ -21,7 +21,6 @@ package org.eclipse.cdt.core.dom.ast; * @noimplement This interface is not intended to be implemented by clients. */ public interface IASTImplicitName extends IASTName { - public static final IASTImplicitName[] EMPTY_NAME_ARRAY = {}; /** diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNodeSelector.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNodeSelector.java index b8e028975df..e6f54c59ed6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNodeSelector.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNodeSelector.java @@ -7,7 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation - *******************************************************************************/ + *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser; import org.eclipse.cdt.core.dom.ast.IASTFileLocation; @@ -24,8 +24,8 @@ import org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver; * @since 5.0 */ public class ASTNodeSelector implements IASTNodeSelector { - private ASTTranslationUnit fTu; - private ILocationResolver fLocationResolver; + private final ASTTranslationUnit fTu; + private final ILocationResolver fLocationResolver; private String fFilePath; private final boolean fIsValid; @@ -46,14 +46,15 @@ public class ASTNodeSelector implements IASTNodeSelector { return false; } - private T findNode(int offsetInFile, int lengthInFile, Relation relation, Class requiredClass) { + private T findNode(int offsetInFile, int lengthInFile, Relation relation, + Class requiredClass) { return findNode(offsetInFile, lengthInFile, relation, requiredClass, false); } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IASTNodeSelector#getNode(int, int) */ - private T findNode(int offsetInFile, int lengthInFile, Relation relation, + private T findNode(int offsetInFile, int lengthInFile, Relation relation, Class requiredClass, boolean searchInExpansion) { if (!fIsValid) { return null; @@ -68,11 +69,12 @@ public class ASTNodeSelector implements IASTNodeSelector { return null; } if (lengthInFile > 0) { - sequenceLength= fLocationResolver.getSequenceNumberForFileOffset(fFilePath, offsetInFile+lengthInFile-1) + 1 - sequenceNumber; + sequenceLength= fLocationResolver.getSequenceNumberForFileOffset(fFilePath, + offsetInFile + lengthInFile - 1) + 1 - sequenceNumber; } else { sequenceLength= 0; if (offsetInFile > 0) { - altSequenceNumber= fLocationResolver.getSequenceNumberForFileOffset(fFilePath, offsetInFile-1); + altSequenceNumber= fLocationResolver.getSequenceNumberForFileOffset(fFilePath, offsetInFile - 1); if (altSequenceNumber + 1 == sequenceNumber) { altSequenceNumber= -1; } else { @@ -82,7 +84,8 @@ public class ASTNodeSelector implements IASTNodeSelector { } } } - final ASTNodeSpecification nodeSpec= new ASTNodeSpecification(relation, requiredClass, offsetInFile, lengthInFile); + final ASTNodeSpecification nodeSpec= + new ASTNodeSpecification(relation, requiredClass, offsetInFile, lengthInFile); nodeSpec.setRangeInSequence(sequenceNumber, sequenceLength, false); nodeSpec.setSearchInExpansion(searchInExpansion); getNode(nodeSpec); @@ -102,15 +105,17 @@ public class ASTNodeSelector implements IASTNodeSelector { IASTPreprocessorMacroExpansion expansion= nodeSpec.findLeadingMacroExpansion(this); if (expansion != null) { IASTFileLocation floc= expansion.getFileLocation(); - seqbegin= fLocationResolver.getSequenceNumberForFileOffset(fFilePath, floc.getNodeOffset() + floc.getNodeLength()-1)+1; + seqbegin= fLocationResolver.getSequenceNumberForFileOffset(fFilePath, + floc.getNodeOffset() + floc.getNodeLength() - 1) + 1; } expansion= nodeSpec.findTrailingMacroExpansion(this); if (expansion != null) { IASTFileLocation floc= expansion.getFileLocation(); - seqend= fLocationResolver.getSequenceNumberForFileOffset(fFilePath, floc.getNodeOffset() + floc.getNodeLength()); + seqend= fLocationResolver.getSequenceNumberForFileOffset(fFilePath, + floc.getNodeOffset() + floc.getNodeLength()); } - nodeSpec.setRangeInSequence(seqbegin, seqend-seqbegin); - + nodeSpec.setRangeInSequence(seqbegin, seqend - seqbegin); + FindNodeForOffsetAction nodeFinder= new FindNodeForOffsetAction(nodeSpec); fTu.accept(nodeFinder); } @@ -131,7 +136,7 @@ public class ASTNodeSelector implements IASTNodeSelector { public IASTNode findEnclosingNode(int offset, int length) { return findNode(offset, length, Relation.ENCLOSING, IASTNode.class); } - + @Override public IASTNode findStrictlyEnclosingNode(int offset, int length) { return findNode(offset, length, Relation.STRICTLY_ENCLOSING, IASTNode.class); @@ -171,12 +176,12 @@ public class ASTNodeSelector implements IASTNodeSelector { public IASTImplicitName findImplicitName(int offset, int length) { return findNode(offset, length, Relation.EXACT_MATCH, IASTImplicitName.class); } - + @Override public IASTImplicitName findEnclosingImplicitName(int offset, int length) { return findNode(offset, length, Relation.ENCLOSING, IASTImplicitName.class); } - + @Override public IASTPreprocessorMacroExpansion findEnclosingMacroExpansion(int offset, int length) { return findNode(offset, length, Relation.ENCLOSING, IASTPreprocessorMacroExpansion.class); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNodeSpecification.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNodeSpecification.java index e36614cb2a6..50e9d498f83 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNodeSpecification.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNodeSpecification.java @@ -17,8 +17,8 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroExpansion; /** - * For searching ast-nodes by offset and length, instances of this class can be used to - * determine whether a node matches or not. + * For searching ast-nodes by offset and length, instances of this class can be used to determine + * whether a node matches or not. * * @since 5.0 */ @@ -35,7 +35,7 @@ public class ASTNodeSpecification { private int fBestEndOffset; private T fBestNode; private boolean fSearchInExpansion; - private boolean fZeroToLeft= false; + private boolean fZeroToLeft; public ASTNodeSpecification(Relation relation, Class clazz, int fileOffset, int fileLength) { fRelation= relation; @@ -80,7 +80,8 @@ public class ASTNodeSpecification { @SuppressWarnings("unchecked") public void visit(ASTNode astNode) { - if (isAcceptableNode(astNode) && isMatchingRange(astNode.getOffset(), astNode.getLength(), fSeqNumber, fSeqEndNumber)) { + if (isAcceptableNode(astNode) && + isMatchingRange(astNode.getOffset(), astNode.getLength(), fSeqNumber, fSeqEndNumber)) { IASTFileLocation loc= astNode.getFileLocation(); if (loc != null) { storeIfBest(loc, (T) astNode); @@ -98,8 +99,8 @@ public class ASTNodeSpecification { } private boolean isMatchingRange(int offset, int length, int selOffset, int selEndOffset) { - final int endOffset= offset+length; - switch(fRelation) { + final int endOffset= offset + length; + switch (fRelation) { case EXACT_MATCH: return selOffset == offset && selEndOffset == endOffset; case FIRST_CONTAINED: @@ -134,8 +135,8 @@ public class ASTNodeSpecification { */ public boolean canContainMatches(ASTNode node) { final int offset= node.getOffset(); - final int endOffset= offset+node.getLength(); - switch(fRelation) { + final int endOffset= offset + node.getLength(); + switch (fRelation) { case EXACT_MATCH: case ENCLOSING: return offset <= fSeqNumber && fSeqEndNumber <= endOffset; @@ -158,7 +159,7 @@ public class ASTNodeSpecification { if (isBetterMatch(offset, length, astNode)) { fBestNode= astNode; fBestOffset= offset; - fBestEndOffset= offset+length; + fBestEndOffset= offset + length; } } } @@ -172,7 +173,7 @@ public class ASTNodeSpecification { return true; } - final int endOffset= offset+length; + final int endOffset= offset + length; switch(fRelation) { case EXACT_MATCH: return isParent(fBestNode, cand); @@ -211,7 +212,8 @@ public class ASTNodeSpecification { } public IASTPreprocessorMacroExpansion findLeadingMacroExpansion(ASTNodeSelector nodeSelector) { - IASTPreprocessorMacroExpansion exp= nodeSelector.findEnclosingMacroExpansion(fZeroToLeft ? fFileOffset-1 : fFileOffset, 1); + IASTPreprocessorMacroExpansion exp= + nodeSelector.findEnclosingMacroExpansion(fZeroToLeft ? fFileOffset - 1 : fFileOffset, 1); if (fRelation == Relation.ENCLOSING || fRelation == Relation.STRICTLY_ENCLOSING) return exp; @@ -219,7 +221,7 @@ public class ASTNodeSpecification { IASTFileLocation loc= exp.getFileLocation(); if (loc != null) { final int offset= loc.getNodeOffset(); - final int endOffset= offset+loc.getNodeLength(); + final int endOffset= offset + loc.getNodeLength(); if (offset == fFileOffset && endOffset <= fFileEndOffset) return exp; } @@ -228,7 +230,8 @@ public class ASTNodeSpecification { } public IASTPreprocessorMacroExpansion findTrailingMacroExpansion(ASTNodeSelector nodeSelector) { - IASTPreprocessorMacroExpansion exp= nodeSelector.findEnclosingMacroExpansion(fFileEndOffset==fFileOffset && !fZeroToLeft ? fFileEndOffset : fFileEndOffset-1, 1); + IASTPreprocessorMacroExpansion exp= + nodeSelector.findEnclosingMacroExpansion(fFileEndOffset == fFileOffset && !fZeroToLeft ? fFileEndOffset : fFileEndOffset - 1, 1); if (fRelation == Relation.ENCLOSING || fRelation == Relation.STRICTLY_ENCLOSING) return exp; @@ -236,7 +239,7 @@ public class ASTNodeSpecification { IASTFileLocation loc= exp.getFileLocation(); if (loc != null) { final int offset= loc.getNodeOffset(); - final int endOffset= offset+loc.getNodeLength(); + final int endOffset= offset + loc.getNodeLength(); if (endOffset == fFileEndOffset && offset >= fFileOffset) return exp; }