1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-03 14:25:37 +02:00

org.eclipse.cdt.core

Fixed Bug 50487 - Wrong completion kind and prefix after "#ifdef" 

org.eclipse.cdt.ui.tests
	Updated CompletionFailedTest_MacroRef_NoPrefix_Bug50487, renamed it to CompletionTest_MacroRef_NoPrefix and moved to passed test package.
	Updated CompletionFailedTest_MacroRef_Prefix_Bug50487, renamed it to Y and moved to passed test package.
This commit is contained in:
John Camelon 2004-01-30 18:28:07 +00:00
parent 9d0e717ea4
commit fbda3f7d9a
12 changed files with 186 additions and 46 deletions

View file

@ -1,3 +1,6 @@
2004-01-30 John Camelon
Fixed Bug 50487 - Wrong completion kind and prefix after "#ifdef"
2004-01-29 Hoda Amer
Removed CompletionKind.KEYWORD.

View file

@ -169,13 +169,36 @@ public class ContextualParser extends Parser implements IParser {
* @see org.eclipse.cdt.internal.core.parser.Parser#handleOffsetLimitException()
*/
protected void handleOffsetLimitException(OffsetLimitReachedException exception) throws OffsetLimitReachedException {
setCompletionToken( exception.getFinalToken() );
if( (finalToken!= null )&& (finalToken.isKeywordOrOperator() ))
setCompletionToken(null);
if( exception.getCompletionNode() == null )
{
setCompletionToken( exception.getFinalToken() );
if( (finalToken!= null )&& (finalToken.isKeywordOrOperator() ))
setCompletionToken(null);
}
else
{
ASTCompletionNode node = (ASTCompletionNode) exception.getCompletionNode();
setCompletionValues( node.getCompletionKind(), node.getKeywordSet(), node.getCompletionPrefix() );
}
throw exception;
}
/**
* @param compilationUnit
* @param kind2
* @param set
* @param object
* @param string
*/
private void setCompletionValues(CompletionKind kind, Set keywordSet, String prefix ) {
setCompletionScope(compilationUnit);
this.keywordSet = keywordSet;
setCompletionKind(kind);
setCompletionContext(null);
setCompletionToken( new Token( IToken.tIDENTIFIER, prefix ) );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.Parser#setCompletionKeywords(java.lang.String[])
*/
@ -217,8 +240,8 @@ public class ContextualParser extends Parser implements IParser {
CompletionKind kind,
Key key,
IASTNode node, String prefix) throws EndOfFileException {
setCompletionValues(scope, kind, key, node );
setCompletionToken( new Token( IToken.tIDENTIFIER, prefix ) );
setCompletionValues(scope, kind, key, node );
}
/* (non-Javadoc)
@ -256,7 +279,6 @@ public class ContextualParser extends Parser implements IParser {
else if( scope instanceof IASTClassSpecifier )
kind = CompletionKind.FIELD_TYPE;
else if (scope instanceof IASTCodeScope)
// kind = CompletionKind.STATEMENT_START;
kind = CompletionKind.SINGLE_NAME_REFERENCE;
else
kind = CompletionKind.VARIABLE_TYPE;

View file

@ -161,7 +161,6 @@ public abstract class Parser implements IParser
*/
protected void translationUnit()
{
IASTCompilationUnit compilationUnit;
try
{
compilationUnit = astFactory.createCompilationUnit();
@ -5275,6 +5274,7 @@ public abstract class Parser implements IParser
protected IToken currToken, // current token we plan to consume next
lastToken; // last token we consumed
private boolean limitReached = false;
protected IASTCompilationUnit compilationUnit;
/**
* Fetches a token from the scanner.

View file

@ -73,5 +73,11 @@ public class ASTCompletionNode implements IASTCompletionNode {
return new EmptyIterator();
return keywordSet.iterator();
}
public Set getKeywordSet()
{
return keywordSet;
}
}

View file

@ -33,8 +33,10 @@ import org.eclipse.cdt.internal.core.parser.scanner.IScannerContext.ContextKind;
public class ContextStack {
private final IParserLogService log;
private Scanner scanner;
public ContextStack( IParserLogService l ) {
public ContextStack( Scanner s, IParserLogService l ) {
scanner = s;
log = l;
}
@ -193,4 +195,9 @@ public class ContextStack {
{
return topContext.getLine();
}
public Scanner getScanner()
{
return scanner;
}
}

View file

@ -21,6 +21,7 @@ public class LimitedScannerContext
implements IScannerContext {
private final int limit;
private final Scanner scanner;
/**
* @param reader
@ -29,8 +30,9 @@ public class LimitedScannerContext
* @param object
* @param offsetLimit
*/
public LimitedScannerContext(Reader reader, String string, ContextKind kind, int offsetLimit) {
public LimitedScannerContext(Scanner scanner, Reader reader, String string, ContextKind kind, int offsetLimit) {
super( reader, string, kind, null );
this.scanner = scanner;
limit = offsetLimit;
}
@ -40,7 +42,11 @@ public class LimitedScannerContext
* @see org.eclipse.cdt.internal.core.parser.IScannerContext#read()
*/
public int read() throws IOException {
if( getOffset() == limit ) throw new IOException();
if( getOffset() == limit )
{
scanner.setOffsetLimitReached(true);
throw new IOException();
}
return super.read();
}

View file

@ -49,11 +49,14 @@ import org.eclipse.cdt.core.parser.ScannerException;
import org.eclipse.cdt.core.parser.ScannerInfo;
import org.eclipse.cdt.core.parser.IMacroDescriptor.MacroType;
import org.eclipse.cdt.core.parser.ast.ASTExpressionEvaluationException;
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
import org.eclipse.cdt.core.parser.ast.IASTFactory;
import org.eclipse.cdt.core.parser.ast.IASTInclusion;
import org.eclipse.cdt.core.parser.extension.IScannerExtension;
import org.eclipse.cdt.internal.core.parser.ast.ASTCompletionNode;
import org.eclipse.cdt.internal.core.parser.problem.IProblemFactory;
import org.eclipse.cdt.internal.core.parser.token.KeywordSets;
import org.eclipse.cdt.internal.core.parser.token.Token;
/**
@ -109,7 +112,7 @@ public class Scanner implements IScanner {
scannerExtension = extension;
scannerExtension.setScanner( this );
astFactory = ParserFactory.createASTFactory( mode, language );
contextStack = new ContextStack( log );
contextStack = new ContextStack( this, log );
try {
//this is a hack to get around a sudden EOF experience
contextStack.push(
@ -277,7 +280,7 @@ public class Scanner implements IScanner {
if( offsetLimit == NO_OFFSET_LIMIT )
context = new ScannerContext(reader, resolvedFilename, ScannerContext.ContextKind.TOP, null );
else
context = new LimitedScannerContext( reader, resolvedFilename, ScannerContext.ContextKind.TOP, offsetLimit );
context = new LimitedScannerContext( this, reader, resolvedFilename, ScannerContext.ContextKind.TOP, offsetLimit );
contextStack.push( context, requestor );
} catch( ContextException ce )
{
@ -633,6 +636,7 @@ public class Scanner implements IScanner {
}
private final ParserMode mode;
private static final IScannerInfo EMPTY_INFO = new ScannerInfo();
public int getCharacter() throws ScannerException
{
@ -1328,6 +1332,10 @@ public class Scanner implements IScanner {
// get the rest of the line
int currentOffset = getCurrentOffset();
String expression = getRestOfPreprocessorLine();
if( isLimitReached() )
handleCompletionOnExpression( expression );
if (expression.trim().equals(""))
handleProblem( IProblem.PREPROCESSOR_INVALID_DIRECTIVE, "#if", beginningOffset, false, true );
@ -1344,7 +1352,12 @@ public class Scanner implements IScanner {
case PreprocessorDirectives.IFDEF :
//TODO add in content assist stuff here
skipOverWhitespace();
if (getDefinition(getNextIdentifier()) == null) {
String definition = getNextIdentifier();
if( isLimitReached() )
handleCompletionOnDefinition( definition );
if (getDefinition(definition) == null) {
// not defined
passOnToClient = branches.poundIf( false );
skipOverTextUntilNewline();
@ -1369,7 +1382,12 @@ public class Scanner implements IScanner {
case PreprocessorDirectives.IFNDEF :
//TODO add in content assist stuff here
skipOverWhitespace();
if (getDefinition(getNextIdentifier()) != null) {
String definition2 = getNextIdentifier();
if( isLimitReached() )
handleCompletionOnDefinition( definition2 );
if (getDefinition(definition2) != null) {
// not defined
skipOverTextUntilNewline();
passOnToClient = branches.poundIf( false );
@ -1401,14 +1419,17 @@ public class Scanner implements IScanner {
case PreprocessorDirectives.ELIF :
//TODO add in content assist stuff here
int co = getCurrentOffset();
String elsifExpression = getRestOfPreprocessorLine().trim();
if (elsifExpression.equals(""))
String elifExpression = getRestOfPreprocessorLine();
if( isLimitReached() )
handleCompletionOnExpression( elifExpression );
if (elifExpression.equals(""))
handleProblem( IProblem.PREPROCESSOR_INVALID_DIRECTIVE, "#elif", beginningOffset, false, true );
boolean elsifResult = false;
if( branches.queryCurrentBranchForElif() )
elsifResult = evaluateExpression(elsifExpression, co );
elsifResult = evaluateExpression(elifExpression, co );
try
{
@ -1418,7 +1439,7 @@ public class Scanner implements IScanner {
{
StringBuffer buffer = new StringBuffer( token );
buffer.append( ' ' );
buffer.append( elsifExpression );
buffer.append( elifExpression );
handleProblem( IProblem.PREPROCESSOR_UNBALANCE_CONDITION,
buffer.toString(),
beginningOffset,
@ -1784,7 +1805,7 @@ public class Scanner implements IScanner {
continue;
}
throwEOF();
throwEOF(null);
}
}
@ -1795,13 +1816,57 @@ public class Scanner implements IScanner {
}
// we're done
throwEOF();
throwEOF(null);
return null;
}
/**
* @param definition
*/
private void handleCompletionOnDefinition(String definition) throws EndOfFileException {
IASTCompletionNode node = new ASTCompletionNode( IASTCompletionNode.CompletionKind.MACRO_REFERENCE,
null, null, definition, KeywordSets.getKeywords(KeywordSets.Key.MACRO, language) );
throwEOF( node );
}
/**
* @param expression2
*/
private void handleCompletionOnExpression(String expression) throws EndOfFileException {
int completionPoint = expression.length();
IScanner subScanner = ParserFactory.createScanner( new StringReader(expression), SCRATCH, EMPTY_INFO, ParserMode.QUICK_PARSE, language, new NullSourceElementRequestor(), new NullLogService());
IToken lastToken = null;
try
{
lastToken = subScanner.nextToken();
}
catch( EndOfFileException eof )
{
// ok
} catch (ScannerException e) {
handleInternalError();
}
String prefix = "";
if( ( lastToken != null ))
{
if( ( lastToken.getType() == IToken.tIDENTIFIER )
&& ( lastToken.getEndOffset() == completionPoint ) )
{
prefix = lastToken.getImage();
}
}
IASTCompletionNode node = new ASTCompletionNode( IASTCompletionNode.CompletionKind.MACRO_REFERENCE,
null, null, prefix, KeywordSets.getKeywords(KeywordSets.Key.MACRO, language) );
throwEOF( node );
}
/**
* @param key
*/
protected void removeSymbol(String key) {
@ -1961,7 +2026,7 @@ public class Scanner implements IScanner {
}
// we're done
throwEOF();
throwEOF(null);
return null;
}
@ -1969,13 +2034,17 @@ public class Scanner implements IScanner {
/**
*
*/
protected void throwEOF() throws EndOfFileException, OffsetLimitReachedException {
if( offsetLimit == NO_OFFSET_LIMIT )
throw new EndOfFileException();
if( finalToken.getEndOffset() == offsetLimit )
throw new OffsetLimitReachedException(finalToken);
throw new OffsetLimitReachedException( (IToken)null );
protected void throwEOF(IASTCompletionNode node) throws EndOfFileException, OffsetLimitReachedException {
if( node == null )
{
if( offsetLimit == NO_OFFSET_LIMIT )
throw new EndOfFileException();
if( finalToken.getEndOffset() == offsetLimit )
throw new OffsetLimitReachedException(finalToken);
throw new OffsetLimitReachedException( (IToken)null );
}
throw new OffsetLimitReachedException( node );
}
@ -2973,7 +3042,8 @@ public class Scanner implements IScanner {
private final ISourceElementRequestor requestor;
private IASTFactory astFactory = null;
private static final int NO_OFFSET_LIMIT = -1;
private int offsetLimit = NO_OFFSET_LIMIT;
private int offsetLimit = NO_OFFSET_LIMIT;
private boolean limitReached = false;
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IScanner#setASTFactory(org.eclipse.cdt.internal.core.parser.ast.IASTFactory)
@ -2996,4 +3066,17 @@ public class Scanner implements IScanner {
return definitions;
}
/**
* @param b
*/
public void setOffsetLimitReached(boolean b) {
limitReached = b;
}
protected boolean isLimitReached()
{
if( offsetLimit == NO_OFFSET_LIMIT ) return false;
return limitReached;
}
}

View file

@ -35,6 +35,7 @@ public class KeywordSets {
public static final Key POST_USING = new Key( 5 );
public static final Key FUNCTION_MODIFIER = new Key( 6 );
public static final Key NAMESPACE_ONLY = new Key(6);
public static final Key MACRO = new Key( 7 );
/**
* @param enumValue
*/
@ -62,6 +63,8 @@ public class KeywordSets {
return (Set) FUNCTION_MODIFIER.get( language );
if( kind == Key.NAMESPACE_ONLY )
return NAMESPACE_ONLY;
if( kind == Key.MACRO )
return MACRO_ONLY;
//TODO finish this
return null;
@ -76,6 +79,14 @@ public class KeywordSets {
NAMESPACE_ONLY.add(Keywords.NAMESPACE );
}
private static final Set MACRO_ONLY;
static
{
MACRO_ONLY = new HashSet();
MACRO_ONLY.add("defined()" );
}
private static final Set DECL_SPECIFIER_SEQUENCE_C;
static
{

View file

@ -1,3 +1,7 @@
2004-01-30 John Camelon
Updated CompletionFailedTest_MacroRef_NoPrefix_Bug50487, renamed it to CompletionTest_MacroRef_NoPrefix and moved to passed test package.
Updated CompletionFailedTest_MacroRef_Prefix_Bug50487, renamed it to Y and moved to passed test package.
2004-01-29 Hoda Amer
-Added CompletionTest_SingleName_Parameter test to success tests.
-Changed BaseTest to check if the expected values exist in the proposed values

View file

@ -71,8 +71,8 @@ public class AutomatedSuite extends TestSuite {
// Failed Tests
addTest(CompletionFailedTest_ScopedReference_NoPrefix_Bug50152.suite());
addTest(CompletionFailedTest_ScopedReference_Prefix_Bug50152.suite());
addTest(CompletionFailedTest_MacroRef_NoPrefix_Bug50487.suite());
addTest(CompletionFailedTest_MacroRef_Prefix_Bug50487.suite());
addTest(CompletionTest_MacroRef_NoPrefix.suite());
addTest(CompletionTest_MacroRef_Prefix.suite());
addTest(CompletionFailedTest_FunctionReference_Bug50807.suite());
addTest(CompletionFailedTest_ConstructorReference_Bug50808.suite());
}

View file

@ -8,12 +8,11 @@
* Contributors:
* IBM Rational Software - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.ui.tests.text.contentassist.failedtests;
package org.eclipse.cdt.ui.tests.text.contentassist;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind;
import org.eclipse.cdt.ui.tests.text.contentassist.CompletionProposalsBaseTest;
/**
* @author hamer
@ -22,7 +21,7 @@ import org.eclipse.cdt.ui.tests.text.contentassist.CompletionProposalsBaseTest;
* Bug#50487 :Wrong completion kind and prefix after "#ifdef"
*
*/
public class CompletionFailedTest_MacroRef_NoPrefix_Bug50487 extends CompletionProposalsBaseTest{
public class CompletionTest_MacroRef_NoPrefix extends CompletionProposalsBaseTest{
private final String fileName = "CompletionTestStart26.cpp";
private final String fileFullPath ="resources/contentassist/" + fileName;
@ -30,7 +29,7 @@ public class CompletionFailedTest_MacroRef_NoPrefix_Bug50487 extends Completion
private final String headerFileFullPath ="resources/contentassist/" + headerFileName;
private final String expectedScopeName = "ASTCompilationUnit";
private final String expectedContextName = "null";
private final CompletionKind expectedKind = CompletionKind.VARIABLE_TYPE; // should be CompletionKind.MACRO_REFERENCE;
private final CompletionKind expectedKind = CompletionKind.MACRO_REFERENCE;
private final String expectedPrefix = "";
private final String[] expectedResults = {
// Should be
@ -39,13 +38,13 @@ public class CompletionFailedTest_MacroRef_NoPrefix_Bug50487 extends Completion
// "xMacro(x,y)"
};
public CompletionFailedTest_MacroRef_NoPrefix_Bug50487(String name) {
public CompletionTest_MacroRef_NoPrefix(String name) {
super(name);
}
public static Test suite() {
TestSuite suite= new TestSuite(CompletionFailedTest_MacroRef_NoPrefix_Bug50487.class.getName());
suite.addTest(new CompletionFailedTest_MacroRef_NoPrefix_Bug50487("testCompletionProposals"));
TestSuite suite= new TestSuite(CompletionTest_MacroRef_NoPrefix.class.getName());
suite.addTest(new CompletionTest_MacroRef_NoPrefix("testCompletionProposals"));
return suite;
}

View file

@ -8,12 +8,11 @@
* Contributors:
* IBM Rational Software - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.ui.tests.text.contentassist.failedtests;
package org.eclipse.cdt.ui.tests.text.contentassist;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind;
import org.eclipse.cdt.ui.tests.text.contentassist.CompletionProposalsBaseTest;
/**
* @author hamer
@ -22,7 +21,7 @@ import org.eclipse.cdt.ui.tests.text.contentassist.CompletionProposalsBaseTest;
* Bug#50487 :Wrong completion kind and prefix after "#ifdef"
*
*/
public class CompletionFailedTest_MacroRef_Prefix_Bug50487 extends CompletionProposalsBaseTest{
public class CompletionTest_MacroRef_Prefix extends CompletionProposalsBaseTest{
private final String fileName = "CompletionTestStart27.cpp";
private final String fileFullPath ="resources/contentassist/" + fileName;
@ -30,20 +29,20 @@ public class CompletionFailedTest_MacroRef_Prefix_Bug50487 extends CompletionPr
private final String headerFileFullPath ="resources/contentassist/" + headerFileName;
private final String expectedScopeName = "ASTCompilationUnit";
private final String expectedContextName = "null";
private final CompletionKind expectedKind = CompletionKind.VARIABLE_TYPE; // should be CompletionKind.MACRO_REFERENCE;
private final String expectedPrefix = ""; // should be "D";
private final CompletionKind expectedKind = CompletionKind.MACRO_REFERENCE;
private final String expectedPrefix = "D";
private final String[] expectedResults = {
// Should be
// "Debug"
};
public CompletionFailedTest_MacroRef_Prefix_Bug50487(String name) {
public CompletionTest_MacroRef_Prefix(String name) {
super(name);
}
public static Test suite() {
TestSuite suite= new TestSuite(CompletionFailedTest_MacroRef_Prefix_Bug50487.class.getName());
suite.addTest(new CompletionFailedTest_MacroRef_Prefix_Bug50487("testCompletionProposals"));
TestSuite suite= new TestSuite(CompletionTest_MacroRef_Prefix.class.getName());
suite.addTest(new CompletionTest_MacroRef_Prefix("testCompletionProposals"));
return suite;
}