1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2013-04-02 20:10:22 -07:00
parent a5188f1c75
commit 30081f07d5
3 changed files with 38 additions and 31 deletions

View file

@ -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 = {};
/**

View file

@ -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 extends IASTNode> T findNode(int offsetInFile, int lengthInFile, Relation relation, Class<T> requiredClass) {
private <T extends IASTNode> T findNode(int offsetInFile, int lengthInFile, Relation relation,
Class<T> requiredClass) {
return findNode(offsetInFile, lengthInFile, relation, requiredClass, false);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTNodeSelector#getNode(int, int)
*/
private <T extends IASTNode> T findNode(int offsetInFile, int lengthInFile, Relation relation,
private <T extends IASTNode> T findNode(int offsetInFile, int lengthInFile, Relation relation,
Class<T> 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<T> nodeSpec= new ASTNodeSpecification<T>(relation, requiredClass, offsetInFile, lengthInFile);
final ASTNodeSpecification<T> nodeSpec=
new ASTNodeSpecification<T>(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);

View file

@ -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<T extends IASTNode> {
private int fBestEndOffset;
private T fBestNode;
private boolean fSearchInExpansion;
private boolean fZeroToLeft= false;
private boolean fZeroToLeft;
public ASTNodeSpecification(Relation relation, Class<T> clazz, int fileOffset, int fileLength) {
fRelation= relation;
@ -80,7 +80,8 @@ public class ASTNodeSpecification<T extends IASTNode> {
@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<T extends IASTNode> {
}
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<T extends IASTNode> {
*/
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<T extends IASTNode> {
if (isBetterMatch(offset, length, astNode)) {
fBestNode= astNode;
fBestOffset= offset;
fBestEndOffset= offset+length;
fBestEndOffset= offset + length;
}
}
}
@ -172,7 +173,7 @@ public class ASTNodeSpecification<T extends IASTNode> {
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<T extends IASTNode> {
}
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<T extends IASTNode> {
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<T extends IASTNode> {
}
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<T extends IASTNode> {
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;
}