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

Fixes related to scalability with large array initializer, bug 253690.

This commit is contained in:
Markus Schorn 2008-11-06 13:59:19 +00:00
parent e6eda2a51d
commit bb8d3bd8a4
47 changed files with 604 additions and 408 deletions

View file

@ -54,7 +54,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
import org.eclipse.cdt.core.dom.parser.ISourceCodeParser;
import org.eclipse.cdt.core.dom.parser.c.ANSICParserExtensionConfiguration;
import org.eclipse.cdt.core.dom.parser.c.GCCParserExtensionConfiguration;
import org.eclipse.cdt.core.dom.parser.c.GCCScannerExtensionConfiguration;
@ -75,6 +74,7 @@ import org.eclipse.cdt.core.parser.tests.scanner.FileCodeReaderFactory;
import org.eclipse.cdt.core.testplugin.CTestPlugin;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
import org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser;
import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor;
import org.eclipse.cdt.internal.core.dom.parser.c.GNUCSourceParser;
import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser;
@ -116,17 +116,17 @@ public class AST2BaseTest extends BaseTestCase {
}
protected IASTTranslationUnit parse(String code, ParserLanguage lang, boolean useGNUExtensions,
boolean expectNoProblems, boolean parseComments) throws ParserException {
boolean expectNoProblems, boolean skipTrivialInitializers) throws ParserException {
IScanner scanner = createScanner(new CodeReader(code.toCharArray()), lang, ParserMode.COMPLETE_PARSE,
new ScannerInfo(), parseComments);
ISourceCodeParser parser2 = null;
new ScannerInfo());
AbstractGNUSourceCodeParser parser = null;
if (lang == ParserLanguage.CPP) {
ICPPParserExtensionConfiguration config = null;
if (useGNUExtensions)
config = new GPPParserExtensionConfiguration();
else
config = new ANSICPPParserExtensionConfiguration();
parser2 = new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG,config, null);
parser = new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG,config, null);
} else {
ICParserExtensionConfiguration config = null;
@ -135,12 +135,14 @@ public class AST2BaseTest extends BaseTestCase {
else
config = new ANSICParserExtensionConfiguration();
parser2 = new GNUCSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, config, null);
parser = new GNUCSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, config, null);
}
if (skipTrivialInitializers)
parser.setSkipTrivialExpressionsInAggregateInitializers(true);
IASTTranslationUnit tu = parser2.parse();
IASTTranslationUnit tu = parser.parse();
if (parser2.encounteredError() && expectNoProblems)
if (parser.encounteredError() && expectNoProblems)
throw new ParserException("FAILURE"); //$NON-NLS-1$
if (lang == ParserLanguage.C && expectNoProblems) {
@ -157,7 +159,7 @@ public class AST2BaseTest extends BaseTestCase {
}
public static IScanner createScanner(CodeReader codeReader, ParserLanguage lang, ParserMode mode,
IScannerInfo scannerInfo, boolean parseComments) {
IScannerInfo scannerInfo) {
IScannerExtensionConfiguration configuration = null;
if (lang == ParserLanguage.C)
configuration= GCCScannerExtensionConfiguration.getInstance();

View file

@ -83,7 +83,7 @@ public class AST2SelectionParseBaseTest extends FileBasePluginTest {
CodeReader codeReader = new CodeReader(code
.toCharArray());
ScannerInfo scannerInfo = new ScannerInfo();
IScanner scanner= AST2BaseTest.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo, false);
IScanner scanner= AST2BaseTest.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo);
ISourceCodeParser parser2 = null;
if( lang == ParserLanguage.CPP )

View file

@ -100,7 +100,7 @@ public class AST2SpecBaseTest extends AST2BaseTest {
private IASTTranslationUnit parse(CodeReader codeReader, ParserLanguage lang, boolean useGNUExtensions,
boolean expectNoProblems, boolean checkBindings, int expectedProblemBindings, String[] problems) throws ParserException {
ScannerInfo scannerInfo = new ScannerInfo();
IScanner scanner= AST2BaseTest.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo, false);
IScanner scanner= AST2BaseTest.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo);
ISourceCodeParser parser2 = null;
if( lang == ParserLanguage.CPP )

View file

@ -5500,4 +5500,35 @@ public class AST2Tests extends AST2BaseTest {
parseAndCheckBindings(code, lang);
}
}
// int a[]= {
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// };
public void testScalabilityOfLargeTrivialInitializer_Bug252970() throws Exception {
final StringBuffer[] input = getContents(3);
StringBuilder buf= new StringBuilder();
buf.append(input[0].toString());
final String line= input[1].toString();
for (int i = 0; i < 25000; i++) { // 250K values
buf.append(line);
}
buf.append(input[2].toString());
final String code= buf.toString();
long mem= memoryUsed();
for (ParserLanguage lang : ParserLanguage.values()) {
IASTTranslationUnit tu= parse(code, lang, false, true, true);
long diff= memoryUsed()-mem;
final int expected = 1024*10 + code.length()*2; // a copy of the buffer + some
assertTrue(String.valueOf(diff) + " expected < " + expected, diff < expected);
}
}
private long memoryUsed() {
System.gc();System.gc();System.gc();
final Runtime runtime = Runtime.getRuntime();
return runtime.totalMemory()-runtime.freeMemory();
}
}

View file

@ -55,7 +55,7 @@ public class ASTNodeSelectorTest extends AST2BaseTest {
fCode= getContents(1)[0].toString();
CodeReader codeReader = new CodeReader(fCode.toCharArray());
ScannerInfo scannerInfo = new ScannerInfo();
IScanner scanner= AST2BaseTest.createScanner(codeReader, ParserLanguage.CPP, ParserMode.COMPLETE_PARSE, scannerInfo, false);
IScanner scanner= AST2BaseTest.createScanner(codeReader, ParserLanguage.CPP, ParserMode.COMPLETE_PARSE, scannerInfo);
GNUCPPSourceParser parser= new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE, new NullLogService(), new GPPParserExtensionConfiguration());
fTu= parser.parse();
fSelector= fTu.getNodeSelector(null);

View file

@ -180,7 +180,7 @@ public class CompleteParser2Tests extends BaseTestCase {
.toCharArray());
ScannerInfo scannerInfo = new ScannerInfo();
ISourceCodeParser parser2 = null;
IScanner scanner= AST2BaseTest.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo, false);
IScanner scanner= AST2BaseTest.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo);
if (lang == ParserLanguage.CPP) {
ICPPParserExtensionConfiguration config = null;
if (gcc)

View file

@ -1355,7 +1355,7 @@ public class QuickParser2Tests extends TestCase {
CodeReader codeReader = new CodeReader( code.toCharArray() );
IScannerInfo scannerInfo = new ScannerInfo();
IScanner scanner= AST2BaseTest.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo, false);
IScanner scanner= AST2BaseTest.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo);
ISourceCodeParser parser2 = null;
if (lang == ParserLanguage.CPP) {
ICPPParserExtensionConfiguration config = null;

View file

@ -43,7 +43,7 @@ public class CompletionTestBase extends TestCase {
protected IASTCompletionNode getCompletionNode(String code, ParserLanguage lang, boolean useGNUExtensions) throws ParserException {
CodeReader codeReader = new CodeReader(code.toCharArray());
ScannerInfo scannerInfo = new ScannerInfo();
IScanner scanner= AST2BaseTest.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo, false);
IScanner scanner= AST2BaseTest.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo);
ISourceCodeParser parser = null;
if( lang == ParserLanguage.CPP )

View file

@ -95,7 +95,7 @@ public class ASTWriterTest extends RewriteBaseTest {
ParserLanguage language = getLanguage(testFile);
boolean useGNUExtensions = getGNUExtension(testFile);
IScanner scanner = AST2BaseTest.createScanner(codeReader, language, ParserMode.COMPLETE_PARSE, scannerInfo, true);
IScanner scanner = AST2BaseTest.createScanner(codeReader, language, ParserMode.COMPLETE_PARSE, scannerInfo);
ISourceCodeParser parser2 = null;
if( language == ParserLanguage.CPP ) {

View file

@ -1370,7 +1370,8 @@ public class IndexBugsTests extends BaseTestCase {
TestSourceReader.createFile(fCProject.getProject(), "f1/g/h/header.h", "#define ID three\n");
TestSourceReader.createFile(fCProject.getProject(), "f1/g/source.cpp", contents + "int CONCAT(one, ID);\n");
TestSourceReader.createFile(fCProject.getProject(), "f2/g/source.cpp", contents + "int CONCAT(two, ID);\n");
TestSourceReader.createFile(fCProject.getProject(), "f1/g/h/source.cpp", contents + "int CONCAT(three, ID);\n");
IFile f= TestSourceReader.createFile(fCProject.getProject(), "f1/g/h/source.cpp", contents + "int CONCAT(three, ID);\n");
waitUntilFileIsIndexed(f, 4000);
indexManager.reindex(fCProject);
waitForIndexer();
fIndex.acquireReadLock();

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX - Initial API and implementation
* Doug Schaefer (QNX) - Initial API and implementation
* Markus Schorn (Wind River Systems)
* IBM Corporation
*******************************************************************************/
@ -27,7 +27,8 @@ import org.eclipse.core.runtime.IAdaptable;
/**
* Models differences between languages. The interface is not supposed to be implemented directly.
* Rather than that clients may subclass {@link AbstractLanguage}.
* @author Doug Schaefer
*
* @noimplement This interface is not intended to be implemented by clients.
*/
public interface ILanguage extends IAdaptable {
@ -35,27 +36,35 @@ public interface ILanguage extends IAdaptable {
* Option for {@link #getASTTranslationUnit(CodeReader, IScannerInfo, ICodeReaderFactory, IIndex, int, IParserLogService)}
* Instructs the parser to skip function and method bodies.
*/
public final static int OPTION_SKIP_FUNCTION_BODIES= 1;
public final static int OPTION_SKIP_FUNCTION_BODIES= 0x1;
/**
* Option for {@link #getASTTranslationUnit(CodeReader, IScannerInfo, ICodeReaderFactory, IIndex, int, IParserLogService)}
* Instructs the parser to add comment nodes to the ast.
*/
public final static int OPTION_ADD_COMMENTS= 2;
public final static int OPTION_ADD_COMMENTS= 0x2;
/**
* Option for {@link #getASTTranslationUnit(CodeReader, IScannerInfo, ICodeReaderFactory, IIndex, int, IParserLogService)}
* Performance optimization, instructs the parser not to create image-locations.
* When using this option {@link IASTName#getImageLocation()} will always return <code>null</code>.
*/
public final static int OPTION_NO_IMAGE_LOCATIONS= 4;
public final static int OPTION_NO_IMAGE_LOCATIONS= 0x4;
/**
* Option for {@link #getASTTranslationUnit(CodeReader, IScannerInfo, ICodeReaderFactory, IIndex, int, IParserLogService)}
* Marks the ast as being based on a source-file rather than a header-file. This makes a difference
* when bindings from the AST are used for searching the index, e.g. for static variables.
*/
public final static int OPTION_IS_SOURCE_UNIT= 8;
public final static int OPTION_IS_SOURCE_UNIT= 0x8;
/**
* Option for {@link #getASTTranslationUnit(CodeReader, IScannerInfo, ICodeReaderFactory, IIndex, int, IParserLogService)}
* Instructs the parser not to create ast nodes for expressions within aggregate initializers
* when they do not contain names.
* @since 5.1
*/
public final static int OPTION_SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS= 0x10;
/**
* Return the language id for this language.

View file

@ -30,6 +30,8 @@ import org.eclipse.core.runtime.IProgressMonitor;
* If a <code>.c</code> file cannot be parsed, its structure remains unknown.
* Use <code>ICElement.isStructureKnown</code> to determine whether this is
* the case.
*
* @noimplement This interface is not intended to be implemented by clients.
*/
public interface ITranslationUnit extends ICElement, IParent, IOpenable, ISourceReference, ISourceManipulation {
@ -38,21 +40,21 @@ public interface ITranslationUnit extends ICElement, IParent, IOpenable, ISource
* Meaning: Skip function and method bodies.
* @since 4.0
*/
public static final int AST_SKIP_FUNCTION_BODIES= 1;
public static final int AST_SKIP_FUNCTION_BODIES= 0x1;
/**
* Style constant for {@link #getAST(IIndex, int)}.
* Meaning: Skip over headers that are found in the index, parse all others.
* Macro definitions and bindings are taken from index for skipped files.
*/
public static final int AST_SKIP_INDEXED_HEADERS = 2;
public static final int AST_SKIP_INDEXED_HEADERS = 0x2;
/**
* Style constant for {@link #getAST(IIndex, int)}.
* Meaning: Skip headers even if they are not found in the index.
* Makes practically only sense in combination with {@link #AST_SKIP_INDEXED_HEADERS}.
*/
public static final int AST_SKIP_NONINDEXED_HEADERS = 4;
public static final int AST_SKIP_NONINDEXED_HEADERS = 0x4;
/**
* Style constant for {@link #getAST(IIndex, int)}.
@ -66,14 +68,14 @@ public interface ITranslationUnit extends ICElement, IParent, IOpenable, ISource
* Style constant for {@link #getAST(IIndex, int)}.
* Meaning: Don't parse the file if there is no build information for it.
*/
public static final int AST_SKIP_IF_NO_BUILD_INFO = 8;
public static final int AST_SKIP_IF_NO_BUILD_INFO = 0x8;
/**
* Style constant for {@link #getAST(IIndex, int)}.
* Meaning: Add nodes for comments to the ast.
* @since 4.0
*/
public static final int AST_CREATE_COMMENT_NODES = 16;
public static final int AST_CREATE_COMMENT_NODES = 0x10;
/**
* Style constant for {@link #getAST(IIndex, int)}.
@ -82,7 +84,15 @@ public interface ITranslationUnit extends ICElement, IParent, IOpenable, ISource
* the flag is ignored.
* @since 4.0
*/
public static final int AST_CONFIGURE_USING_SOURCE_CONTEXT= 32;
public static final int AST_CONFIGURE_USING_SOURCE_CONTEXT= 0x20;
/**
* Style constant for {@link #getAST(IIndex, int)}.
* Instructs the parser not to create ast nodes for expressions within aggregate initializers
* when they do not contain names.
* @since 5.1
*/
public final static int AST_SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS= 0x40;
/**
* Creates and returns an include declaration in this translation unit

View file

@ -40,7 +40,8 @@ public class ASTCache {
/** Full parse mode (no PDOM) */
public static int PARSE_MODE_FULL= ITranslationUnit.AST_CONFIGURE_USING_SOURCE_CONTEXT;
/** Fast parse mode (use PDOM) */
public static int PARSE_MODE_FAST= ITranslationUnit.AST_SKIP_ALL_HEADERS | ITranslationUnit.AST_CONFIGURE_USING_SOURCE_CONTEXT;
public static int PARSE_MODE_FAST= ITranslationUnit.AST_SKIP_ALL_HEADERS | ITranslationUnit.AST_CONFIGURE_USING_SOURCE_CONTEXT
| ITranslationUnit.AST_SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS;
/**
* Do something with an AST.

View file

@ -135,7 +135,7 @@ public class CModelBuilder2 implements IContributedModelBuilder {
else {
parseFlags |= ITranslationUnit.AST_CONFIGURE_USING_SOURCE_CONTEXT;
}
parseFlags |= ITranslationUnit.AST_SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS;
final IASTTranslationUnit ast;
try {
ast= fTranslationUnit.getAST(index, parseFlags, fProgressMonitor);

View file

@ -822,6 +822,9 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
if ((style & AST_CREATE_COMMENT_NODES) != 0) {
options |= ILanguage.OPTION_ADD_COMMENTS;
}
if ((style & AST_SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS) != 0) {
options |= ILanguage.OPTION_SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS;
}
if (isSourceUnit()) {
options |= ILanguage.OPTION_IS_SOURCE_UNIT;
}

View file

@ -38,6 +38,7 @@ import org.eclipse.cdt.core.parser.KeywordSetKey;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.util.CharArrayIntMap;
import org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser;
import org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor;
import org.eclipse.cdt.internal.core.parser.token.KeywordSets;
import org.eclipse.cdt.internal.core.util.ICancelable;
@ -181,7 +182,13 @@ public abstract class AbstractCLikeLanguage extends AbstractLanguage implements
else
mode= ParserMode.COMPLETE_PARSE;
return createParser(scanner, mode, log, index);
ISourceCodeParser parser= createParser(scanner, mode, log, index);
if ((options & OPTION_SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS) != 0) {
if (parser instanceof AbstractGNUSourceCodeParser) {
((AbstractGNUSourceCodeParser) parser).setSkipTrivialExpressionsInAggregateInitializers(true);
}
}
return parser;
}

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Rational Software - Initial API and implementation
* John Camelon (IBM Rational Software) - Initial API and implementation
* Markus Schorn (Wind River Systems)
* Ed Swartz (Nokia)
* Mike Kucera (IBM) - bug #206952
@ -81,9 +81,51 @@ import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor;
import org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver;
/**
* @author jcamelon
* Base class for the c- and c++ parser.
*/
public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
protected static class FoundAggregateInitializer extends Exception {
public final IASTDeclarator fDeclarator;
public IASTDeclSpecifier fDeclSpec;
public FoundAggregateInitializer(IASTDeclarator d) {
fDeclarator= d;
}
}
protected static class FoundDeclaratorException extends Exception {
private static final long serialVersionUID = 0;
public IASTDeclSpecifier declSpec;
public IASTDeclarator declarator;
public IASTDeclSpecifier altSpec;
public IASTDeclarator altDeclarator;
public IToken currToken;
public FoundDeclaratorException(IASTDeclarator d, IToken t) {
this.declarator = d;
this.currToken =t;
}
}
protected static class NameChecker extends ASTVisitor {
private boolean fFound;
protected NameChecker() {
shouldVisitNames= true;
}
@Override
public int visit(IASTName name) {
fFound= true;
return PROCESS_ABORT;
}
public boolean containsName(IASTNode node) {
fFound= false;
node.accept(this);
return fFound;
}
}
protected NameChecker NAME_CHECKER= new NameChecker();
protected static final int DEFAULT_DESIGNATOR_LIST_SIZE = 4;
protected static int parseCount = 0;
@ -103,6 +145,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
protected final IBuiltinBindingsProvider builtinBindingsProvider;
protected boolean functionCallCanBeLValue= false;
protected boolean skipTrivialExpressionsInAggregateInitializers= false;
/**
* Marks the beginning of the current declaration. It is important to clear the mark whenever we
@ -141,6 +185,14 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
this.builtinBindingsProvider= builtinBindingsProvider;
}
/**
* Instructs the parser not to create ast nodes for expressions within aggregate initializers
* when they do not contain names.
*/
public void setSkipTrivialExpressionsInAggregateInitializers(boolean val) {
skipTrivialExpressionsInAggregateInitializers= val;
}
private AbstractParserLogService wrapLogService(IParserLogService logService) {
if (logService instanceof AbstractParserLogService) {
return (AbstractParserLogService) logService;
@ -1225,13 +1277,17 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
return compoundStatement();
}
protected abstract IASTDeclarator initDeclarator(DeclarationOptions option) throws EndOfFileException, BacktrackException;
protected abstract IASTDeclarator initDeclarator(DeclarationOptions option)
throws EndOfFileException, BacktrackException, FoundAggregateInitializer;
/**
* @param option the options with which to parse the declaration
* @throws FoundDeclaratorException encountered EOF while looking ahead
* @throws FoundAggregateInitializer found aggregate initializer, needs special treatment
* because of scalability.
*/
protected void lookAheadForDeclarator(final DeclarationOptions option) throws FoundDeclaratorException {
protected void lookAheadForDeclarator(final DeclarationOptions option)
throws FoundDeclaratorException, FoundAggregateInitializer {
IToken mark = null;
try {
mark = mark();
@ -1252,23 +1308,6 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
protected abstract boolean verifyLookaheadDeclarator(DeclarationOptions option, IASTDeclarator d, IToken nextToken);
public static class FoundDeclaratorException extends Exception {
private static final long serialVersionUID = 0;
public IASTDeclSpecifier declSpec;
public IASTDeclarator declarator;
public IASTDeclSpecifier altSpec;
public IASTDeclarator altDeclarator;
public IToken currToken;
public FoundDeclaratorException(IASTDeclarator d, IToken t) {
this.declarator = d;
this.currToken =t;
}
}
/**
* Parse an enumeration specifier, as according to the ANSI specs in C &
* C++. enumSpecifier: "enum" (name)? "{" (enumerator-list) "}"
@ -1439,7 +1478,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
protected abstract IASTCaseStatement createCaseStatement();
protected abstract IASTDeclaration declaration(DeclarationOptions option) throws BacktrackException, EndOfFileException;
protected abstract IASTDeclSpecifier declSpecifierSeq(DeclarationOptions option) throws BacktrackException, EndOfFileException, FoundDeclaratorException;
protected abstract IASTDeclSpecifier declSpecifierSeq(DeclarationOptions option) throws BacktrackException, EndOfFileException, FoundDeclaratorException, FoundAggregateInitializer;
protected IASTDeclaration[] problemDeclaration(int offset, BacktrackException bt, DeclarationOptions option) {
failParse();
@ -1523,7 +1562,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
protected IASTDeclaration functionStyleAsmDeclaration() throws BacktrackException, EndOfFileException {
final int offset= LA(1).getOffset();
IASTDeclSpecifier declSpec;
IASTDeclSpecifier declSpec= null;
IASTDeclarator dtor;
try {
declSpec = declSpecifierSeq(DeclarationOptions.FUNCTION_STYLE_ASM);
@ -1537,6 +1576,10 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
dtor= e.declarator;
}
backup( e.currToken );
} catch (FoundAggregateInitializer lie) {
if (declSpec == null)
declSpec= lie.fDeclSpec;
dtor= addInitializer(lie);
}
if (LT(1) != IToken.tLBRACE)
@ -1561,6 +1604,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
return funcDefinition;
}
protected abstract IASTDeclarator addInitializer(FoundAggregateInitializer lie) throws EndOfFileException;
protected IToken asmExpression(StringBuilder content) throws EndOfFileException, BacktrackException {
IToken t= consume(IToken.tLPAREN);
boolean needspace= false;

View file

@ -159,12 +159,12 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
if (LT(1) == IToken.tASSIGN) {
consume();
final List<IASTNode> empty= Collections.emptyList();
return cInitializerClause(empty);
return cInitializerClause(empty, false);
}
return null;
}
protected IASTInitializer cInitializerClause(List<IASTNode> designators)
protected IASTInitializer cInitializerClause(List<IASTNode> designators, boolean inAggregateInitializer)
throws EndOfFileException, BacktrackException {
IToken la = LA(1);
int startingOffset = la.getOffset();
@ -190,9 +190,11 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
if (LT(1) == IToken.tASSIGN)
consume();
IASTInitializer initializer = cInitializerClause(newDesignators);
IASTInitializer initializer = cInitializerClause(newDesignators, true);
if (newDesignators.isEmpty()) {
// depending on value of skipTrivialItemsInCompoundInitializers initializer may be null
if (initializer != null)
result.addInitializer(initializer);
} else {
ICASTDesignatedInitializer desigInitializer = createDesignatorInitializer();
@ -232,6 +234,10 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
// try this now instead
// assignmentExpression
IASTExpression assignmentExpression = assignmentExpression();
if (inAggregateInitializer && skipTrivialExpressionsInAggregateInitializers) {
if (!NAME_CHECKER.containsName(assignmentExpression))
return null;
}
IASTInitializerExpression result = createInitializerExpression();
result.setExpression(assignmentExpression);
((ASTNode) result).setOffsetAndLength(
@ -387,17 +393,27 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
final int firstOffset= LA(1).getOffset();
int endOffset= firstOffset;
boolean insertSemi= false;
boolean parseDtors= true;
IASTDeclSpecifier declSpec;
IASTDeclSpecifier declSpec= null;
IASTDeclarator dtor= null;
IToken markBeforDtor= null;
try {
declSpec = declSpecifierSeq(declOption);
switch(LTcatchEOF(1)) {
final int lt1= LTcatchEOF(1);
switch(lt1) {
case 0: // eof
case IToken.tSEMI:
case IToken.tEOC:
case IToken.tSEMI:
parseDtors= false;
insertSemi= lt1==0;
if (lt1 == IToken.tSEMI)
endOffset= consume().getEndOffset();
else
endOffset= calculateEndOffset(declSpec);
break;
default:
markBeforDtor= mark();
try {
@ -408,6 +424,13 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
backup(markBeforDtor);
}
}
} catch (FoundAggregateInitializer lie) {
if (declSpec == null)
declSpec= lie.fDeclSpec;
// scalability: don't keep references to tokens, initializer may be large
declarationMark= null;
markBeforDtor= null;
dtor= addInitializer(lie);
} catch (FoundDeclaratorException e) {
if (e.altSpec != null) {
declSpec= e.altSpec;
@ -428,14 +451,23 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
throw e;
}
IASTDeclarator[] declarators= {dtor};
IASTDeclarator[] declarators= IASTDeclarator.EMPTY_DECLARATOR_ARRAY;
if (parseDtors) {
declarators= new IASTDeclarator[]{dtor};
while (LTcatchEOF(1) == IToken.tCOMMA) {
consume();
declarators= (IASTDeclarator[]) ArrayUtil.append( IASTDeclarator.class, declarators, initDeclarator(declOption));
try {
dtor= initDeclarator(declOption);
} catch (FoundAggregateInitializer e) {
// scalability: don't keep references to tokens, initializer may be large
declarationMark= null;
markBeforDtor= null;
dtor= addInitializer(e);
}
declarators= (IASTDeclarator[]) ArrayUtil.append( IASTDeclarator.class, declarators, dtor);
}
declarators= (IASTDeclarator[]) ArrayUtil.removeNulls( IASTDeclarator.class, declarators );
boolean insertSemi= false;
final int lt1= LTcatchEOF(1);
switch (lt1) {
case IToken.tLBRACE:
@ -450,10 +482,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
default:
if (declOption != DeclarationOptions.LOCAL) {
insertSemi= true;
if (markBeforDtor == null || !isOnSameLine(calculateEndOffset(declSpec), markBeforDtor.getOffset())) {
if (markBeforDtor != null) {
if (markBeforDtor != null && !isOnSameLine(calculateEndOffset(declSpec), markBeforDtor.getOffset())) {
backup(markBeforDtor);
}
declarators= IASTDeclarator.EMPTY_DECLARATOR_ARRAY;
endOffset= calculateEndOffset(declSpec);
break;
@ -468,6 +498,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
}
throwBacktrack(LA(1));
}
}
// no function body
IASTSimpleDeclaration simpleDeclaration = createSimpleDeclaration();
@ -657,7 +688,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
consume(IToken.tRPAREN).getEndOffset();
if (LT(1) == IToken.tLBRACE) {
final List<IASTNode> emptyList = Collections.emptyList();
IASTInitializer i = cInitializerClause(emptyList);
IASTInitializer i = cInitializerClause(emptyList, false);
firstExpression = buildTypeIdInitializerExpression(t, i, offset, calculateEndOffset(i));
break;
}
@ -896,6 +927,9 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
declSpecifier= e.declSpec;
declarator= e.declarator;
backup(e.currToken);
} catch (FoundAggregateInitializer lie) {
// type-ids have not compound initializers
return null;
}
} catch (BacktrackException bt) {
return null;
@ -982,7 +1016,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
@Override
protected IASTDeclSpecifier declSpecifierSeq(final DeclarationOptions declOption)
throws BacktrackException, EndOfFileException, FoundDeclaratorException {
throws BacktrackException, EndOfFileException, FoundDeclaratorException, FoundAggregateInitializer {
final int offset= LA(1).getOffset();
int endOffset= offset;
@ -1141,6 +1175,9 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
if (endOffset != offset || declOption.fAllowEmptySpecifier) {
lookAheadForDeclarator(declOption);
}
} catch (FoundAggregateInitializer e) {
e.fDeclSpec= createSimpleDeclSpec(storageClass, simpleType, options, isLong, typeofExpression, offset, endOffset);
throw e;
} catch (FoundDeclaratorException e) {
e.declSpec= createSimpleDeclSpec(storageClass, simpleType, options, isLong, typeofExpression, offset, endOffset);
@ -1152,6 +1189,9 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
e.altDeclarator= altDtor;
e.altSpec= createNamedTypeSpecifier(idToken, storageClass, options, offset, idToken.getEndOffset());
}
} catch (FoundAggregateInitializer lie) {
lie.fDeclSpec= e.declSpec;
throw lie;
} catch (BacktrackException bt) {
} finally {
backup(mark);
@ -1485,9 +1525,13 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
}
@Override
protected IASTDeclarator initDeclarator(final DeclarationOptions option) throws EndOfFileException, BacktrackException {
protected IASTDeclarator initDeclarator(final DeclarationOptions option)
throws EndOfFileException, BacktrackException, FoundAggregateInitializer {
IASTDeclarator d = declarator(option);
if (LT(1) == IToken.tASSIGN && LT(2) == IToken.tLBRACE)
throw new FoundAggregateInitializer(d);
IASTInitializer i = optionalCInitializer();
if (i != null) {
d.setInitializer(i);
@ -1496,6 +1540,21 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
return d;
}
@Override
protected IASTDeclarator addInitializer(FoundAggregateInitializer e) throws EndOfFileException {
final IASTDeclarator d = e.fDeclarator;
try {
IASTInitializer i = optionalCInitializer();
if (i != null) {
d.setInitializer(i);
((ASTNode) d).setLength(calculateEndOffset(i) - ((ASTNode) d).getOffset());
}
} catch (BacktrackException e1) {
// mstodo add problem node
}
return d;
}
protected IASTDeclarator declarator(DeclarationOptions option) throws EndOfFileException, BacktrackException {
final int startingOffset = LA(1).getOffset();
int endOffset = startingOffset;
@ -1968,6 +2027,10 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
altDeclSpec= fd.altSpec;
altDeclarator= fd.altDeclarator;
backup(fd.currToken);
} catch (FoundAggregateInitializer lie) {
if (declSpec == null)
declSpec= lie.fDeclSpec;
declarator= addInitializer(lie);
} finally {
fPreventKnrCheck--;
}

View file

@ -874,6 +874,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
declSpecifier= e.declSpec;
declarator= e.declarator;
backup(e.currToken);
} catch (FoundAggregateInitializer lie) {
// type-ids have no initializers
return null;
} catch (BacktrackException bt) {
return null;
}
@ -2245,24 +2248,33 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
final int firstOffset= LA(1).getOffset();
int endOffset= firstOffset;
boolean insertSemi= false;
boolean parseDtors= true;
ICPPASTDeclSpecifier declSpec;
ICPPASTDeclSpecifier declSpec= null;
IASTDeclarator dtor= null;
IToken markBeforDtor= null;
try {
declSpec = declSpecifierSeq(declOption);
switch(LTcatchEOF(1)) {
final int lt1= LTcatchEOF(1);
switch(lt1) {
case 0: // eof
case IToken.tEOC:
case IToken.tSEMI:
if (!validWithoutDtor(declOption, declSpec)) {
if (lt1 != IToken.tEOC && !validWithoutDtor(declOption, declSpec))
throwBacktrack(LA(1));
}
parseDtors= false;
insertSemi= lt1==0;
if (lt1 == IToken.tSEMI)
endOffset= consume().getEndOffset();
else
endOffset= calculateEndOffset(declSpec);
break;
case IToken.tCOMMA:
throwBacktrack(LA(1));
break;
case IToken.tEOC:
break;
default:
markBeforDtor= mark();
try {
@ -2278,6 +2290,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
}
break;
}
} catch (FoundAggregateInitializer lie) {
if (declSpec == null)
declSpec= (ICPPASTDeclSpecifier) lie.fDeclSpec;
// scalability: don't keep references to tokens, initializer may be large
declarationMark= null;
markBeforDtor= null;
dtor= addInitializer(lie);
} catch (FoundDeclaratorException e) {
declSpec= (ICPPASTDeclSpecifier) e.declSpec;
dtor= e.declarator;
@ -2293,15 +2312,23 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
throw e;
}
IASTDeclarator[] declarators= {dtor};
IASTDeclarator[] declarators= IASTDeclarator.EMPTY_DECLARATOR_ARRAY;
if (parseDtors) {
declarators= new IASTDeclarator[]{dtor};
while (LTcatchEOF(1) == IToken.tCOMMA) {
consume();
declarators= (IASTDeclarator[]) ArrayUtil.append( IASTDeclarator.class, declarators, initDeclarator(declSpec, declOption));
try {
dtor= initDeclarator(declSpec, declOption);
} catch (FoundAggregateInitializer e) {
// scalability: don't keep references to tokens, initializer may be large
declarationMark= null;
markBeforDtor= null;
dtor= addInitializer(e);
}
declarators = (IASTDeclarator[]) ArrayUtil.append(IASTDeclarator.class, declarators, dtor);
}
declarators = (IASTDeclarator[]) ArrayUtil.removeNulls(IASTDeclarator.class, declarators);
boolean insertSemi= false;
final int lt1= LTcatchEOF(1);
switch (lt1) {
case IToken.tEOC:
@ -2318,11 +2345,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
if (declOption != DeclarationOptions.LOCAL) {
insertSemi= true;
if (validWithoutDtor(declOption, declSpec)) {
// class definition without semicolon
if (markBeforDtor == null || !isOnSameLine(calculateEndOffset(declSpec), markBeforDtor.getOffset())) {
if (markBeforDtor != null) {
if (markBeforDtor != null && !isOnSameLine(calculateEndOffset(declSpec), markBeforDtor.getOffset())) {
backup(markBeforDtor);
}
declarators= IASTDeclarator.EMPTY_DECLARATOR_ARRAY;
endOffset= calculateEndOffset(declSpec);
break;
@ -2330,7 +2354,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
}
endOffset= figureEndOffset(declSpec, declarators);
if (lt1 == 0 || !isOnSameLine(endOffset, LA(1).getOffset())) {
insertSemi= true;
break;
}
if (declarators.length == 1 && declarators[0] instanceof IASTFunctionDeclarator) {
@ -2339,6 +2362,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
}
throwBacktrack(LA(1));
}
}
// no function body
IASTSimpleDeclaration simpleDeclaration= createSimpleDeclaration();
@ -2515,7 +2539,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
skipBrackets(IToken.tLBRACKET, IToken.tRBRACKET);
}
IASTDeclSpecifier declSpec;
IASTDeclSpecifier declSpec= null;
IASTDeclarator declarator;
try {
declSpec= declSpecifierSeq(DeclarationOptions.PARAMETER);
@ -2524,6 +2548,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
declSpec= e.declSpec;
declarator= e.declarator;
backup(e.currToken);
} catch (FoundAggregateInitializer lie) {
if (declSpec == null)
declSpec= lie.fDeclSpec;
declarator= addInitializer(lie);
}
final ICPPASTParameterDeclaration parm = createParameterDeclaration();
@ -2558,10 +2586,11 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
* ("typename")? name |
* { "class" | "struct" | "union" } classSpecifier |
* {"enum"} enumSpecifier
* @throws FoundAggregateInitializer
*/
@Override
protected ICPPASTDeclSpecifier declSpecifierSeq(final DeclarationOptions option)
throws BacktrackException, EndOfFileException, FoundDeclaratorException {
throws BacktrackException, EndOfFileException, FoundDeclaratorException, FoundAggregateInitializer {
int storageClass = IASTDeclSpecifier.sc_unspecified;
int simpleType = IASTSimpleDeclSpecifier.t_unspecified;
int options= 0;
@ -2748,6 +2777,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
if (option.fAllowEmptySpecifier && LT(1) != IToken.tCOMPLETION) {
lookAheadForDeclarator(option);
}
} catch (FoundAggregateInitializer e) {
e.fDeclSpec= createSimpleDeclSpec(storageClass, simpleType, options, isLong, typeofExpression, offset, endOffset);
throw e;
}catch (FoundDeclaratorException e) {
if (e.currToken.getType() == IToken.tEOC || option == DeclarationOptions.FUNCTION_STYLE_ASM
|| canBeConstructorDestructorOrConversion(option, storageClass, options, e.declarator)) {
@ -3046,12 +3078,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
}
@Override
protected IASTDeclarator initDeclarator(DeclarationOptions option) throws EndOfFileException, BacktrackException {
protected IASTDeclarator initDeclarator(DeclarationOptions option)
throws EndOfFileException, BacktrackException, FoundAggregateInitializer {
// called from the lookahead, only.
return initDeclarator(DtorStrategy.PREFER_FUNCTION, option);
}
protected IASTDeclarator initDeclarator(IASTDeclSpecifier declspec, DeclarationOptions option) throws EndOfFileException, BacktrackException {
protected IASTDeclarator initDeclarator(IASTDeclSpecifier declspec, DeclarationOptions option)
throws EndOfFileException, BacktrackException, FoundAggregateInitializer {
final IToken mark= mark();
IASTDeclarator dtor1= null;
IToken end1= null;
@ -3144,11 +3178,15 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
* @return declarator that this parsing produced.
* @throws BacktrackException
* request a backtrack
* @throws FoundAggregateInitializer
*/
protected IASTDeclarator initDeclarator(DtorStrategy strategy, DeclarationOptions option)
throws EndOfFileException, BacktrackException {
throws EndOfFileException, BacktrackException, FoundAggregateInitializer {
final IASTDeclarator dtor= declarator(strategy, option);
if (option.fAllowInitializer) {
if (LT(1) == IToken.tASSIGN && LT(2) == IToken.tLBRACE)
throw new FoundAggregateInitializer(dtor);
IASTInitializer initializer= optionalCPPInitializer(dtor);
if (initializer != null) {
dtor.setInitializer(initializer);
@ -3158,6 +3196,21 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
return dtor;
}
@Override
protected IASTDeclarator addInitializer(FoundAggregateInitializer e) throws EndOfFileException {
final IASTDeclarator d = e.fDeclarator;
try {
IASTInitializer i = optionalCPPInitializer(e.fDeclarator);
if (i != null) {
d.setInitializer(i);
((ASTNode) d).setLength(calculateEndOffset(i) - ((ASTNode) d).getOffset());
}
} catch (BacktrackException e1) {
// mstodo add problem node
}
return d;
}
protected IASTInitializer optionalCPPInitializer(IASTDeclarator d)
throws EndOfFileException, BacktrackException {
// handle initializer
@ -3165,7 +3218,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
if (LT(1) == IToken.tASSIGN) {
consume();
try {
return initializerClause();
return initializerClause(false);
} catch (EndOfFileException eof) {
failParse();
throw eof;
@ -3200,7 +3253,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
}
protected IASTInitializer initializerClause() throws EndOfFileException, BacktrackException {
protected IASTInitializer initializerClause(boolean inAggregateInitializer) throws EndOfFileException, BacktrackException {
if (LT(1) == IToken.tLBRACE) {
int startingOffset = consume().getOffset();
@ -3219,7 +3272,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
if (LT(1) == IToken.tRBRACE)
break;
IASTInitializer clause = initializerClause();
IASTInitializer clause = initializerClause(true);
if (clause != null) {
result.addInitializer(clause);
}
@ -3236,6 +3289,11 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
// try this now instead
// assignmentExpression
IASTExpression assignmentExpression = assignmentExpression();
if (inAggregateInitializer && skipTrivialExpressionsInAggregateInitializers) {
if (!NAME_CHECKER.containsName(assignmentExpression))
return null;
}
IASTInitializerExpression result = createInitializerExpression();
((ASTNode) result).setOffsetAndLength(((ASTNode) assignmentExpression));
result.setExpression(assignmentExpression);
@ -3975,7 +4033,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
private IASTSimpleDeclaration simpleSingleDeclaration(DeclarationOptions options) throws BacktrackException, EndOfFileException {
final int startOffset= LA(1).getOffset();
IASTDeclSpecifier declSpec;
IASTDeclSpecifier declSpec= null;
IASTDeclarator declarator;
try {
@ -3985,6 +4043,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
declSpec= e.declSpec;
declarator= e.declarator;
backup(e.currToken);
} catch (FoundAggregateInitializer lie) {
if (declSpec == null)
declSpec= lie.fDeclSpec;
declarator= addInitializer(lie);
}
final int endOffset = figureEndOffset(declSpec, declarator);

View file

@ -219,7 +219,8 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
}
fTodoTaskUpdater= createTodoTaskUpdater();
fASTOptions= ILanguage.OPTION_ADD_COMMENTS | ILanguage.OPTION_NO_IMAGE_LOCATIONS;
fASTOptions= ILanguage.OPTION_ADD_COMMENTS | ILanguage.OPTION_NO_IMAGE_LOCATIONS
| ILanguage.OPTION_SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS;
if (getSkipReferences() == SKIP_ALL_REFERENCES) {
fASTOptions |= ILanguage.OPTION_SKIP_FUNCTION_BODIES;
}

View file

@ -17,10 +17,7 @@ import junit.framework.Test;
import org.eclipse.core.resources.IFile;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.model.ICProject;
@ -63,8 +60,7 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest {
String content = readTaggedComment("testFunctions");
IFile file= createFile(getProject(), filename, content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor = openEditor(file);
editor.selectAndReveal(content.indexOf("proto"), 5);
openCallHierarchy(editor);
@ -108,8 +104,7 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest {
String content = readTaggedComment("testVariables");
IFile file= createFile(getProject(), filename, content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor = openEditor(file);
editor.selectAndReveal(content.indexOf("extern_var"), 0);
openCallHierarchy(editor);
@ -164,8 +159,7 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest {
String content = readTaggedComment(contentTag);
IFile file= createFile(getProject(), filename, content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor = openEditor(file);
editor.selectAndReveal(content.indexOf("enumerator"), 0);
openCallHierarchy(editor);
@ -220,8 +214,7 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest {
String content = readTaggedComment("testStructMembers");
IFile file= createFile(getProject(), "struct_member.c", content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor = openEditor(file);
editor.selectAndReveal(content.indexOf("mem1"), 0);
openCallHierarchy(editor);
@ -267,8 +260,7 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest {
String content = readTaggedComment("testStructMembers");
IFile file= createFile(getProject(), "struct_member.cpp", content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor = openEditor(file);
editor.selectAndReveal(content.indexOf("mem1"), 0);
openCallHierarchy(editor);
@ -314,8 +306,7 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest {
String content = readTaggedComment("testStructMembers");
IFile file= createFile(getProject(), "anon_struct_member.c", content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor = openEditor(file);
editor.selectAndReveal(content.indexOf("mem3"), 0);
openCallHierarchy(editor);
@ -343,8 +334,7 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest {
String content = readTaggedComment("testStructMembers");
IFile file= createFile(getProject(), "anon_struct_member.cpp", content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor = openEditor(file);
editor.selectAndReveal(content.indexOf("mem3"), 0);
openCallHierarchy(editor);
@ -406,8 +396,7 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest {
String content = readTaggedComment("testUnionMembers");
IFile file= createFile(getProject(), "union_member.c", content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor = openEditor(file);
editor.selectAndReveal(content.indexOf("mem1"), 0);
openCallHierarchy(editor);
@ -453,8 +442,7 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest {
String content = readTaggedComment("testUnionMembers");
IFile file= createFile(getProject(), "union_member.cpp", content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor = openEditor(file);
editor.selectAndReveal(content.indexOf("mem1"), 0);
openCallHierarchy(editor);
@ -500,8 +488,7 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest {
String content = readTaggedComment("testUnionMembers");
IFile file= createFile(getProject(), "anon_union_member.c", content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor = openEditor(file);
editor.selectAndReveal(content.indexOf("mem3"), 0);
openCallHierarchy(editor);
@ -529,8 +516,7 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest {
String content = readTaggedComment("testUnionMembers");
IFile file= createFile(getProject(), "anon_union_member.cpp", content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor = openEditor(file);
editor.selectAndReveal(content.indexOf("mem3"), 0);
openCallHierarchy(editor);
@ -575,11 +561,9 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest {
TreeItem i1, i2, i3, i4, i5, i6;
Tree tree;
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor;
CEditor editor= openEditor(file1);
// first file with definition of gf()
editor= (CEditor) IDE.openEditor(page, file1);
editor.selectAndReveal(content1.indexOf("sf"), 0);
openCallHierarchy(editor);
tree = getCHTreeViewer().getTree();
@ -611,7 +595,7 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest {
checkTreeNode(i6, 0, null);
// second file without definition of gf()
editor= (CEditor) IDE.openEditor(page, file2);
editor = openEditor(file2);
editor.selectAndReveal(content1.indexOf("sf"), 0);
openCallHierarchy(editor);
tree = getCHTreeViewer().getTree();
@ -646,11 +630,10 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest {
TreeItem i0, i1, i2, i3, i4, i5, i6;
Tree tree;
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor;
// first file with definition of gf()
editor= (CEditor) IDE.openEditor(page, file1);
editor= openEditor(file1);
editor.selectAndReveal(content1.indexOf("sf"), 0);
openCallHierarchy(editor);
tree = getCHTreeViewer().getTree();
@ -682,7 +665,7 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest {
checkTreeNode(i6, 0, null);
// second file without definition of gf()
editor= (CEditor) IDE.openEditor(page, file2);
editor= openEditor(file2);
editor.selectAndReveal(content1.indexOf("sf"), 0);
openCallHierarchy(editor);
tree = getCHTreeViewer().getTree();
@ -719,8 +702,7 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest {
String content = readTaggedComment("testFunctionsWithParams");
IFile file= createFile(getProject(), filename, content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor = openEditor(file);
editor.selectAndReveal(content.indexOf("proto"), 5);
openCallHierarchy(editor);

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -8,16 +8,12 @@
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.ui.tests.callhierarchy;
import junit.framework.Test;
import org.eclipse.core.resources.IFile;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
import org.eclipse.cdt.internal.ui.editor.CEditor;
@ -56,8 +52,7 @@ public class BasicCppCallHierarchyTest extends CallHierarchyBaseTest {
String content = readTaggedComment("testMethods");
IFile file= createFile(getProject(), "testMethods.cpp", content);
waitForIndexer(fIndex, file, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor = openEditor(file);
editor.selectAndReveal(content.indexOf("method"), 2);
openCallHierarchy(editor);
@ -140,8 +135,7 @@ public class BasicCppCallHierarchyTest extends CallHierarchyBaseTest {
String content = readTaggedComment("testStaticMethods");
IFile file= createFile(getProject(), "testStaticMethods.cpp", content);
waitForIndexer(fIndex, file, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor = openEditor(file);
editor.selectAndReveal(content.indexOf("method"), 2);
openCallHierarchy(editor);
@ -229,8 +223,7 @@ public class BasicCppCallHierarchyTest extends CallHierarchyBaseTest {
String content = readTaggedComment("testFields");
IFile file= createFile(getProject(), "testFields.cpp", content);
waitForIndexer(fIndex, file, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor = openEditor(file);
editor.selectAndReveal(content.indexOf("field"), 2);
openCallHierarchy(editor);
@ -304,8 +297,7 @@ public class BasicCppCallHierarchyTest extends CallHierarchyBaseTest {
String content = readTaggedComment("testAutomaticConstructor");
IFile file= createFile(getProject(), "testConstructor.cpp", content);
waitForIndexer(fIndex, file, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor = openEditor(file);
editor.selectAndReveal(content.indexOf("MyClass()"), 2);
openCallHierarchy(editor);
@ -334,8 +326,7 @@ public class BasicCppCallHierarchyTest extends CallHierarchyBaseTest {
String content = readTaggedComment("testConstructor");
IFile file= createFile(getProject(), "testConstructor.cpp", content);
waitForIndexer(fIndex, file, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor = openEditor(file);
editor.selectAndReveal(content.indexOf("MyClass()"), 2);
openCallHierarchy(editor);
@ -348,8 +339,7 @@ public class BasicCppCallHierarchyTest extends CallHierarchyBaseTest {
String content = readTaggedComment("testConstructor");
IFile file= createFile(getProject(), "testConstructor.cpp", content);
waitForIndexer(fIndex, file, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor = openEditor(file);
editor.selectAndReveal(content.indexOf("~MyClass()"), 2);
openCallHierarchy(editor);
@ -384,8 +374,7 @@ public class BasicCppCallHierarchyTest extends CallHierarchyBaseTest {
String content = readTaggedComment("testNamespace");
IFile file= createFile(getProject(), "testNamespace.cpp", content);
waitForIndexer(fIndex, file, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor = openEditor(file);
editor.selectAndReveal(content.indexOf("var"), 2);
openCallHierarchy(editor);
@ -442,8 +431,7 @@ public class BasicCppCallHierarchyTest extends CallHierarchyBaseTest {
String content = readTaggedComment("testNamespace");
IFile file= createFile(getProject(), "testNamespace.cpp", content);
waitForIndexer(fIndex, file, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor = openEditor(file);
editor.selectAndReveal(content.indexOf("var; // r1"), 2);
openCallHierarchy(editor);

View file

@ -18,7 +18,6 @@ import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMManager;
@ -41,6 +40,7 @@ public class CallHierarchyAcrossProjectsTest extends CallHierarchyBaseTest {
return suite(CallHierarchyAcrossProjectsTest.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
@ -51,6 +51,7 @@ public class CallHierarchyAcrossProjectsTest extends CallHierarchyBaseTest {
TestScannerProvider.sIncludes= new String[]{fCProject.getProject().getLocation().toOSString(), fCProject2.getProject().getLocation().toOSString()};
}
@Override
protected void tearDown() throws Exception {
if (fCProject2 != null) {
CProjectHelper.delete(fCProject2);
@ -89,7 +90,7 @@ public class CallHierarchyAcrossProjectsTest extends CallHierarchyBaseTest {
IFile sourceFile= createFile(fCProject2.getProject(), "testMethods.cpp", source);
waitForIndexer(fIndex, sourceFile, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, sourceFile);
CEditor editor= openEditor(sourceFile);
editor.selectAndReveal(source.indexOf("method"), 2);
@ -162,7 +163,7 @@ public class CallHierarchyAcrossProjectsTest extends CallHierarchyBaseTest {
IFile sourceFile1= createFile(fCProject.getProject(), "testMethods1.cpp", source1);
IFile sourceFile2= createFile(fCProject2.getProject(), "testMethods2.cpp", source2);
CEditor editor= openFile(sourceFile1);
CEditor editor= openEditor(sourceFile1);
waitForIndexer(fIndex, sourceFile2, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
editor.selectAndReveal(source1.indexOf("method3"), 2);
@ -212,7 +213,7 @@ public class CallHierarchyAcrossProjectsTest extends CallHierarchyBaseTest {
IFile sourceFile1= createFile(fCProject2.getProject(), "testMethods1.cpp", source1);
IFile sourceFile2= createFile(getProject(), "testMethods2.cpp", source2);
CEditor editor= openFile(sourceFile1);
CEditor editor= openEditor(sourceFile1);
waitForIndexer(fIndex, sourceFile1, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
waitForIndexer(fIndex, sourceFile2, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
@ -273,7 +274,7 @@ public class CallHierarchyAcrossProjectsTest extends CallHierarchyBaseTest {
IFile sourceFile1= createFile(getProject(), "testMethods1.cpp", source1);
IFile sourceFile2= createFile(getProject(), "testMethods2.cpp", source2);
CEditor editor= openFile(sourceFile2);
CEditor editor= openEditor(sourceFile2);
waitForIndexer(fIndex, sourceFile2, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
editor.selectAndReveal(source2.indexOf("main"), 2);

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
* Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -8,7 +8,6 @@
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.ui.tests.callhierarchy;
import org.eclipse.core.resources.IFile;
@ -30,6 +29,7 @@ import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.tests.BaseUITestCase;
import org.eclipse.cdt.ui.tests.text.EditorTestHelper;
import org.eclipse.cdt.internal.ui.callhierarchy.CHViewPart;
import org.eclipse.cdt.internal.ui.callhierarchy.CallHierarchyUI;
@ -46,6 +46,7 @@ public class CallHierarchyBaseTest extends BaseUITestCase {
super(name);
}
@Override
protected void setUp() throws Exception {
super.setUp();
CallHierarchyUI.setIsJUnitTest(true);
@ -61,6 +62,7 @@ public class CallHierarchyBaseTest extends BaseUITestCase {
}
}
@Override
protected void tearDown() throws Exception {
closeAllEditors();
if (fCProject != null) {
@ -73,9 +75,10 @@ public class CallHierarchyBaseTest extends BaseUITestCase {
return fCProject.getProject();
}
protected CEditor openFile(IFile file) throws PartInitException {
protected CEditor openEditor(IFile file) throws PartInitException {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
EditorTestHelper.joinReconciler(EditorTestHelper.getSourceViewer(editor), 100, 500, 10);
return editor;
}

View file

@ -15,14 +15,9 @@ import junit.framework.Test;
import org.eclipse.core.resources.IFile;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.WorkbenchException;
import org.eclipse.ui.ide.IDE;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.ui.CUIPlugin;
@ -145,13 +140,6 @@ public class CallHierarchyBugs extends CallHierarchyBaseTest {
CallHierarchyUI.open(workbenchWindow, (ICElement) obj);
}
private CEditor openEditor(IFile file) throws WorkbenchException {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart editor= IDE.openEditor(page, file, true);
runEventQueue(0);
return (CEditor) editor;
}
// class Base {
// public:
// virtual void vmethod();
@ -345,26 +333,46 @@ public class CallHierarchyBugs extends CallHierarchyBaseTest {
// CALL(0);
// }
public void testMacrosHidingCall_249801() throws Exception {
long t= System.currentTimeMillis();
String content= getContentsForTest(1)[0].toString();
t= printTime("contents", t);
IFile file= createFile(getProject(), "file249801.cpp", content);
t= printTime("file", t);
waitForIndexer(fIndex, file, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
t= printTime("indexer", t);
final CHViewPart ch= (CHViewPart) activateView(CUIPlugin.ID_CALL_HIERARCHY);
final IWorkbenchWindow workbenchWindow = ch.getSite().getWorkbenchWindow();
t= printTime("view", t);
// open editor, check outline
CEditor editor= openEditor(file);
t= printTime("editor", t);
int idx = content.indexOf("MACRO(Test");
editor.selectAndReveal(idx, 0);
openCallHierarchy(editor, false);
t= printTime("ch1", t);
Tree chTree= checkTreeNode(ch, 0, "PREFIX_Test(char *, char *)").getParent();
TreeItem ti= checkTreeNode(chTree, 0, 0, "call(int)");
t= printTime("checked", t);
idx = content.indexOf("CALL(0");
editor.selectAndReveal(idx+4, 0);
openCallHierarchy(editor, true);
t= printTime("ch2",t );
chTree= checkTreeNode(ch, 0, "call(int)").getParent();
ti= checkTreeNode(chTree, 0, 0, "PREFIX_Test(char *, char *)");
t= printTime("checked", t);
}
/**
* mstodo
* @param string
* @return
*/
private long printTime(String string, long off) {
long t= System.currentTimeMillis();
System.out.println(string + (t-off));
return t;
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
* Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -8,7 +8,6 @@
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.ui.tests.callhierarchy;
import junit.framework.Test;
@ -19,7 +18,6 @@ import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
import org.eclipse.cdt.core.CCorePlugin;
@ -64,10 +62,9 @@ public class CppCallHierarchyTest extends CallHierarchyBaseTest {
String source = content[1].toString();
IFile headerFile= createFile(getProject(), "testMethods.h", header);
IFile sourceFile= createFile(getProject(), "testMethods.cpp", source);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
waitForIndexer(fIndex, sourceFile, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
CEditor editor= (CEditor) IDE.openEditor(page, sourceFile);
CEditor editor= openEditor(sourceFile);
editor.selectAndReveal(source.indexOf("method"), 2);
openCallHierarchy(editor);
Tree tree = getCHTreeViewer().getTree();
@ -138,7 +135,7 @@ public class CppCallHierarchyTest extends CallHierarchyBaseTest {
IFile sourceFile1= createFile(getProject(), "testMethods1.cpp", source1);
IFile sourceFile2= createFile(getProject(), "testMethods2.cpp", source2);
CEditor editor= openFile(sourceFile1);
CEditor editor= openEditor(sourceFile1);
waitForIndexer(fIndex, sourceFile2, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
editor.selectAndReveal(source1.indexOf("method3"), 2);
@ -190,7 +187,7 @@ public class CppCallHierarchyTest extends CallHierarchyBaseTest {
waitForIndexer(fIndex, sourceFile2, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
CEditor editor= openFile(sourceFile1);
CEditor editor= openEditor(sourceFile1);
editor.selectAndReveal(source1.indexOf("method3"), 2);
openCallHierarchy(editor);
TreeViewer tv = getCHTreeViewer();
@ -248,7 +245,7 @@ public class CppCallHierarchyTest extends CallHierarchyBaseTest {
IFile sourceFile1= createFile(getProject(), "testMethods1.cpp", source1);
IFile sourceFile2= createFile(getProject(), "testMethods2.cpp", source2);
CEditor editor= openFile(sourceFile2);
CEditor editor= openEditor(sourceFile2);
waitForIndexer(fIndex, sourceFile2, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
editor.selectAndReveal(source2.indexOf("main"), 2);
@ -302,8 +299,7 @@ public class CppCallHierarchyTest extends CallHierarchyBaseTest {
String cppSource = content[1].toString();
IFile cFile= createFile(getProject(), "s.c", cSource);
IFile cppFile= createFile(getProject(), "s.cpp", cppSource);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, cFile);
CEditor editor= openEditor(cFile);
waitForIndexer(fIndex, cppFile, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
CCorePlugin.getIndexManager().joinIndexer(INDEXER_WAIT_TIME, NPM);
@ -320,7 +316,7 @@ public class CppCallHierarchyTest extends CallHierarchyBaseTest {
checkTreeNode(node, 1, null);
editor= (CEditor) IDE.openEditor(page, cppFile);
editor= openEditor(cppFile);
editor.selectAndReveal(cppSource.indexOf("cppfunc"), 2);
openCallHierarchy(editor, false);
tree = getCHTreeViewer().getTree();
@ -349,7 +345,7 @@ public class CppCallHierarchyTest extends CallHierarchyBaseTest {
IFile cFile= createFile(getProject(), "s.c", cSource);
IFile cppFile= createFile(getProject(), "s.cpp", cppSource);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, cFile);
CEditor editor= openEditor(cFile);
waitForIndexer(fIndex, cppFile, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
CCorePlugin.getIndexManager().joinIndexer(INDEXER_WAIT_TIME, NPM);
@ -366,7 +362,7 @@ public class CppCallHierarchyTest extends CallHierarchyBaseTest {
checkTreeNode(node, 1, null);
editor= (CEditor) IDE.openEditor(page, cppFile);
editor= openEditor(cppFile);
editor.selectAndReveal(cppSource.indexOf("cppfunc"), 2);
openCallHierarchy(editor, true);
tree = getCHTreeViewer().getTree();

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -8,7 +8,6 @@
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.ui.tests.callhierarchy;
import junit.framework.Test;
@ -35,7 +34,7 @@ public class InitializersInCallHierarchyTest extends CallHierarchyBaseTest {
String content = readTaggedComment("intvar");
IFile file= createFile(getProject(), "intvar.c", content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
CEditor editor = openFile(file);
CEditor editor = openEditor(file);
editor.selectAndReveal(content.indexOf("a"), 1);
openCallHierarchy(editor);

View file

@ -92,8 +92,10 @@ public class HyperlinkTest extends TestCase {
assertNotNull(file);
assertTrue(file.exists());
editor = (CEditor)EditorTestHelper.openInEditor(file, true);
EditorTestHelper.joinReconciler(EditorTestHelper.getSourceViewer(editor), 100, 500, 10);
}
@Override
protected void tearDown() throws Exception {
EditorTestHelper.closeEditor(editor);
CProjectHelper.delete(project);

View file

@ -36,6 +36,7 @@ import org.eclipse.search.ui.text.AbstractTextSearchResult;
import org.eclipse.search2.internal.ui.SearchView;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IViewReference;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
@ -46,17 +47,18 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ILanguage;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.testplugin.FileManager;
import org.eclipse.cdt.ui.tests.BaseUITestCase;
import org.eclipse.cdt.ui.tests.text.EditorTestHelper;
import org.eclipse.cdt.internal.core.model.ASTCache.ASTRunnable;
import org.eclipse.cdt.internal.core.parser.ParserException;
import org.eclipse.cdt.internal.ui.editor.ASTProvider;
import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.internal.ui.editor.ICEditorActionDefinitionIds;
import org.eclipse.cdt.internal.ui.search.actions.OpenDeclarationsAction;
@ -74,10 +76,17 @@ public class BaseSelectionTestsIndexer extends BaseUITestCase {
super(name);
}
@Override
protected void setUp() throws Exception {
super.setUp();
OpenDeclarationsAction.sIsJUnitTest= true;
OpenDeclarationsAction.sAllowFallback= false;
IWorkbenchPage page= PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewReference[] refs= page.getViewReferences();
for (int i = 0; i < refs.length; i++) {
IViewReference viewReference = refs[i];
page.setPartState(viewReference, IWorkbenchPage.STATE_RESTORED);
}
}
public void waitForIndex(int maxSec) throws Exception {
@ -192,34 +201,33 @@ public class BaseSelectionTestsIndexer extends BaseUITestCase {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart part = null;
try {
part = page.openEditor(new FileEditorInput(file), "org.eclipse.cdt.ui.editor.CEditor"); //$NON-NLS-1$
part = page.openEditor(new FileEditorInput(file), "org.eclipse.cdt.ui.editor.CEditor", true); //$NON-NLS-1$
} catch (PartInitException e) {
assertFalse(true);
}
if (part instanceof AbstractTextEditor) {
if (part instanceof CEditor) {
CEditor editor= (CEditor) part;
EditorTestHelper.joinReconciler(EditorTestHelper.getSourceViewer(editor), 100, 500, 10);
((AbstractTextEditor)part).getSelectionProvider().setSelection(new TextSelection(offset,length));
final OpenDeclarationsAction action = (OpenDeclarationsAction) ((AbstractTextEditor)part).getAction("OpenDeclarations"); //$NON-NLS-1$
final OpenDeclarationsAction action = (OpenDeclarationsAction) editor.getAction("OpenDeclarations"); //$NON-NLS-1$
action.runSync();
// update the file/part to point to the newly opened IFile/IEditorPart
part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
IEditorInput input = part.getEditorInput();
if (input instanceof FileEditorInput) {
file = ((FileEditorInput)input).getFile();
} else {
assertFalse(true); // bail!
}
assertTrue (part instanceof CEditor);
editor= (CEditor) part;
EditorTestHelper.joinReconciler(EditorTestHelper.getSourceViewer(editor), 100, 500, 10);
// the action above should highlight the declaration, so now retrieve it and use that selection to get the IASTName selected on the TU
ISelection sel = ((AbstractTextEditor)part).getSelectionProvider().getSelection();
ISelection sel= editor.getSelectionProvider().getSelection();
final IASTName[] result= {null};
if (sel instanceof ITextSelection) {
final ITextSelection textSel = (ITextSelection)sel;
ITranslationUnit tu = (ITranslationUnit)CoreModel.getDefault().create(file);
IStatus ok= ASTProvider.getASTProvider().runOnAST(tu, ASTProvider.WAIT_YES, monitor, new ASTRunnable() {
ITranslationUnit tu = (ITranslationUnit)editor.getInputCElement();
IStatus ok= ASTProvider.getASTProvider().runOnAST(tu, ASTProvider.WAIT_IF_OPEN, monitor, new ASTRunnable() {
public IStatus runOnAST(ILanguage language, IASTTranslationUnit ast) throws CoreException {
result[0]= ast.getNodeSelector(null).findName(textSel.getOffset(), textSel.getLength());
return Status.OK_STATUS;

View file

@ -56,6 +56,7 @@ import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.core.testplugin.FileManager;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.tests.BaseUITestCase;
import org.eclipse.cdt.ui.tests.text.EditorTestHelper;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.model.ASTCache.ASTRunnable;
@ -248,6 +249,7 @@ public class CPPSelectionTestsNoIndexer extends BaseUITestCase {
IEditorPart part = null;
try {
part = page.openEditor(new FileEditorInput(file), "org.eclipse.cdt.ui.editor.CEditor"); //$NON-NLS-1$
EditorTestHelper.joinReconciler(EditorTestHelper.getSourceViewer((AbstractTextEditor) part), 100, 500, 10);
} catch (PartInitException e) {
assertFalse(true);
}
@ -266,7 +268,7 @@ public class CPPSelectionTestsNoIndexer extends BaseUITestCase {
if (sel instanceof ITextSelection) {
final ITextSelection textSel = (ITextSelection)sel;
ITranslationUnit tu= CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editor.getEditorInput());
IStatus ok= ASTProvider.getASTProvider().runOnAST(tu, ASTProvider.WAIT_YES, monitor, new ASTRunnable() {
IStatus ok= ASTProvider.getASTProvider().runOnAST(tu, ASTProvider.WAIT_IF_OPEN, monitor, new ASTRunnable() {
public IStatus runOnAST(ILanguage language, IASTTranslationUnit ast) throws CoreException {
result[0]= ast.getNodeSelector(null).findName(textSel.getOffset(), textSel.getLength());
return Status.OK_STATUS;

View file

@ -44,19 +44,20 @@ import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ILanguage;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.core.testplugin.FileManager;
import org.eclipse.cdt.ui.tests.BaseUITestCase;
import org.eclipse.cdt.ui.tests.text.EditorTestHelper;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.model.ASTCache.ASTRunnable;
import org.eclipse.cdt.internal.core.parser.ParserException;
import org.eclipse.cdt.internal.ui.editor.ASTProvider;
import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.internal.ui.search.actions.OpenDeclarationsAction;
/**
@ -275,10 +276,12 @@ public class CSelectionTestsNoIndexer extends BaseUITestCase {
assertFalse(true);
}
if (part instanceof AbstractTextEditor) {
((AbstractTextEditor)part).getSelectionProvider().setSelection(new TextSelection(offset,length));
if (part instanceof CEditor) {
CEditor editor= (CEditor) part;
EditorTestHelper.joinReconciler(EditorTestHelper.getSourceViewer(editor), 100, 500, 10);
editor.getSelectionProvider().setSelection(new TextSelection(offset,length));
final OpenDeclarationsAction action = (OpenDeclarationsAction) ((AbstractTextEditor)part).getAction("OpenDeclarations"); //$NON-NLS-1$
final OpenDeclarationsAction action = (OpenDeclarationsAction) editor.getAction("OpenDeclarations"); //$NON-NLS-1$
action.runSync();
// the action above should highlight the declaration, so now retrieve it and use that selection to get the IASTName selected on the TU
@ -287,8 +290,8 @@ public class CSelectionTestsNoIndexer extends BaseUITestCase {
final IASTName[] result= {null};
if (sel instanceof ITextSelection) {
final ITextSelection textSel = (ITextSelection)sel;
ITranslationUnit tu = (ITranslationUnit)CoreModel.getDefault().create(file);
IStatus ok= ASTProvider.getASTProvider().runOnAST(tu, ASTProvider.WAIT_YES, monitor, new ASTRunnable() {
ITranslationUnit tu = (ITranslationUnit) editor.getInputCElement();
IStatus ok= ASTProvider.getASTProvider().runOnAST(tu, ASTProvider.WAIT_IF_OPEN, monitor, new ASTRunnable() {
public IStatus runOnAST(ILanguage language, IASTTranslationUnit ast) throws CoreException {
result[0]= ast.getNodeSelector(null).findName(textSel.getOffset(), textSel.getLength());
return Status.OK_STATUS;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007 Wind River Systems, Inc. and others.
* Copyright (c) 2007, 2008 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -8,7 +8,6 @@
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.ui.tests.typehierarchy;
import junit.framework.Test;
@ -16,9 +15,6 @@ import junit.framework.Test;
import org.eclipse.core.resources.IFile;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
import org.eclipse.cdt.internal.ui.editor.CEditor;
@ -41,8 +37,7 @@ public class CTypeHierarchyTest extends TypeHierarchyBaseTest {
String content= getContentsForTest(1)[0].toString();
IFile file= createFile(getProject(), "enum.c", content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor= openEditor(file);
Tree tree;
TreeItem item;
@ -78,8 +73,7 @@ public class CTypeHierarchyTest extends TypeHierarchyBaseTest {
String content= getContentsForTest(1)[0].toString();
IFile file= createFile(getProject(), "enummem.c", content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor= openEditor(file);
Tree tree;
TreeItem item;
@ -115,8 +109,7 @@ public class CTypeHierarchyTest extends TypeHierarchyBaseTest {
String content= getContentsForTest(1)[0].toString();
IFile file= createFile(getProject(), "enum.cpp", content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor= openEditor(file);
Tree tree;
TreeItem item;
@ -152,8 +145,7 @@ public class CTypeHierarchyTest extends TypeHierarchyBaseTest {
String content= getContentsForTest(1)[0].toString();
IFile file= createFile(getProject(), "enummem.cpp", content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor= openEditor(file);
Tree tree;
TreeItem item;
@ -197,8 +189,7 @@ public class CTypeHierarchyTest extends TypeHierarchyBaseTest {
String content= getContentsForTest(1)[0].toString();
IFile file= createFile(getProject(), "struct.c", content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor= openEditor(file);
editor.selectAndReveal(content.indexOf("S1"), 1);
openTypeHierarchy(editor);
@ -252,8 +243,7 @@ public class CTypeHierarchyTest extends TypeHierarchyBaseTest {
String content= getContentsForTest(1)[0].toString();
IFile file= createFile(getProject(), "structmem.c", content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor= openEditor(file);
editor.selectAndReveal(content.indexOf("a1"), 1);
openTypeHierarchy(editor);
@ -287,8 +277,7 @@ public class CTypeHierarchyTest extends TypeHierarchyBaseTest {
String content= getContentsForTest(1)[0].toString();
IFile file= createFile(getProject(), "struct.cpp", content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor= openEditor(file);
editor.selectAndReveal(content.indexOf("S1"), 1);
openTypeHierarchy(editor);
@ -343,8 +332,7 @@ public class CTypeHierarchyTest extends TypeHierarchyBaseTest {
String content= getContentsForTest(1)[0].toString();
IFile file= createFile(getProject(), "structmem.cpp", content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor= openEditor(file);
editor.selectAndReveal(content.indexOf("a1"), 1);
openTypeHierarchy(editor);
@ -378,8 +366,7 @@ public class CTypeHierarchyTest extends TypeHierarchyBaseTest {
String content= getContentsForTest(1)[0].toString();
IFile file= createFile(getProject(), "union.c", content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor= openEditor(file);
editor.selectAndReveal(content.indexOf("U1"), 1);
openTypeHierarchy(editor);
@ -429,8 +416,7 @@ public class CTypeHierarchyTest extends TypeHierarchyBaseTest {
String content= getContentsForTest(1)[0].toString();
IFile file= createFile(getProject(), "unionmem.c", content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor= openEditor(file);
editor.selectAndReveal(content.indexOf("a1"), 1);
openTypeHierarchy(editor);
@ -456,8 +442,7 @@ public class CTypeHierarchyTest extends TypeHierarchyBaseTest {
String content= getContentsForTest(1)[0].toString();
IFile file= createFile(getProject(), "union.cpp", content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor= openEditor(file);
editor.selectAndReveal(content.indexOf("U1"), 1);
openTypeHierarchy(editor);
@ -516,8 +501,7 @@ public class CTypeHierarchyTest extends TypeHierarchyBaseTest {
String content= getContentsForTest(1)[0].toString();
IFile file= createFile(getProject(), "unionmem.cpp", content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor= openEditor(file);
editor.selectAndReveal(content.indexOf("a1"), 1);
openTypeHierarchy(editor);

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007 Wind River Systems, Inc. and others.
* Copyright (c) 2007, 2008 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -8,7 +8,6 @@
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.ui.tests.typehierarchy;
import junit.framework.Test;
@ -16,9 +15,6 @@ import junit.framework.Test;
import org.eclipse.core.resources.IFile;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
import org.eclipse.cdt.internal.ui.editor.CEditor;
@ -57,8 +53,7 @@ public class CppTypeHierarchyTest extends TypeHierarchyBaseTest {
String content= getContentsForTest(1)[0].toString();
IFile file= createFile(getProject(), "class.cpp", content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor= openEditor(file);
Tree tree;
TreeItem item1, item2, item3, item4;
@ -151,8 +146,7 @@ public class CppTypeHierarchyTest extends TypeHierarchyBaseTest {
String content= getContentsForTest(1)[0].toString();
IFile file= createFile(getProject(), "classmem.cpp", content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor= openEditor(file);
Tree tree;
TreeItem item1, item2, item3, item4;
@ -245,8 +239,8 @@ public class CppTypeHierarchyTest extends TypeHierarchyBaseTest {
String content= getContentsForTest(1)[0].toString();
IFile file= createFile(getProject(), "multi.cpp", content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor= openEditor(file);
Tree tree;
TreeItem item1, item2, item3, item4;
@ -356,8 +350,8 @@ public class CppTypeHierarchyTest extends TypeHierarchyBaseTest {
String content= getContentsForTest(1)[0].toString();
IFile file= createFile(getProject(), "multimem.cpp", content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor= openEditor(file);
Tree tree;
TreeItem item1, item2, item3, item4;
@ -467,8 +461,8 @@ public class CppTypeHierarchyTest extends TypeHierarchyBaseTest {
String content= getContentsForTest(1)[0].toString();
IFile file= createFile(getProject(), "diamond.cpp", content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor= openEditor(file);
Tree tree;
TreeItem item1, item2, item3, item4;
@ -578,8 +572,8 @@ public class CppTypeHierarchyTest extends TypeHierarchyBaseTest {
String content= getContentsForTest(1)[0].toString();
IFile file= createFile(getProject(), "diamondmem.cpp", content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor= openEditor(file);
Tree tree;
TreeItem item1, item2, item3, item4;
@ -686,8 +680,8 @@ public class CppTypeHierarchyTest extends TypeHierarchyBaseTest {
String content= getContentsForTest(1)[0].toString();
IFile file= createFile(getProject(), "viaTypedef.cpp", content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor= openEditor(file);
Tree tree;
TreeItem item1, item2, item3, item4;
@ -777,8 +771,8 @@ public class CppTypeHierarchyTest extends TypeHierarchyBaseTest {
String content= getContentsForTest(1)[0].toString();
IFile file= createFile(getProject(), "viaTypedefmem.cpp", content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor= openEditor(file);
Tree tree;
TreeItem item1, item2, item3, item4;
@ -856,8 +850,8 @@ public class CppTypeHierarchyTest extends TypeHierarchyBaseTest {
String content= getContentsForTest(1)[0].toString();
IFile file= createFile(getProject(), "simpleTemplate.cpp", content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor= openEditor(file);
Tree tree;
TreeItem item1, item2, item3, item4;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007 Wind River Systems, Inc. and others.
* Copyright (c) 2007, 2008 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -8,7 +8,6 @@
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.ui.tests.typehierarchy;
import junit.framework.Test;
@ -17,9 +16,6 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.Platform;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
import org.eclipse.cdt.internal.ui.editor.CEditor;
@ -58,8 +54,8 @@ public class QuickTypeHierarchyTest extends TypeHierarchyBaseTest {
String content= getContentsForTest(1)[0].toString();
IFile file= createFile(getProject(), "class.cpp", content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor= openEditor(file);
Tree tree;
TreeItem item1, item2, item3, item4;
@ -154,8 +150,8 @@ public class QuickTypeHierarchyTest extends TypeHierarchyBaseTest {
String content= getContentsForTest(1)[0].toString();
IFile file= createFile(getProject(), "classmem.cpp", content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor= openEditor(file);
Tree tree;
TreeItem item1, item2, item3, item4;
@ -251,8 +247,8 @@ public class QuickTypeHierarchyTest extends TypeHierarchyBaseTest {
String content= getContentsForTest(1)[0].toString();
IFile file= createFile(getProject(), "multi.cpp", content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor= openEditor(file);
Tree tree;
TreeItem item1, item2, item3, item4;
@ -362,8 +358,8 @@ public class QuickTypeHierarchyTest extends TypeHierarchyBaseTest {
String content= getContentsForTest(1)[0].toString();
IFile file= createFile(getProject(), "multimem.cpp", content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor= openEditor(file);
Tree tree;
TreeItem item1, item2, item3, item4;
@ -473,8 +469,8 @@ public class QuickTypeHierarchyTest extends TypeHierarchyBaseTest {
String content= getContentsForTest(1)[0].toString();
IFile file= createFile(getProject(), "diamond.cpp", content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor= openEditor(file);
Tree tree;
TreeItem item1, item2, item3, item4;
@ -584,8 +580,8 @@ public class QuickTypeHierarchyTest extends TypeHierarchyBaseTest {
String content= getContentsForTest(1)[0].toString();
IFile file= createFile(getProject(), "diamondmem.cpp", content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor= openEditor(file);
Tree tree;
TreeItem item1, item2, item3, item4;
@ -689,8 +685,8 @@ public class QuickTypeHierarchyTest extends TypeHierarchyBaseTest {
String content= getContentsForTest(1)[0].toString();
IFile file= createFile(getProject(), "viaTypedef.cpp", content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor= openEditor(file);
Tree tree;
TreeItem item1, item2, item3, item4;
@ -783,8 +779,8 @@ public class QuickTypeHierarchyTest extends TypeHierarchyBaseTest {
String content= getContentsForTest(1)[0].toString();
IFile file= createFile(getProject(), "viaTypedefmem.cpp", content);
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
CEditor editor= openEditor(file);
Tree tree;
TreeItem item1, item2, item3, item4;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007 Wind River Systems, Inc. and others.
* Copyright (c) 2007, 2008 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -8,7 +8,6 @@
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.ui.tests.typehierarchy;
import junit.framework.Test;
@ -19,9 +18,6 @@ import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMManager;
@ -44,6 +40,7 @@ public class TypeHierarchyAcrossProjectsTest extends TypeHierarchyBaseTest {
return suite(TypeHierarchyAcrossProjectsTest.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
@ -57,6 +54,7 @@ public class TypeHierarchyAcrossProjectsTest extends TypeHierarchyBaseTest {
TestScannerProvider.sIncludes= new String[]{fCProject.getProject().getLocation().toOSString(), fCProject2.getProject().getLocation().toOSString()};
}
@Override
protected void tearDown() throws Exception {
if (fCProject2 != null) {
CProjectHelper.delete(fCProject2);
@ -92,10 +90,9 @@ public class TypeHierarchyAcrossProjectsTest extends TypeHierarchyBaseTest {
String source = content[1].toString();
IFile headerFile= createFile(fCProject.getProject(), "simpleHeader.h", header);
IFile sourceFile= createFile(fCProject2.getProject(), "simple.cpp", source);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
waitForIndexer(fIndex, sourceFile, TypeHierarchyBaseTest.INDEXER_WAIT_TIME);
CEditor editor= (CEditor) IDE.openEditor(page, sourceFile);
CEditor editor= openEditor(sourceFile);
Tree tree;
TreeItem item1, item2, item3, item4;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007 Wind River Systems, Inc. and others.
* Copyright (c) 2007, 2008 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -8,7 +8,6 @@
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.ui.tests.typehierarchy;
import org.eclipse.core.resources.IFile;
@ -37,6 +36,7 @@ import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.tests.BaseUITestCase;
import org.eclipse.cdt.ui.tests.text.EditorTestHelper;
import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.internal.ui.typehierarchy.THViewPart;
@ -52,6 +52,7 @@ public class TypeHierarchyBaseTest extends BaseUITestCase {
super(name);
}
@Override
protected void setUp() throws Exception {
super.setUp();
fCProject= CProjectHelper.createCCProject("__thTest__", "bin", IPDOMManager.ID_FAST_INDEXER);
@ -59,6 +60,7 @@ public class TypeHierarchyBaseTest extends BaseUITestCase {
fIndex= CCorePlugin.getIndexManager().getIndex(fCProject);
}
@Override
protected void tearDown() throws Exception {
closeAllEditors();
if (fCProject != null) {
@ -71,9 +73,10 @@ public class TypeHierarchyBaseTest extends BaseUITestCase {
return fCProject.getProject();
}
protected CEditor openFile(IFile file) throws PartInitException {
protected CEditor openEditor(IFile file) throws PartInitException {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
CEditor editor= (CEditor) IDE.openEditor(page, file);
EditorTestHelper.joinReconciler(EditorTestHelper.getSourceViewer(editor), 100, 500, 10);
return editor;
}

View file

@ -188,9 +188,11 @@ public class CreateParserLogAction implements IObjectActionDelegate {
}
private void createLog(final PrintStream out, final ITranslationUnit tu, IProgressMonitor pm) {
ASTProvider.getASTProvider().runOnAST(tu, ASTProvider.WAIT_YES, pm, new ASTCache.ASTRunnable() {
ASTProvider.getASTProvider().runOnAST(tu, ASTProvider.WAIT_IF_OPEN, pm, new ASTCache.ASTRunnable() {
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) throws CoreException {
if (ast != null)
return createLog(out, tu, lang, ast);
return Status.CANCEL_STATUS;
}
});
}

View file

@ -65,17 +65,19 @@ public final class ASTProvider {
/**
* Wait flag indicating that a client requesting an AST
* wants to wait until an AST is ready.
* wants to wait until an AST is ready. If the translation unit is not open no ast will
* be provided.
* <p>
* An AST will be created by this AST provider if the shared
* AST is not for the given C element.
* If not yet cached and if the translation unit is open, an AST will be created by
* this AST provider.
* </p>
*/
public static final WAIT_FLAG WAIT_YES= new WAIT_FLAG("wait yes"); //$NON-NLS-1$
public static final WAIT_FLAG WAIT_IF_OPEN= new WAIT_FLAG("wait if open"); //$NON-NLS-1$
/**
* Wait flag indicating that a client requesting an AST
* only wants to wait for the shared AST of the active editor.
* If the translation unit is not open no ast will be provided.
* <p>
* No AST will be created by the AST provider.
* </p>
@ -261,17 +263,6 @@ public final class ASTProvider {
}
}
/**
* Returns whether this AST provider is active on the given
* translation unit.
*
* @param tu the translation unit
* @return <code>true</code> if the given translation unit is the active one
*/
public boolean isActive(ITranslationUnit tu) {
return fCache.isActiveElement(tu) && tu.isOpen();
}
/**
* Informs that reconciling for the given element is about to be started.
*
@ -339,13 +330,17 @@ public final class ASTProvider {
public IStatus runOnAST(ICElement cElement, WAIT_FLAG waitFlag, IProgressMonitor monitor,
ASTCache.ASTRunnable astRunnable) {
Assert.isTrue(cElement instanceof ITranslationUnit);
boolean isActive= isActive((ITranslationUnit)cElement);
final ITranslationUnit tu = (ITranslationUnit)cElement;
if (!tu.isOpen())
return Status.CANCEL_STATUS;
final boolean isActive= fCache.isActiveElement(tu);
if (waitFlag == WAIT_ACTIVE_ONLY && !isActive) {
return Status.CANCEL_STATUS;
}
if (isActive && updateModificationStamp()) {
fCache.disposeAST();
}
return fCache.runOnAST((ITranslationUnit)cElement, waitFlag != WAIT_NO, monitor, astRunnable);
return fCache.runOnAST(tu, waitFlag != WAIT_NO, monitor, astRunnable);
}
}

View file

@ -68,7 +68,7 @@ public class CElementHyperlinkDetector extends AbstractHyperlinkDetector {
}
final IHyperlink[] result= {null};
IStatus status= ASTProvider.getASTProvider().runOnAST(workingCopy, ASTProvider.WAIT_YES, null, new ASTRunnable() {
IStatus status= ASTProvider.getASTProvider().runOnAST(workingCopy, ASTProvider.WAIT_ACTIVE_ONLY, null, new ASTRunnable() {
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) {
if (ast != null) {
final int offset= region.getOffset();

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
* Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -9,7 +9,6 @@
* Anton Leherbauer (Wind River Systems) - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.editor;
import java.util.ArrayList;
@ -108,7 +107,7 @@ public class InactiveCodeHighlighting implements ICReconcilingListener, ITextInp
IStatus result = Status.OK_STATUS;
if (fTranslationUnit != null) {
final ASTProvider astProvider= CUIPlugin.getDefault().getASTProvider();
result= astProvider.runOnAST(fTranslationUnit, ASTProvider.WAIT_YES, monitor, new ASTCache.ASTRunnable() {
result= astProvider.runOnAST(fTranslationUnit, ASTProvider.WAIT_IF_OPEN, monitor, new ASTCache.ASTRunnable() {
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) {
reconciled(ast, true, monitor);
return Status.OK_STATUS;

View file

@ -10,7 +10,6 @@
* Anton Leherbauer (Wind River Systems) - Adapted for CDT
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.editor;
import java.util.ArrayList;
@ -513,7 +512,7 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener {
final Job me= this;
ASTProvider astProvider= CUIPlugin.getDefault().getASTProvider();
IStatus status= astProvider.runOnAST(element, ASTProvider.WAIT_YES, monitor, new ASTCache.ASTRunnable() {
IStatus status= astProvider.runOnAST(element, ASTProvider.WAIT_IF_OPEN, monitor, new ASTCache.ASTRunnable() {
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) {
reconciled(ast, true, monitor);
synchronized (fJobLock) {

View file

@ -52,7 +52,7 @@ public class PDOMSearchTextSelectionQuery extends PDOMSearchQuery {
@Override
protected IStatus runWithIndex(final IIndex index, IProgressMonitor monitor) {
return ASTProvider.getASTProvider().runOnAST(tu, ASTProvider.WAIT_YES, monitor, new ASTRunnable() {
return ASTProvider.getASTProvider().runOnAST(tu, ASTProvider.WAIT_ACTIVE_ONLY, monitor, new ASTRunnable() {
public IStatus runOnAST(ILanguage language, IASTTranslationUnit ast) throws CoreException {
if (ast != null) {
IASTName searchName= ast.getNodeSelector(null).findEnclosingName(selection.getOffset(), selection.getLength());

View file

@ -61,7 +61,6 @@ import org.eclipse.cdt.core.model.ILanguage;
import org.eclipse.cdt.core.model.ISourceRange;
import org.eclipse.cdt.core.model.ISourceReference;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.core.model.util.CElementBaseLabels;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.ui.CUIPlugin;
@ -103,7 +102,7 @@ public class OpenDeclarationsAction extends SelectionParseAction implements ASTR
ITextSelection fTextSelection;
private String fSelectedText;
private IWorkingCopy fWorkingCopy;
private ITranslationUnit fWorkingCopy;
private IIndex fIndex;
private IProgressMonitor fMonitor;
@ -122,10 +121,11 @@ public class OpenDeclarationsAction extends SelectionParseAction implements ASTR
clearStatusLine();
fMonitor= monitor;
fWorkingCopy = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(fEditor.getEditorInput());
if (fWorkingCopy == null)
ICElement celem= fEditor.getInputCElement();
if (!(celem instanceof ITranslationUnit))
return Status.CANCEL_STATUS;
fWorkingCopy= (ITranslationUnit) celem;
fIndex= CCorePlugin.getIndexManager().getIndex(fWorkingCopy.getCProject(),
IIndexManager.ADD_DEPENDENCIES | IIndexManager.ADD_DEPENDENT);
@ -136,7 +136,7 @@ public class OpenDeclarationsAction extends SelectionParseAction implements ASTR
}
try {
return ASTProvider.getASTProvider().runOnAST(fWorkingCopy, ASTProvider.WAIT_YES, monitor, this);
return ASTProvider.getASTProvider().runOnAST(fWorkingCopy, ASTProvider.WAIT_ACTIVE_ONLY, monitor, this);
} finally {
fIndex.releaseReadLock();
}

View file

@ -9,7 +9,6 @@
* IBM Corporation - initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.text.correction;
import java.util.ArrayList;
@ -120,7 +119,7 @@ public class CorrectionCommandHandler extends AbstractHandler {
private ICompletionProposal getLocalRenameProposal(final IInvocationContext context) {
final ICCompletionProposal[] proposals= new ICCompletionProposal[1];
ASTProvider.getASTProvider().runOnAST(context.getTranslationUnit(), ASTProvider.WAIT_YES,
ASTProvider.getASTProvider().runOnAST(context.getTranslationUnit(), ASTProvider.WAIT_ACTIVE_ONLY,
new NullProgressMonitor(), new ASTRunnable() {
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit astRoot) throws CoreException {

View file

@ -170,7 +170,7 @@ public class QuickAssistLightBulbUpdater {
if (workingCopy != null) {
installSelectionListener();
final Point point= fViewer.getSelectedRange();
ASTProvider.getASTProvider().runOnAST(workingCopy, ASTProvider.WAIT_YES, null, new ASTRunnable() {
ASTProvider.getASTProvider().runOnAST(workingCopy, ASTProvider.WAIT_IF_OPEN, null, new ASTRunnable() {
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit astRoot) {
if (astRoot != null) {
doSelectionChanged(point.x, point.y, astRoot);

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2007 IBM Corporation and others.
* Copyright (c) 2000, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -14,17 +14,10 @@ package org.eclipse.cdt.internal.ui.text.correction.proposals;
import java.util.Arrays;
import java.util.Comparator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.viewers.StyledString;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocument;
@ -39,7 +32,12 @@ import org.eclipse.jface.text.link.LinkedPosition;
import org.eclipse.jface.text.link.LinkedPositionGroup;
import org.eclipse.jface.text.link.LinkedModeUI.ExitFlags;
import org.eclipse.jface.text.link.LinkedModeUI.IExitPolicy;
import org.eclipse.jface.viewers.StyledString;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.texteditor.link.EditorLinkedModeUI;
@ -136,10 +134,13 @@ public class LinkedNamesAssistProposal implements ICCompletionProposal, IComplet
final int secectionOffset = selection.x;
final int selectionLength = selection.y;
ASTProvider.getASTProvider().runOnAST(fTranslationUnit, ASTProvider.WAIT_YES,
ASTProvider.getASTProvider().runOnAST(fTranslationUnit, ASTProvider.WAIT_ACTIVE_ONLY,
new NullProgressMonitor(), new ASTRunnable() {
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit astRoot) throws CoreException {
if (astRoot == null)
return Status.CANCEL_STATUS;
IASTNodeSelector selector= astRoot.getNodeSelector(null);
IASTName name= selector.findEnclosingName(secectionOffset, selectionLength);
if (name != null) {
@ -249,7 +250,7 @@ public class LinkedNamesAssistProposal implements ICCompletionProposal, IComplet
public String getDisplayString() {
String shortCutString= CorrectionCommandHandler.getShortCutString(getCommandId());
if (shortCutString != null) {
return CorrectionMessages.bind(CorrectionMessages.ChangeCorrectionProposal_name_with_shortcut,
return NLS.bind(CorrectionMessages.ChangeCorrectionProposal_name_with_shortcut,
fLabel, shortCutString);
}
return fLabel;
@ -263,7 +264,7 @@ public class LinkedNamesAssistProposal implements ICCompletionProposal, IComplet
String shortCutString= CorrectionCommandHandler.getShortCutString(getCommandId());
if (shortCutString != null) {
String decorated= CorrectionMessages.bind(CorrectionMessages.ChangeCorrectionProposal_name_with_shortcut,
String decorated= NLS.bind(CorrectionMessages.ChangeCorrectionProposal_name_with_shortcut,
fLabel, shortCutString);
return ColoringLabelProvider.decorateStyledString(str, decorated, StyledString.QUALIFIER_STYLER);
}

View file

@ -393,7 +393,7 @@ public class IndexUI {
return null;
final IASTName[] result= {null};
ASTProvider.getASTProvider().runOnAST(workingCopy, ASTProvider.WAIT_YES, null, new ASTRunnable() {
ASTProvider.getASTProvider().runOnAST(workingCopy, ASTProvider.WAIT_ACTIVE_ONLY, null, new ASTRunnable() {
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) {
if (ast != null) {
final IASTNodeSelector nodeSelector = ast.getNodeSelector(null);