mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Cosmetics.
This commit is contained in:
parent
a5188f1c75
commit
30081f07d5
3 changed files with 38 additions and 31 deletions
|
@ -6,7 +6,7 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Mike Kucera (IBM) - Initial API and implementation
|
* Mike Kucera (IBM) - Initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.core.dom.ast;
|
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.
|
* @noimplement This interface is not intended to be implemented by clients.
|
||||||
*/
|
*/
|
||||||
public interface IASTImplicitName extends IASTName {
|
public interface IASTImplicitName extends IASTName {
|
||||||
|
|
||||||
public static final IASTImplicitName[] EMPTY_NAME_ARRAY = {};
|
public static final IASTImplicitName[] EMPTY_NAME_ARRAY = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -24,8 +24,8 @@ import org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver;
|
||||||
* @since 5.0
|
* @since 5.0
|
||||||
*/
|
*/
|
||||||
public class ASTNodeSelector implements IASTNodeSelector {
|
public class ASTNodeSelector implements IASTNodeSelector {
|
||||||
private ASTTranslationUnit fTu;
|
private final ASTTranslationUnit fTu;
|
||||||
private ILocationResolver fLocationResolver;
|
private final ILocationResolver fLocationResolver;
|
||||||
private String fFilePath;
|
private String fFilePath;
|
||||||
private final boolean fIsValid;
|
private final boolean fIsValid;
|
||||||
|
|
||||||
|
@ -46,7 +46,8 @@ public class ASTNodeSelector implements IASTNodeSelector {
|
||||||
return false;
|
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);
|
return findNode(offsetInFile, lengthInFile, relation, requiredClass, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,11 +69,12 @@ public class ASTNodeSelector implements IASTNodeSelector {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (lengthInFile > 0) {
|
if (lengthInFile > 0) {
|
||||||
sequenceLength= fLocationResolver.getSequenceNumberForFileOffset(fFilePath, offsetInFile+lengthInFile-1) + 1 - sequenceNumber;
|
sequenceLength= fLocationResolver.getSequenceNumberForFileOffset(fFilePath,
|
||||||
|
offsetInFile + lengthInFile - 1) + 1 - sequenceNumber;
|
||||||
} else {
|
} else {
|
||||||
sequenceLength= 0;
|
sequenceLength= 0;
|
||||||
if (offsetInFile > 0) {
|
if (offsetInFile > 0) {
|
||||||
altSequenceNumber= fLocationResolver.getSequenceNumberForFileOffset(fFilePath, offsetInFile-1);
|
altSequenceNumber= fLocationResolver.getSequenceNumberForFileOffset(fFilePath, offsetInFile - 1);
|
||||||
if (altSequenceNumber + 1 == sequenceNumber) {
|
if (altSequenceNumber + 1 == sequenceNumber) {
|
||||||
altSequenceNumber= -1;
|
altSequenceNumber= -1;
|
||||||
} else {
|
} 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.setRangeInSequence(sequenceNumber, sequenceLength, false);
|
||||||
nodeSpec.setSearchInExpansion(searchInExpansion);
|
nodeSpec.setSearchInExpansion(searchInExpansion);
|
||||||
getNode(nodeSpec);
|
getNode(nodeSpec);
|
||||||
|
@ -102,14 +105,16 @@ public class ASTNodeSelector implements IASTNodeSelector {
|
||||||
IASTPreprocessorMacroExpansion expansion= nodeSpec.findLeadingMacroExpansion(this);
|
IASTPreprocessorMacroExpansion expansion= nodeSpec.findLeadingMacroExpansion(this);
|
||||||
if (expansion != null) {
|
if (expansion != null) {
|
||||||
IASTFileLocation floc= expansion.getFileLocation();
|
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);
|
expansion= nodeSpec.findTrailingMacroExpansion(this);
|
||||||
if (expansion != null) {
|
if (expansion != null) {
|
||||||
IASTFileLocation floc= expansion.getFileLocation();
|
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);
|
FindNodeForOffsetAction nodeFinder= new FindNodeForOffsetAction(nodeSpec);
|
||||||
fTu.accept(nodeFinder);
|
fTu.accept(nodeFinder);
|
||||||
|
|
|
@ -17,8 +17,8 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroExpansion;
|
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroExpansion;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For searching ast-nodes by offset and length, instances of this class can be used to
|
* For searching ast-nodes by offset and length, instances of this class can be used to determine
|
||||||
* determine whether a node matches or not.
|
* whether a node matches or not.
|
||||||
*
|
*
|
||||||
* @since 5.0
|
* @since 5.0
|
||||||
*/
|
*/
|
||||||
|
@ -35,7 +35,7 @@ public class ASTNodeSpecification<T extends IASTNode> {
|
||||||
private int fBestEndOffset;
|
private int fBestEndOffset;
|
||||||
private T fBestNode;
|
private T fBestNode;
|
||||||
private boolean fSearchInExpansion;
|
private boolean fSearchInExpansion;
|
||||||
private boolean fZeroToLeft= false;
|
private boolean fZeroToLeft;
|
||||||
|
|
||||||
public ASTNodeSpecification(Relation relation, Class<T> clazz, int fileOffset, int fileLength) {
|
public ASTNodeSpecification(Relation relation, Class<T> clazz, int fileOffset, int fileLength) {
|
||||||
fRelation= relation;
|
fRelation= relation;
|
||||||
|
@ -80,7 +80,8 @@ public class ASTNodeSpecification<T extends IASTNode> {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void visit(ASTNode astNode) {
|
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();
|
IASTFileLocation loc= astNode.getFileLocation();
|
||||||
if (loc != null) {
|
if (loc != null) {
|
||||||
storeIfBest(loc, (T) astNode);
|
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) {
|
private boolean isMatchingRange(int offset, int length, int selOffset, int selEndOffset) {
|
||||||
final int endOffset= offset+length;
|
final int endOffset= offset + length;
|
||||||
switch(fRelation) {
|
switch (fRelation) {
|
||||||
case EXACT_MATCH:
|
case EXACT_MATCH:
|
||||||
return selOffset == offset && selEndOffset == endOffset;
|
return selOffset == offset && selEndOffset == endOffset;
|
||||||
case FIRST_CONTAINED:
|
case FIRST_CONTAINED:
|
||||||
|
@ -134,8 +135,8 @@ public class ASTNodeSpecification<T extends IASTNode> {
|
||||||
*/
|
*/
|
||||||
public boolean canContainMatches(ASTNode node) {
|
public boolean canContainMatches(ASTNode node) {
|
||||||
final int offset= node.getOffset();
|
final int offset= node.getOffset();
|
||||||
final int endOffset= offset+node.getLength();
|
final int endOffset= offset + node.getLength();
|
||||||
switch(fRelation) {
|
switch (fRelation) {
|
||||||
case EXACT_MATCH:
|
case EXACT_MATCH:
|
||||||
case ENCLOSING:
|
case ENCLOSING:
|
||||||
return offset <= fSeqNumber && fSeqEndNumber <= endOffset;
|
return offset <= fSeqNumber && fSeqEndNumber <= endOffset;
|
||||||
|
@ -158,7 +159,7 @@ public class ASTNodeSpecification<T extends IASTNode> {
|
||||||
if (isBetterMatch(offset, length, astNode)) {
|
if (isBetterMatch(offset, length, astNode)) {
|
||||||
fBestNode= astNode;
|
fBestNode= astNode;
|
||||||
fBestOffset= offset;
|
fBestOffset= offset;
|
||||||
fBestEndOffset= offset+length;
|
fBestEndOffset= offset + length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -172,7 +173,7 @@ public class ASTNodeSpecification<T extends IASTNode> {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int endOffset= offset+length;
|
final int endOffset= offset + length;
|
||||||
switch(fRelation) {
|
switch(fRelation) {
|
||||||
case EXACT_MATCH:
|
case EXACT_MATCH:
|
||||||
return isParent(fBestNode, cand);
|
return isParent(fBestNode, cand);
|
||||||
|
@ -211,7 +212,8 @@ public class ASTNodeSpecification<T extends IASTNode> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public IASTPreprocessorMacroExpansion findLeadingMacroExpansion(ASTNodeSelector nodeSelector) {
|
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)
|
if (fRelation == Relation.ENCLOSING || fRelation == Relation.STRICTLY_ENCLOSING)
|
||||||
return exp;
|
return exp;
|
||||||
|
|
||||||
|
@ -219,7 +221,7 @@ public class ASTNodeSpecification<T extends IASTNode> {
|
||||||
IASTFileLocation loc= exp.getFileLocation();
|
IASTFileLocation loc= exp.getFileLocation();
|
||||||
if (loc != null) {
|
if (loc != null) {
|
||||||
final int offset= loc.getNodeOffset();
|
final int offset= loc.getNodeOffset();
|
||||||
final int endOffset= offset+loc.getNodeLength();
|
final int endOffset= offset + loc.getNodeLength();
|
||||||
if (offset == fFileOffset && endOffset <= fFileEndOffset)
|
if (offset == fFileOffset && endOffset <= fFileEndOffset)
|
||||||
return exp;
|
return exp;
|
||||||
}
|
}
|
||||||
|
@ -228,7 +230,8 @@ public class ASTNodeSpecification<T extends IASTNode> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public IASTPreprocessorMacroExpansion findTrailingMacroExpansion(ASTNodeSelector nodeSelector) {
|
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)
|
if (fRelation == Relation.ENCLOSING || fRelation == Relation.STRICTLY_ENCLOSING)
|
||||||
return exp;
|
return exp;
|
||||||
|
|
||||||
|
@ -236,7 +239,7 @@ public class ASTNodeSpecification<T extends IASTNode> {
|
||||||
IASTFileLocation loc= exp.getFileLocation();
|
IASTFileLocation loc= exp.getFileLocation();
|
||||||
if (loc != null) {
|
if (loc != null) {
|
||||||
final int offset= loc.getNodeOffset();
|
final int offset= loc.getNodeOffset();
|
||||||
final int endOffset= offset+loc.getNodeLength();
|
final int endOffset= offset + loc.getNodeLength();
|
||||||
if (endOffset == fFileEndOffset && offset >= fFileOffset)
|
if (endOffset == fFileEndOffset && offset >= fFileOffset)
|
||||||
return exp;
|
return exp;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue