mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Updated Selection Search to use the parser exclusively for Open Declaration actions. <BR>
Fixed OpenDeclarationAction to open external files again.
This commit is contained in:
parent
b2de2fdd6c
commit
7a2c6de5fb
23 changed files with 397 additions and 87 deletions
|
@ -129,6 +129,22 @@ public class CompleteParseBaseTest extends TestCase
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.parser.ast.IASTNode#getFileIndex()
|
||||||
|
*/
|
||||||
|
public int getFileIndex() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.parser.ast.IASTNode#setFileIndex(int)
|
||||||
|
*/
|
||||||
|
public void setFileIndex(int index) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class CodeScope extends Scope implements IASTCodeScope
|
public static class CodeScope extends Scope implements IASTCodeScope
|
||||||
|
|
|
@ -53,7 +53,9 @@ public class SelectionParseTest extends CompleteParseBaseTest {
|
||||||
ParserLanguage.CPP,
|
ParserLanguage.CPP,
|
||||||
ParserUtil.getParserLogService());
|
ParserUtil.getParserLogService());
|
||||||
|
|
||||||
return parser.parse( offset1, offset2 );
|
IParser.ISelectionParseResult result =parser.parse( offset1, offset2 );
|
||||||
|
if( result == null ) return null;
|
||||||
|
return (IASTNode) result.getOffsetableNamedElement();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,5 +16,7 @@ package org.eclipse.cdt.core.parser;
|
||||||
public interface IFilenameProvider {
|
public interface IFilenameProvider {
|
||||||
|
|
||||||
public char [] getCurrentFilename();
|
public char [] getCurrentFilename();
|
||||||
|
public int getCurrentFileIndex();
|
||||||
|
public String getFilenameForIndex( int index );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
package org.eclipse.cdt.core.parser;
|
package org.eclipse.cdt.core.parser;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
|
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTNode;
|
import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,13 +36,19 @@ public interface IParser {
|
||||||
*/
|
*/
|
||||||
public IASTCompletionNode parse( int offset) throws ParseError;
|
public IASTCompletionNode parse( int offset) throws ParseError;
|
||||||
|
|
||||||
|
|
||||||
|
public static interface ISelectionParseResult
|
||||||
|
{
|
||||||
|
public IASTOffsetableNamedElement getOffsetableNamedElement();
|
||||||
|
public String getFilename();
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param startingOffset
|
* @param startingOffset
|
||||||
* @param endingOffset
|
* @param endingOffset
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public IASTNode parse( int startingOffset, int endingOffset ) throws ParseError;
|
public ISelectionParseResult parse( int startingOffset, int endingOffset ) throws ParseError;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If an error was encountered, give us the offset of the token that caused the error.
|
* If an error was encountered, give us the offset of the token that caused the error.
|
||||||
|
|
|
@ -20,7 +20,6 @@ import org.eclipse.cdt.core.parser.ParserFactory;
|
||||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||||
import org.eclipse.cdt.core.parser.ParserMode;
|
import org.eclipse.cdt.core.parser.ParserMode;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
|
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTNode;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTScope;
|
import org.eclipse.cdt.core.parser.ast.IASTScope;
|
||||||
import org.eclipse.cdt.core.parser.extension.IParserExtension;
|
import org.eclipse.cdt.core.parser.extension.IParserExtension;
|
||||||
|
|
||||||
|
@ -60,7 +59,7 @@ public class CompleteParser extends Parser {
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.parser.IParser#parse(int, int)
|
* @see org.eclipse.cdt.core.parser.IParser#parse(int, int)
|
||||||
*/
|
*/
|
||||||
public IASTNode parse(int startingOffset, int endingOffset) throws ParseError {
|
public ISelectionParseResult parse(int startingOffset, int endingOffset) throws ParseError {
|
||||||
throw new ParseError( ParseError.ParseErrorKind.METHOD_NOT_IMPLEMENTED );
|
throw new ParseError( ParseError.ParseErrorKind.METHOD_NOT_IMPLEMENTED );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,6 @@ import org.eclipse.cdt.core.parser.ParserMode;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
|
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTCodeScope;
|
import org.eclipse.cdt.core.parser.ast.IASTCodeScope;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
|
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTNode;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTScope;
|
import org.eclipse.cdt.core.parser.ast.IASTScope;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind;
|
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind;
|
||||||
import org.eclipse.cdt.core.parser.extension.IParserExtension;
|
import org.eclipse.cdt.core.parser.extension.IParserExtension;
|
||||||
|
@ -149,7 +148,7 @@ public class CompletionParser extends ContextualParser implements IParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IASTNode parse(int startingOffset, int endingOffset) {
|
public ISelectionParseResult parse(int startingOffset, int endingOffset) {
|
||||||
throw new ParseError( ParseError.ParseErrorKind.METHOD_NOT_IMPLEMENTED );
|
throw new ParseError( ParseError.ParseErrorKind.METHOD_NOT_IMPLEMENTED );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2916,4 +2916,16 @@ public class ExpressionParser implements IExpressionParser, IParserData {
|
||||||
IToken first = consume(IToken.tIDENTIFIER); // throws backtrack if its not that
|
IToken first = consume(IToken.tIDENTIFIER); // throws backtrack if its not that
|
||||||
return first;
|
return first;
|
||||||
}
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.parser.IFilenameProvider#getCurrentFileIndex()
|
||||||
|
*/
|
||||||
|
public int getCurrentFileIndex() {
|
||||||
|
return scanner.getCurrentFileIndex();
|
||||||
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.parser.IFilenameProvider#getFilenameForIndex(int)
|
||||||
|
*/
|
||||||
|
public String getFilenameForIndex(int index) {
|
||||||
|
return scanner.getFilenameForIndex(index);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,7 @@ import org.eclipse.cdt.core.parser.ast.IASTNamespaceAlias;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
|
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTNode;
|
import org.eclipse.cdt.core.parser.ast.IASTNode;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTOffsetableElement;
|
import org.eclipse.cdt.core.parser.ast.IASTOffsetableElement;
|
||||||
|
import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTScope;
|
import org.eclipse.cdt.core.parser.ast.IASTScope;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier;
|
import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTemplate;
|
import org.eclipse.cdt.core.parser.ast.IASTTemplate;
|
||||||
|
@ -3076,7 +3077,7 @@ public abstract class Parser extends ExpressionParser implements IParser
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.parser.IParser#parse(int, int)
|
* @see org.eclipse.cdt.core.parser.IParser#parse(int, int)
|
||||||
*/
|
*/
|
||||||
public IASTNode parse(int startingOffset, int endingOffset)
|
public ISelectionParseResult parse(int startingOffset, int endingOffset)
|
||||||
throws ParseError {
|
throws ParseError {
|
||||||
throw new ParseError( ParseError.ParseErrorKind.METHOD_NOT_IMPLEMENTED );
|
throw new ParseError( ParseError.ParseErrorKind.METHOD_NOT_IMPLEMENTED );
|
||||||
}
|
}
|
||||||
|
@ -3111,6 +3112,8 @@ public abstract class Parser extends ExpressionParser implements IParser
|
||||||
protected void endDeclaration( IASTDeclaration declaration ) throws EndOfFileException
|
protected void endDeclaration( IASTDeclaration declaration ) throws EndOfFileException
|
||||||
{
|
{
|
||||||
cleanupLastToken();
|
cleanupLastToken();
|
||||||
|
if( declaration instanceof IASTOffsetableNamedElement )
|
||||||
|
handleNode( (IASTOffsetableNamedElement) declaration );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3126,4 +3129,11 @@ public abstract class Parser extends ExpressionParser implements IParser
|
||||||
{
|
{
|
||||||
cleanupLastToken();
|
cleanupLastToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param expression
|
||||||
|
*/
|
||||||
|
protected void handleNode(IASTOffsetableNamedElement node ) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,6 @@ import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||||
import org.eclipse.cdt.core.parser.ParserMode;
|
import org.eclipse.cdt.core.parser.ParserMode;
|
||||||
import org.eclipse.cdt.core.parser.ParseError.ParseErrorKind;
|
import org.eclipse.cdt.core.parser.ParseError.ParseErrorKind;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
|
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTNode;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTScope;
|
import org.eclipse.cdt.core.parser.ast.IASTScope;
|
||||||
import org.eclipse.cdt.core.parser.extension.IParserExtension;
|
import org.eclipse.cdt.core.parser.extension.IParserExtension;
|
||||||
|
|
||||||
|
@ -61,7 +60,7 @@ public class QuickParser extends Parser {
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.parser.IParser#parse(int, int)
|
* @see org.eclipse.cdt.core.parser.IParser#parse(int, int)
|
||||||
*/
|
*/
|
||||||
public IASTNode parse(int startingOffset, int endingOffset) throws ParseError {
|
public ISelectionParseResult parse(int startingOffset, int endingOffset) throws ParseError {
|
||||||
throw new ParseError( ParseErrorKind.METHOD_NOT_IMPLEMENTED );
|
throw new ParseError( ParseErrorKind.METHOD_NOT_IMPLEMENTED );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,9 @@
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.parser;
|
package org.eclipse.cdt.internal.core.parser;
|
||||||
|
|
||||||
|
import java.util.Hashtable;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.EndOfFileException;
|
import org.eclipse.cdt.core.parser.EndOfFileException;
|
||||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||||
|
@ -45,6 +47,8 @@ public class SelectionParser extends ContextualParser {
|
||||||
private ITokenDuple greaterContextDuple = null;
|
private ITokenDuple greaterContextDuple = null;
|
||||||
private boolean pastPointOfSelection = false;
|
private boolean pastPointOfSelection = false;
|
||||||
private IASTNode contextNode = null;
|
private IASTNode contextNode = null;
|
||||||
|
private static final int DEFAULT_MAP_SIZE = 512;
|
||||||
|
private static final float DEFAULT_FLOAT_SIZE = 0.75f;
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.internal.core.parser.Parser#handleNewToken(org.eclipse.cdt.core.parser.IToken)
|
* @see org.eclipse.cdt.internal.core.parser.Parser#handleNewToken(org.eclipse.cdt.core.parser.IToken)
|
||||||
|
@ -102,7 +106,7 @@ public class SelectionParser extends ContextualParser {
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.parser.IParser#parse(int, int)
|
* @see org.eclipse.cdt.core.parser.IParser#parse(int, int)
|
||||||
*/
|
*/
|
||||||
public IASTNode parse(int startingOffset, int endingOffset) {
|
public ISelectionParseResult parse(int startingOffset, int endingOffset) {
|
||||||
offsetRange = new OffsetDuple( startingOffset, endingOffset );
|
offsetRange = new OffsetDuple( startingOffset, endingOffset );
|
||||||
translationUnit();
|
translationUnit();
|
||||||
return reconcileTokenDuple();
|
return reconcileTokenDuple();
|
||||||
|
@ -111,7 +115,7 @@ public class SelectionParser extends ContextualParser {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
protected IASTNode reconcileTokenDuple() throws ParseError {
|
protected ISelectionParseResult reconcileTokenDuple() throws ParseError {
|
||||||
if( firstTokenOfDuple == null || lastTokenOfDuple == null )
|
if( firstTokenOfDuple == null || lastTokenOfDuple == null )
|
||||||
throw new ParseError( ParseError.ParseErrorKind.OFFSET_RANGE_NOT_NAME );
|
throw new ParseError( ParseError.ParseErrorKind.OFFSET_RANGE_NOT_NAME );
|
||||||
|
|
||||||
|
@ -130,7 +134,7 @@ public class SelectionParser extends ContextualParser {
|
||||||
* @param duple
|
* @param duple
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
protected IASTNode provideSelectionNode(ITokenDuple duple) {
|
protected ISelectionParseResult provideSelectionNode(ITokenDuple duple) {
|
||||||
|
|
||||||
ITokenDuple finalDuple = null;
|
ITokenDuple finalDuple = null;
|
||||||
// reconcile the name to look up first
|
// reconcile the name to look up first
|
||||||
|
@ -150,8 +154,15 @@ public class SelectionParser extends ContextualParser {
|
||||||
else
|
else
|
||||||
finalDuple = greaterContextDuple;
|
finalDuple = greaterContextDuple;
|
||||||
|
|
||||||
|
IASTNode node = lookupNode(finalDuple);
|
||||||
|
if( node == null ) return null;
|
||||||
|
if( !(node instanceof IASTOffsetableNamedElement )) return null;
|
||||||
|
int indexValue = -1;
|
||||||
|
Object index = nodeTable.get( node );
|
||||||
|
if( index instanceof Integer )
|
||||||
|
indexValue = ((Integer)index).intValue();
|
||||||
|
|
||||||
return lookupNode(finalDuple);
|
return new SelectionParseResult( (IASTOffsetableNamedElement) node, getFilenameForIndex(indexValue) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -258,4 +269,41 @@ public class SelectionParser extends ContextualParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Map nodeTable = new Hashtable( DEFAULT_MAP_SIZE, DEFAULT_FLOAT_SIZE );
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.internal.core.parser.Parser#handleNode(org.eclipse.cdt.core.parser.ast.IASTNode)
|
||||||
|
*/
|
||||||
|
protected void handleNode(IASTOffsetableNamedElement node) {
|
||||||
|
if( node != null )
|
||||||
|
nodeTable.put( node, new Integer( getCurrentFileIndex()) );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SelectionParseResult implements ISelectionParseResult
|
||||||
|
{
|
||||||
|
|
||||||
|
public SelectionParseResult( IASTOffsetableNamedElement node, String fileName )
|
||||||
|
{
|
||||||
|
this.node = node;
|
||||||
|
this.fileName = fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final String fileName;
|
||||||
|
private final IASTOffsetableNamedElement node;
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.parser.IParser.ISelectionParseResult#getNode()
|
||||||
|
*/
|
||||||
|
public IASTOffsetableNamedElement getOffsetableNamedElement() {
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.parser.IParser.ISelectionParseResult#getFilename()
|
||||||
|
*/
|
||||||
|
public String getFilename() {
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,6 @@ import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||||
import org.eclipse.cdt.core.parser.ParserMode;
|
import org.eclipse.cdt.core.parser.ParserMode;
|
||||||
import org.eclipse.cdt.core.parser.ParseError.ParseErrorKind;
|
import org.eclipse.cdt.core.parser.ParseError.ParseErrorKind;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
|
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTNode;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTScope;
|
import org.eclipse.cdt.core.parser.ast.IASTScope;
|
||||||
import org.eclipse.cdt.core.parser.extension.IParserExtension;
|
import org.eclipse.cdt.core.parser.extension.IParserExtension;
|
||||||
|
|
||||||
|
@ -69,7 +68,7 @@ public class StructuralParser extends Parser implements IParser {
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.parser.IParser#parse(int, int)
|
* @see org.eclipse.cdt.core.parser.IParser#parse(int, int)
|
||||||
*/
|
*/
|
||||||
public IASTNode parse(int startingOffset, int endingOffset) throws ParseError {
|
public ISelectionParseResult parse(int startingOffset, int endingOffset) throws ParseError {
|
||||||
throw new ParseError( ParseErrorKind.METHOD_NOT_IMPLEMENTED );
|
throw new ParseError( ParseErrorKind.METHOD_NOT_IMPLEMENTED );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -157,6 +157,7 @@ public class ASTInclusion implements IASTInclusion {
|
||||||
}
|
}
|
||||||
|
|
||||||
private int startingLineNumber, endingLineNumber, nameLineNumber;
|
private int startingLineNumber, endingLineNumber, nameLineNumber;
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine()
|
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine()
|
||||||
*/
|
*/
|
||||||
|
@ -175,4 +176,19 @@ public class ASTInclusion implements IASTInclusion {
|
||||||
public int getNameLineNumber() {
|
public int getNameLineNumber() {
|
||||||
return nameLineNumber;
|
return nameLineNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int fileIndex;
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFileIndex()
|
||||||
|
*/
|
||||||
|
public int getFileIndex() {
|
||||||
|
return fileIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setFileIndex()
|
||||||
|
*/
|
||||||
|
public void setFileIndex(int index) {
|
||||||
|
fileIndex = index;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -186,4 +186,20 @@ public class ASTMacro implements IASTMacro {
|
||||||
public boolean isCircular() {
|
public boolean isCircular() {
|
||||||
return innerMacro.isCircular();
|
return innerMacro.isCircular();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int fileIndex;
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFileIndex()
|
||||||
|
*/
|
||||||
|
public int getFileIndex() {
|
||||||
|
return fileIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setFileIndex()
|
||||||
|
*/
|
||||||
|
public void setFileIndex(int index) {
|
||||||
|
fileIndex = index;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -344,6 +344,7 @@ public class ASTExpression extends ASTNode implements IASTExpression
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private ASTExpression recursiveFindExpressionForDuple(IASTExpression expression, ITokenDuple duple) {
|
private ASTExpression recursiveFindExpressionForDuple(IASTExpression expression, ITokenDuple duple) {
|
||||||
|
if( expression == null ) return null;
|
||||||
return ((ASTExpression)expression).findOwnerExpressionForIDExpression(duple);
|
return ((ASTExpression)expression).findOwnerExpressionForIDExpression(duple);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2402,6 +2402,8 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
||||||
resolveLeftoverConstructorInitializerMembers( symbol, constructorChain );
|
resolveLeftoverConstructorInitializerMembers( symbol, constructorChain );
|
||||||
|
|
||||||
ASTMethod method = new ASTMethod( symbol, parameters, returnType, exception, startOffset, startingLine, nameOffset, nameEndOffset, nameLine, ownerTemplate, references, previouslyDeclared, isConstructor, isDestructor, isPureVirtual, visibility, constructorChain, hasFunctionTryBlock, isFriend );
|
ASTMethod method = new ASTMethod( symbol, parameters, returnType, exception, startOffset, startingLine, nameOffset, nameEndOffset, nameLine, ownerTemplate, references, previouslyDeclared, isConstructor, isDestructor, isPureVirtual, visibility, constructorChain, hasFunctionTryBlock, isFriend );
|
||||||
|
if( functionDeclaration != null && isFunctionDefinition )
|
||||||
|
attachSymbolExtension( symbol, (ASTSymbol) functionDeclaration.getASTExtension().getPrimaryDeclaration(), false );
|
||||||
attachSymbolExtension( symbol, method, isFunctionDefinition );
|
attachSymbolExtension( symbol, method, isFunctionDefinition );
|
||||||
return method;
|
return method;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,13 +45,49 @@ public class ContextStack {
|
||||||
public int getLine() { return -1; }
|
public int getLine() { return -1; }
|
||||||
public int undoStackSize() { return 0; }
|
public int undoStackSize() { return 0; }
|
||||||
public int popUndo() { return '\n'; }
|
public int popUndo() { return '\n'; }
|
||||||
|
public int getFilenameIndex() { return -1; }
|
||||||
}
|
}
|
||||||
private final IParserLogService log;
|
private final IParserLogService log;
|
||||||
private int current_size = 8;
|
private int current_size = 8;
|
||||||
|
|
||||||
private IScannerContext [] cs = new IScannerContext[current_size];
|
private IScannerContext [] cs = new IScannerContext[current_size];
|
||||||
private int cs_pos = 0;
|
private int cs_pos = 0;
|
||||||
|
|
||||||
|
private int currentInclusionArraySize = 16;
|
||||||
|
private int currentInclusionIndex = 0;
|
||||||
|
private String [] fileNames = new String[ currentInclusionArraySize ];
|
||||||
|
private static final String EMPTY_STRING = ""; //$NON-NLS-1$
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public final String getInclusionFilename( int index )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return fileNames[ index ];
|
||||||
|
}
|
||||||
|
catch( ArrayIndexOutOfBoundsException aioobe )
|
||||||
|
{
|
||||||
|
return EMPTY_STRING;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final void addInclusionFilename( String filename )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
fileNames[ currentInclusionIndex++ ] = filename;
|
||||||
|
}
|
||||||
|
catch( ArrayIndexOutOfBoundsException aioobe )
|
||||||
|
{
|
||||||
|
int newSize = currentInclusionArraySize * 2;
|
||||||
|
String newFileNames [] = new String[ newSize ];
|
||||||
|
System.arraycopy( fileNames, 0, newFileNames, 0, fileNames.length );
|
||||||
|
newFileNames[ currentInclusionArraySize++ ] = filename;
|
||||||
|
currentInclusionArraySize = newSize;
|
||||||
|
fileNames = newFileNames;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static IScannerContext sentinel = new SentinelContext();
|
private static IScannerContext sentinel = new SentinelContext();
|
||||||
|
|
||||||
|
@ -65,11 +101,7 @@ public class ContextStack {
|
||||||
{
|
{
|
||||||
int new_size = current_size*2;
|
int new_size = current_size*2;
|
||||||
IScannerContext [] new_cs = new IScannerContext[new_size];
|
IScannerContext [] new_cs = new IScannerContext[new_size];
|
||||||
|
System.arraycopy( cs, 0, new_cs, 0, cs.length );
|
||||||
for (int i = 0; i < current_size; i++) {
|
|
||||||
new_cs[i] = cs[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
new_cs[current_size] = c;
|
new_cs[current_size] = c;
|
||||||
current_size = new_size;
|
current_size = new_size;
|
||||||
cs = new_cs;
|
cs = new_cs;
|
||||||
|
@ -96,6 +128,7 @@ public class ContextStack {
|
||||||
public void updateContext(Reader reader, String filename, int type, IASTInclusion inclusion, ISourceElementRequestor requestor, int macroOffset, int macroLength) throws ContextException
|
public void updateContext(Reader reader, String filename, int type, IASTInclusion inclusion, ISourceElementRequestor requestor, int macroOffset, int macroLength) throws ContextException
|
||||||
{
|
{
|
||||||
int startLine = 1;
|
int startLine = 1;
|
||||||
|
int index = -1;
|
||||||
|
|
||||||
// If we expand a macro within a macro, then keep offsets of the top-level one,
|
// If we expand a macro within a macro, then keep offsets of the top-level one,
|
||||||
// as only the top level macro identifier is properly positioned
|
// as only the top level macro identifier is properly positioned
|
||||||
|
@ -107,8 +140,13 @@ public class ContextStack {
|
||||||
|
|
||||||
startLine = getCurrentContext().getLine();
|
startLine = getCurrentContext().getLine();
|
||||||
}
|
}
|
||||||
|
else if( type == IScannerContext.ContextKind.INCLUSION )
|
||||||
IScannerContext context = new ScannerContext( reader, filename, type, null, macroOffset, macroLength, startLine );
|
{
|
||||||
|
addInclusionFilename( filename );
|
||||||
|
index = currentInclusionIndex - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
IScannerContext context = new ScannerContext( reader, filename, type, null, macroOffset, macroLength, startLine, index );
|
||||||
context.setExtension(inclusion);
|
context.setExtension(inclusion);
|
||||||
push( context, requestor );
|
push( context, requestor );
|
||||||
}
|
}
|
||||||
|
@ -121,7 +159,11 @@ public class ContextStack {
|
||||||
|
|
||||||
TraceUtil.outputTrace(log, "Scanner::ContextStack: entering inclusion ", null, context.getFilename(), null, null ); //$NON-NLS-1$
|
TraceUtil.outputTrace(log, "Scanner::ContextStack: entering inclusion ", null, context.getFilename(), null, null ); //$NON-NLS-1$
|
||||||
context.getExtension().enterScope( requestor );
|
context.getExtension().enterScope( requestor );
|
||||||
}
|
}
|
||||||
|
else if( context.getKind() == IScannerContext.ContextKind.TOP )
|
||||||
|
{
|
||||||
|
addInclusionFilename( context.getFilename() );
|
||||||
|
}
|
||||||
|
|
||||||
// This could be replaced with a check for shouldExpandMacro -- but it is called by
|
// This could be replaced with a check for shouldExpandMacro -- but it is called by
|
||||||
// the scanner before this point
|
// the scanner before this point
|
||||||
|
|
|
@ -63,6 +63,8 @@ public interface IScannerContext {
|
||||||
|
|
||||||
public IASTInclusion getExtension();
|
public IASTInclusion getExtension();
|
||||||
public void setExtension( IASTInclusion ext );
|
public void setExtension( IASTInclusion ext );
|
||||||
|
|
||||||
|
public int getFilenameIndex();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return
|
* @return
|
||||||
|
|
|
@ -30,8 +30,8 @@ public class LimitedScannerContext
|
||||||
* @param object
|
* @param object
|
||||||
* @param offsetLimit
|
* @param offsetLimit
|
||||||
*/
|
*/
|
||||||
public LimitedScannerContext(Scanner scanner, Reader reader, String string, int kind, int offsetLimit) {
|
public LimitedScannerContext(Scanner scanner, Reader reader, String string, int kind, int offsetLimit, int index ) {
|
||||||
super( reader, string, kind, null );
|
super( reader, string, kind, null, index );
|
||||||
this.scanner = scanner;
|
this.scanner = scanner;
|
||||||
limit = offsetLimit;
|
limit = offsetLimit;
|
||||||
}
|
}
|
||||||
|
|
|
@ -282,9 +282,9 @@ public class Scanner implements IScanner {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if( offsetLimit == NO_OFFSET_LIMIT )
|
if( offsetLimit == NO_OFFSET_LIMIT )
|
||||||
context = new ScannerContext(scannerData.getInitialReader(), resolvedFilename, ScannerContext.ContextKind.TOP, null );
|
context = new ScannerContext(scannerData.getInitialReader(), resolvedFilename, ScannerContext.ContextKind.TOP, null, 0 );
|
||||||
else
|
else
|
||||||
context = new LimitedScannerContext( this, scannerData.getInitialReader(), resolvedFilename, ScannerContext.ContextKind.TOP, offsetLimit );
|
context = new LimitedScannerContext( this, scannerData.getInitialReader(), resolvedFilename, ScannerContext.ContextKind.TOP, offsetLimit, 0 );
|
||||||
scannerData.getContextStack().push( context, scannerData.getClientRequestor() );
|
scannerData.getContextStack().push( context, scannerData.getClientRequestor() );
|
||||||
} catch( ContextException ce )
|
} catch( ContextException ce )
|
||||||
{
|
{
|
||||||
|
@ -2132,7 +2132,7 @@ public class Scanner implements IScanner {
|
||||||
return newToken( type, buffer.toString());
|
return newToken( type, buffer.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected String getCurrentFile()
|
protected String getCurrentFile()
|
||||||
{
|
{
|
||||||
|
@ -3214,4 +3214,20 @@ public class Scanner implements IScanner {
|
||||||
buffer.append( "EOF"); //$NON-NLS-1$
|
buffer.append( "EOF"); //$NON-NLS-1$
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.parser.IFilenameProvider#getCurrentFileIndex()
|
||||||
|
*/
|
||||||
|
public int getCurrentFileIndex() {
|
||||||
|
IScannerContext mostRelevantFileContext = scannerData.getContextStack().getMostRelevantFileContext();
|
||||||
|
return (( mostRelevantFileContext == null ) ? -1 : mostRelevantFileContext.getFilenameIndex() );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.parser.IFilenameProvider#getFilenameForIndex(int)
|
||||||
|
*/
|
||||||
|
public String getFilenameForIndex(int index) {
|
||||||
|
if( index < 0 ) return EMPTY_STRING;
|
||||||
|
return scannerData.getContextStack().getInclusionFilename(index);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ public class ScannerContext implements IScannerContext
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.internal.core.parser.IScannerContext#initialize(Reader, String, int, IASTInclusion, int, int, int)
|
* @see org.eclipse.cdt.internal.core.parser.IScannerContext#initialize(Reader, String, int, IASTInclusion, int, int, int)
|
||||||
*/
|
*/
|
||||||
public ScannerContext(Reader r, String f, int k, IASTInclusion i, int mO, int mL, int l)
|
public ScannerContext(Reader r, String f, int k, IASTInclusion i, int mO, int mL, int l, int index)
|
||||||
{
|
{
|
||||||
reader = r;
|
reader = r;
|
||||||
filename = f;
|
filename = f;
|
||||||
|
@ -38,14 +38,15 @@ public class ScannerContext implements IScannerContext
|
||||||
macroOffset = mO;
|
macroOffset = mO;
|
||||||
macroLength = mL;
|
macroLength = mL;
|
||||||
line = l;
|
line = l;
|
||||||
|
this.index = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.internal.core.parser.IScannerContext#initialize(Reader, String, int, IASTInclusion)
|
* @see org.eclipse.cdt.internal.core.parser.IScannerContext#initialize(Reader, String, int, IASTInclusion)
|
||||||
*/
|
*/
|
||||||
public ScannerContext(Reader r, String f, int k, IASTInclusion i)
|
public ScannerContext(Reader r, String f, int k, IASTInclusion i, int index)
|
||||||
{
|
{
|
||||||
this(r, f, k, i, -1, -1, 1);
|
this(r, f, k, i, -1, -1, 1, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int read() throws IOException {
|
public int read() throws IOException {
|
||||||
|
@ -176,6 +177,7 @@ public class ScannerContext implements IScannerContext
|
||||||
}
|
}
|
||||||
|
|
||||||
private IASTInclusion inc = null;
|
private IASTInclusion inc = null;
|
||||||
|
private final int index;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -191,4 +193,11 @@ public class ScannerContext implements IScannerContext
|
||||||
buffer.append( getLine() );
|
buffer.append( getLine() );
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.internal.core.parser.scanner.IScannerContext#getFilenameIndex()
|
||||||
|
*/
|
||||||
|
public int getFilenameIndex() {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,13 +57,7 @@ public class ParserUtil
|
||||||
// IResource in the workspace
|
// IResource in the workspace
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
IWorkspace workspace = ResourcesPlugin.getWorkspace();
|
IResource resultingResource = getResourceForFilename(finalPath);
|
||||||
IPath path = new Path( finalPath );
|
|
||||||
|
|
||||||
if( workspace.getRoot().getLocation().isPrefixOf( path ) )
|
|
||||||
path = path.removeFirstSegments(workspace.getRoot().getLocation().segmentCount() );
|
|
||||||
|
|
||||||
IResource resultingResource = workspace.getRoot().findMember(path);
|
|
||||||
|
|
||||||
if( resultingResource != null && resultingResource.getType() == IResource.FILE )
|
if( resultingResource != null && resultingResource.getType() == IResource.FILE )
|
||||||
{
|
{
|
||||||
|
@ -85,6 +79,21 @@ public class ParserUtil
|
||||||
return InternalParserUtil.createFileReader(finalPath);
|
return InternalParserUtil.createFileReader(finalPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param finalPath
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static IResource getResourceForFilename(String finalPath) {
|
||||||
|
IWorkspace workspace = ResourcesPlugin.getWorkspace();
|
||||||
|
IPath path = new Path( finalPath );
|
||||||
|
|
||||||
|
if( workspace.getRoot().getLocation().isPrefixOf( path ) )
|
||||||
|
path = path.removeFirstSegments(workspace.getRoot().getLocation().segmentCount() );
|
||||||
|
|
||||||
|
IResource resultingResource = workspace.getRoot().findMember(path);
|
||||||
|
return resultingResource;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param resultingResource
|
* @param resultingResource
|
||||||
* @param workingCopies
|
* @param workingCopies
|
||||||
|
@ -92,7 +101,7 @@ public class ParserUtil
|
||||||
*/
|
*/
|
||||||
protected static Reader findWorkingCopy(IResource resultingResource, Iterator workingCopies) {
|
protected static Reader findWorkingCopy(IResource resultingResource, Iterator workingCopies) {
|
||||||
if( parserLogService.isTracing() )
|
if( parserLogService.isTracing() )
|
||||||
parserLogService.traceLog( "Attempting to find the working copy for " + resultingResource.getName() );
|
parserLogService.traceLog( "Attempting to find the working copy for " + resultingResource.getName() ); //$NON-NLS-1$
|
||||||
while( workingCopies.hasNext() )
|
while( workingCopies.hasNext() )
|
||||||
{
|
{
|
||||||
Object next = workingCopies.next();
|
Object next = workingCopies.next();
|
||||||
|
@ -102,12 +111,12 @@ public class ParserUtil
|
||||||
{
|
{
|
||||||
CharArrayReader arrayReader = new CharArrayReader( copy.getContents() );
|
CharArrayReader arrayReader = new CharArrayReader( copy.getContents() );
|
||||||
if( parserLogService.isTracing() )
|
if( parserLogService.isTracing() )
|
||||||
parserLogService.traceLog( "Working copy found!!" );
|
parserLogService.traceLog( "Working copy found!!" ); //$NON-NLS-1$
|
||||||
return new BufferedReader( arrayReader );
|
return new BufferedReader( arrayReader );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( parserLogService.isTracing() )
|
if( parserLogService.isTracing() )
|
||||||
parserLogService.traceLog( "Working copy not found." );
|
parserLogService.traceLog( "Working copy not found." ); //$NON-NLS-1$
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,7 @@ import org.eclipse.cdt.core.parser.ast.IASTFunction;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTMethod;
|
import org.eclipse.cdt.core.parser.ast.IASTMethod;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
|
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTNode;
|
import org.eclipse.cdt.core.parser.ast.IASTNode;
|
||||||
|
import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
||||||
import org.eclipse.cdt.core.search.ICSearchConstants;
|
import org.eclipse.cdt.core.search.ICSearchConstants;
|
||||||
import org.eclipse.cdt.core.search.ICSearchScope;
|
import org.eclipse.cdt.core.search.ICSearchScope;
|
||||||
|
@ -183,10 +184,13 @@ public abstract class FindAction extends Action {
|
||||||
|
|
||||||
IFile resourceFile = fEditor.getInputFile();
|
IFile resourceFile = fEditor.getInputFile();
|
||||||
IParser parser = setupParser(resourceFile);
|
IParser parser = setupParser(resourceFile);
|
||||||
IASTNode node = null;
|
IASTOffsetableNamedElement node = null;
|
||||||
|
IParser.ISelectionParseResult result = null;
|
||||||
|
|
||||||
try{
|
try{
|
||||||
node = parser.parse(selectionStart,selectionEnd);
|
result = parser.parse(selectionStart,selectionEnd);
|
||||||
|
if( result != null )
|
||||||
|
node = result.getOffsetableNamedElement();
|
||||||
}
|
}
|
||||||
catch (ParseError er){}
|
catch (ParseError er){}
|
||||||
catch (Exception ex){}
|
catch (Exception ex){}
|
||||||
|
@ -196,12 +200,12 @@ public abstract class FindAction extends Action {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node == null){
|
if (node == null || !( node instanceof IASTNode )){
|
||||||
operationNotAvailableDialog();
|
operationNotAvailableDialog();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CSearchQuery job = createSearchQuery(selectedText.getText(),getSearchForFromNode(node));
|
CSearchQuery job = createSearchQuery(selectedText.getText(),getSearchForFromNode((IASTNode)node));
|
||||||
NewSearchUI.activateSearchResultView();
|
NewSearchUI.activateSearchResultView();
|
||||||
|
|
||||||
NewSearchUI.runQuery(job);
|
NewSearchUI.runQuery(job);
|
||||||
|
|
|
@ -42,10 +42,11 @@ import org.eclipse.cdt.core.parser.ast.IASTFunction;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTMethod;
|
import org.eclipse.cdt.core.parser.ast.IASTMethod;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
|
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTNode;
|
import org.eclipse.cdt.core.parser.ast.IASTNode;
|
||||||
|
import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
||||||
|
import org.eclipse.cdt.core.resources.FileStorage;
|
||||||
import org.eclipse.cdt.core.search.BasicSearchResultCollector;
|
import org.eclipse.cdt.core.search.BasicSearchResultCollector;
|
||||||
import org.eclipse.cdt.core.search.ICSearchConstants;
|
import org.eclipse.cdt.core.search.ICSearchConstants;
|
||||||
import org.eclipse.cdt.core.search.ICSearchPattern;
|
|
||||||
import org.eclipse.cdt.core.search.ICSearchScope;
|
import org.eclipse.cdt.core.search.ICSearchScope;
|
||||||
import org.eclipse.cdt.core.search.IMatch;
|
import org.eclipse.cdt.core.search.IMatch;
|
||||||
import org.eclipse.cdt.core.search.OrPattern;
|
import org.eclipse.cdt.core.search.OrPattern;
|
||||||
|
@ -61,7 +62,11 @@ import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
import org.eclipse.cdt.ui.IWorkingCopyManager;
|
import org.eclipse.cdt.ui.IWorkingCopyManager;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
|
import org.eclipse.core.resources.IResource;
|
||||||
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
import org.eclipse.core.runtime.Path;
|
||||||
import org.eclipse.jface.action.Action;
|
import org.eclipse.jface.action.Action;
|
||||||
import org.eclipse.jface.dialogs.MessageDialog;
|
import org.eclipse.jface.dialogs.MessageDialog;
|
||||||
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
|
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
|
||||||
|
@ -146,6 +151,48 @@ public class OpenDeclarationsAction extends Action implements IUpdate {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class Storage
|
||||||
|
{
|
||||||
|
private IASTOffsetableNamedElement element;
|
||||||
|
private IResource resource;
|
||||||
|
private String fileName;
|
||||||
|
|
||||||
|
public IASTOffsetableNamedElement getNamedElement()
|
||||||
|
{
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @return Returns the fileName.
|
||||||
|
*/
|
||||||
|
public final String getFileName() {
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @param fileName The fileName to set.
|
||||||
|
*/
|
||||||
|
public final void setFileName(String fileName) {
|
||||||
|
this.fileName = fileName;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @return Returns the resource.
|
||||||
|
*/
|
||||||
|
public final IResource getResource() {
|
||||||
|
return resource;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @param resource The resource to set.
|
||||||
|
*/
|
||||||
|
public final void setResource(IResource resource) {
|
||||||
|
this.resource = resource;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @param element The element to set.
|
||||||
|
*/
|
||||||
|
public final void setElement(IASTOffsetableNamedElement element) {
|
||||||
|
this.element = element;
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* @see IAction#actionPerformed
|
* @see IAction#actionPerformed
|
||||||
*/
|
*/
|
||||||
|
@ -156,28 +203,27 @@ public class OpenDeclarationsAction extends Action implements IUpdate {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final ArrayList elementsFound = new ArrayList();
|
// final ArrayList elementsFound = new ArrayList();
|
||||||
|
final Storage storage = new Storage();
|
||||||
|
|
||||||
|
|
||||||
IRunnableWithProgress runnable = new IRunnableWithProgress()
|
IRunnableWithProgress runnable = new IRunnableWithProgress()
|
||||||
{
|
{
|
||||||
public void run(IProgressMonitor monitor) {
|
public void run(IProgressMonitor monitor) {
|
||||||
BasicSearchResultCollector resultCollector = new BasicSearchResultCollector(monitor);
|
// IWorkingCopyManager fManager = CUIPlugin.getDefault().getWorkingCopyManager();
|
||||||
IWorkingCopyManager fManager = CUIPlugin.getDefault().getWorkingCopyManager();
|
// ITranslationUnit unit = fManager.getWorkingCopy(fEditor.getEditorInput());
|
||||||
ITranslationUnit unit = fManager.getWorkingCopy(fEditor.getEditorInput());
|
|
||||||
//TODO: Change to Project Scope
|
|
||||||
ICElement[] projectScopeElement = new ICElement[1];
|
|
||||||
projectScopeElement[0] = unit.getCProject();//(ICElement)currentScope.getCProject();
|
|
||||||
ICSearchScope scope = SearchEngine.createCSearchScope(projectScopeElement, true);
|
|
||||||
|
|
||||||
IFile resourceFile = fEditor.getInputFile();
|
IFile resourceFile = fEditor.getInputFile();
|
||||||
IParser parser = setupParser(resourceFile);
|
IParser parser = setupParser(resourceFile);
|
||||||
|
int selectionStart = selNode.selStart;
|
||||||
IASTNode node = null;
|
int selectionEnd = selNode.selEnd;
|
||||||
|
|
||||||
|
IParser.ISelectionParseResult result = null;
|
||||||
|
IASTOffsetableNamedElement node = null;
|
||||||
try{
|
try{
|
||||||
int selectionStart = selNode.selStart;
|
result = parser.parse(selectionStart,selectionEnd);
|
||||||
int selectionEnd = selNode.selEnd;
|
if( result != null )
|
||||||
node = parser.parse(selectionStart,selectionEnd);
|
node = result.getOffsetableNamedElement();
|
||||||
}
|
}
|
||||||
catch (ParseError er){}
|
catch (ParseError er){}
|
||||||
catch ( VirtualMachineError vmErr){
|
catch ( VirtualMachineError vmErr){
|
||||||
|
@ -191,42 +237,84 @@ public class OpenDeclarationsAction extends Action implements IUpdate {
|
||||||
if (node == null){
|
if (node == null){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SearchFor searchFor = getSearchForFromNode(node);
|
|
||||||
ICSearchPattern pattern = SearchEngine.createSearchPattern( selNode.selText,searchFor,ICSearchConstants.DECLARATIONS,true);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
|
||||||
searchEngine.search(CUIPlugin.getWorkspace(), pattern, scope, resultCollector, true);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
}
|
|
||||||
elementsFound.addAll(resultCollector.getSearchResults());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
storage.setFileName( result.getFilename() );
|
||||||
|
storage.setElement( node );
|
||||||
|
storage.setResource( ParserUtil.getResourceForFilename( result.getFilename() ) );
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ProgressMonitorDialog progressMonitor = new ProgressMonitorDialog(getShell());
|
ProgressMonitorDialog progressMonitor = new ProgressMonitorDialog(getShell());
|
||||||
progressMonitor.run(true, true, runnable);
|
progressMonitor.run(true, true, runnable);
|
||||||
|
|
||||||
if (elementsFound.isEmpty() == true) {
|
if( storage.getResource() != null )
|
||||||
//TODO: Get rid of back up search when selection search improves
|
{
|
||||||
//MessageDialog.openInformation(getShell(),CSearchMessages.getString("CSearchOperation.operationUnavailable.title"), CSearchMessages.getString("CSearchOperation.operationUnavailable.message")); //$NON-NLS-1$
|
open( storage.getResource(), storage.getNamedElement().getNameOffset(), storage.getNamedElement().getNameEndOffset() - storage.getNamedElement().getNameOffset() );
|
||||||
temporaryBackUpSearch();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
IMatch selected= selectCElement(elementsFound, getShell(), fDialogTitle, fDialogMessage);
|
{
|
||||||
if (selected != null) {
|
if( open( storage.getFileName(), storage.getNamedElement().getNameOffset(), storage.getNamedElement().getNameEndOffset() - storage.getNamedElement().getNameOffset()) );
|
||||||
open(selected);
|
return;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BasicSearchResultCollector resultCollector = new BasicSearchResultCollector(new NullProgressMonitor() );
|
||||||
|
//
|
||||||
|
// SearchFor searchFor = getSearchForFromNode(((IASTNode)storage.getNamedElement()));
|
||||||
|
// ICSearchPattern pattern = SearchEngine.createSearchPattern( selNode.selText,searchFor,ICSearchConstants.DECLARATIONS,true);
|
||||||
|
// IWorkingCopyManager fManager = CUIPlugin.getDefault().getWorkingCopyManager();
|
||||||
|
// //TODO: Change to Project Scope
|
||||||
|
// ICElement[] projectScopeElement = new ICElement[1];
|
||||||
|
// ITranslationUnit unit = fManager.getWorkingCopy(fEditor.getEditorInput());
|
||||||
|
// projectScopeElement[0] = unit.getCProject();//(ICElement)currentScope.getCProject();
|
||||||
|
// ICSearchScope scope = SearchEngine.createCSearchScope(projectScopeElement, true);
|
||||||
|
//
|
||||||
|
// try {
|
||||||
|
// searchEngine.search(CUIPlugin.getWorkspace(), pattern, scope, resultCollector, true);
|
||||||
|
// } catch (InterruptedException e) {
|
||||||
|
// }
|
||||||
|
// elementsFound.addAll(resultCollector.getSearchResults());
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// if (elementsFound.isEmpty() == true) {
|
||||||
|
// //TODO: Get rid of back up search when selection search improves
|
||||||
|
// //MessageDialog.openInformation(getShell(),CSearchMessages.getString("CSearchOperation.operationUnavailable.title"), CSearchMessages.getString("CSearchOperation.operationUnavailable.message")); //$NON-NLS-1$
|
||||||
|
// temporaryBackUpSearch();
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// IMatch selected= selectCElement(elementsFound, getShell(), fDialogTitle, fDialogMessage);
|
||||||
|
// if (selected != null) {
|
||||||
|
// open(selected);
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
} catch(Exception x) {
|
} catch(Exception x) {
|
||||||
CUIPlugin.getDefault().log(x);
|
CUIPlugin.getDefault().log(x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string
|
||||||
|
* @param i
|
||||||
|
*/
|
||||||
|
protected boolean open(String filename, int offset, int length) throws PartInitException, CModelException {
|
||||||
|
IPath path = new Path( filename );
|
||||||
|
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
|
||||||
|
if( file != null )
|
||||||
|
{
|
||||||
|
open( file, offset, length );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
FileStorage storage = new FileStorage(null, path);
|
||||||
|
IEditorPart part = EditorUtility.openInEditor(storage);
|
||||||
|
setSelectionAtOffset(part, offset, length);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
protected Shell getShell() {
|
protected Shell getShell() {
|
||||||
return fEditor.getSite().getShell();
|
return fEditor.getSite().getShell();
|
||||||
}
|
}
|
||||||
|
@ -293,11 +381,25 @@ public class OpenDeclarationsAction extends Action implements IUpdate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void open( IMatch element ) throws CModelException, PartInitException
|
||||||
|
{
|
||||||
|
open( element.getResource(), element.getStartOffset(), element.getEndOffset() - element.getStartOffset() );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens the editor on the given element and subsequently selects it.
|
* Opens the editor on the given element and subsequently selects it.
|
||||||
*/
|
*/
|
||||||
protected void open(IMatch element) throws CModelException, PartInitException {
|
protected void open( IResource resource, int offset, int length ) throws CModelException, PartInitException {
|
||||||
IEditorPart part= EditorUtility.openInEditor(element.getResource());
|
IEditorPart part= EditorUtility.openInEditor(resource);
|
||||||
|
setSelectionAtOffset(part, offset, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param part
|
||||||
|
* @param offset
|
||||||
|
* @param length TODO
|
||||||
|
*/
|
||||||
|
private void setSelectionAtOffset(IEditorPart part, int offset, int length) {
|
||||||
//int line = element.getStartOffset();
|
//int line = element.getStartOffset();
|
||||||
//if(line > 0) line--;
|
//if(line > 0) line--;
|
||||||
if(part instanceof CEditor) {
|
if(part instanceof CEditor) {
|
||||||
|
@ -308,11 +410,10 @@ public class OpenDeclarationsAction extends Action implements IUpdate {
|
||||||
//if(line > 3) {
|
//if(line > 3) {
|
||||||
// ed.selectAndReveal(document.getLineOffset(line - 3), 0);
|
// ed.selectAndReveal(document.getLineOffset(line - 3), 0);
|
||||||
//}
|
//}
|
||||||
ed.selectAndReveal(element.getStartOffset() /*document.getLineOffset(line)*/, 0);
|
ed.selectAndReveal(offset, length);
|
||||||
} catch (Exception e) {}
|
} catch (Exception e) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows a dialog for resolving an ambigous C element.
|
* Shows a dialog for resolving an ambigous C element.
|
||||||
* Utility method that can be called by subclassers.
|
* Utility method that can be called by subclassers.
|
||||||
|
|
Loading…
Add table
Reference in a new issue