diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/pdomdepgen/PDOMDependencyCalculator.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/pdomdepgen/PDOMDependencyCalculator.java index 8d2a5dcbb09..26dadfca0e2 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/pdomdepgen/PDOMDependencyCalculator.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/pdomdepgen/PDOMDependencyCalculator.java @@ -1,5 +1,5 @@ /********************************************************************** - * Copyright (c) 2006 QNX Software Systems and others. + * Copyright (c) 2006, 2007 QNX Software Systems 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 @@ -7,6 +7,7 @@ * * Contributors: * QNX Software Systems - Initial API and implementation + * Anton Leherbauer (Wind River Systems) **********************************************************************/ package org.eclipse.cdt.managedbuilder.pdomdepgen; @@ -67,9 +68,11 @@ public class PDOMDependencyCalculator implements IManagedDependencyCalculator { IIndexInclude[] includes = index.findIncludes(file, IIndex.DEPTH_INFINITE); List/**/ list = new ArrayList/**/(); - for (int i = 0; i < includes.length; ++i) - list.add(IndexLocationFactory.getAbsolutePath(includes[i].getIncludesLocation())); - + for (int i = 0; i < includes.length; ++i) { + if (includes[i].isResolved()) { + list.add(IndexLocationFactory.getAbsolutePath(includes[i].getIncludesLocation())); + } + } dependencies = (IPath[])list.toArray(new IPath[list.size()]); } else dependencies = new IPath[0]; diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationTests.java index 490fb9dd2bf..5604285e85a 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationTests.java @@ -465,7 +465,6 @@ public class DOMLocationTests extends AST2BaseTest { public void testBug162180() throws Exception { StringBuffer buffer = new StringBuffer(); buffer.append( "#include \n"); //$NON-NLS-1$ - int declOffset= buffer.length(); buffer.append( "int x;\n"); //$NON-NLS-1$ String code = buffer.toString(); for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP @@ -474,7 +473,7 @@ public class DOMLocationTests extends AST2BaseTest { IASTDeclaration[] decls= tu.getDeclarations(); assertEquals( decls.length, 1 ); IASTPreprocessorStatement [] statements = tu.getAllPreprocessorStatements(); - assertEquals( statements.length, 0 ); + assertEquals( statements.length, 1 ); IASTProblem[] problems = tu.getPreprocessorProblems(); assertEquals( problems.length, 1 ); assertSoleLocation( decls[0], code, "int x;"); @@ -494,7 +493,6 @@ public class DOMLocationTests extends AST2BaseTest { buffer.append( "#include \n"); //$NON-NLS-1$ buffer.append( "#include \r\n"); //$NON-NLS-1$ buffer.append( "#include // more stuff \n"); //$NON-NLS-1$ - int declOffset= buffer.length(); buffer.append( "int x;\n"); //$NON-NLS-1$ String code = buffer.toString(); for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP @@ -504,12 +502,12 @@ public class DOMLocationTests extends AST2BaseTest { IASTPreprocessorStatement [] statements = tu.getAllPreprocessorStatements(); IASTProblem[] problems = tu.getPreprocessorProblems(); assertEquals( 1, decls.length); - assertEquals( 0, statements.length); + assertEquals( 3, statements.length); assertEquals( 3, problems.length); String snip= ""; - assertSoleLocation(problems[0], code, "#include "); - assertSoleLocation(problems[1], code, "#include "); - assertSoleLocation(problems[2], code, "#include // more stuff "); + assertSoleLocation(statements[0], code, "#include "); + assertSoleLocation(statements[1], code, "#include "); + assertSoleLocation(statements[2], code, "#include "); assertSoleLocation(decls[0], code, "int x;"); } } @@ -590,7 +588,7 @@ public class DOMLocationTests extends AST2BaseTest { IASTPreprocessorStatement [] statements = tu.getAllPreprocessorStatements(); IASTProblem[] problems = tu.getPreprocessorProblems(); assertEquals( 1, decls.length); - assertEquals( 0, statements.length); + assertEquals( 1, statements.length); assertEquals( 2, problems.length); assertSoleLocation(problems[0], code, "#include \"\""); assertSoleLocation(problems[1], code, "else"); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexIncludeTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexIncludeTest.java index 844ecc385e4..84180ef745e 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexIncludeTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexIncludeTest.java @@ -210,7 +210,62 @@ public class IndexIncludeTest extends IndexTestBase { TestScannerProvider.sIncludes= null; } } - + + public void testInactiveInclude() throws Exception { + TestScannerProvider.sIncludes= new String[]{fProject.getProject().getLocation().toOSString()}; + try { + String content = "#if 0\n#include \"inactive20070213.h\"\n#endif\n"; + IFile file= TestSourceReader.createFile(fProject.getProject(), "source20070213.cpp", content); + CCoreInternals.getPDOMManager().reindex(fProject); + waitForIndexer(); + + fIndex.acquireReadLock(); + try { + IIndexFile ifile= fIndex.getFile(IndexLocationFactory.getWorkspaceIFL(file)); + assertNotNull(ifile); + IIndexInclude[] includes= ifile.getIncludes(); + assertEquals(1, includes.length); + + assertFalse(includes[0].isActive()); + checkInclude(includes[0], content, "inactive20070213.h", false); + } + finally { + fIndex.releaseReadLock(); + } + } + finally { + TestScannerProvider.sIncludes= null; + } + } + + public void testUnresolvedInclude() throws Exception { + TestScannerProvider.sIncludes= new String[]{fProject.getProject().getLocation().toOSString()}; + try { + String content = "#include \"unresolved20070213.h\"\n"; + IFile file= TestSourceReader.createFile(fProject.getProject(), "source20070214.cpp", content); + CCoreInternals.getPDOMManager().reindex(fProject); + waitForIndexer(); + + fIndex.acquireReadLock(); + try { + IIndexFile ifile= fIndex.getFile(IndexLocationFactory.getWorkspaceIFL(file)); + assertNotNull(ifile); + IIndexInclude[] includes= ifile.getIncludes(); + assertEquals(1, includes.length); + + assertTrue(includes[0].isActive()); + assertFalse(includes[0].isResolved()); + checkInclude(includes[0], content, "unresolved20070213.h", false); + } + finally { + fIndex.releaseReadLock(); + } + } + finally { + TestScannerProvider.sIncludes= null; + } + } + private void checkInclude(IIndexInclude include, String content, String includeName, boolean isSystem) throws CoreException { int offset= content.indexOf(includeName); assertEquals(offset, include.getNameOffset()); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IInclude.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IInclude.java index d4c867e2300..6cb37d54035 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IInclude.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IInclude.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 QNX Software Systems and others. + * Copyright (c) 2000, 2007 QNX Software Systems 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 @@ -7,6 +7,7 @@ * * Contributors: * QNX Software Systems - Initial API and implementation + * Anton Leherbauer (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.model; @@ -32,4 +33,15 @@ public interface IInclude extends ICElement, ISourceReference, ISourceManipulati public String getFullFileName(); public boolean isLocal(); + + /** + * @return whether this include directive is in active code, ie. not hidden + * by conditional compilation + */ + public boolean isActive(); + + /** + * @return whether this include directive was resolved and followed. + */ + boolean isResolved(); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder2.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder2.java index 1a3fd5ea588..8c96af240b8 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder2.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder2.java @@ -296,16 +296,6 @@ public class CModelBuilder2 implements IContributedModelBuilder { createInclusion(fTranslationUnit, includeDirective); } } - // problem includes - final IASTProblem[] ppProblems= ast.getPreprocessorProblems(); - for (int i= 0; i < ppProblems.length; i++) { - IASTProblem problem= ppProblems[i]; - if (problem.getID() == IASTProblem.PREPROCESSOR_INCLUSION_NOT_FOUND) { - if (isLocalToFile(problem)) { - createProblemInclusion(fTranslationUnit, problem); - } - } - } // macros final IASTPreprocessorMacroDefinition[] macroDefinitions= ast.getMacroDefinitions(); for (int i= 0; i < macroDefinitions.length; i++) { @@ -347,6 +337,7 @@ public class CModelBuilder2 implements IContributedModelBuilder { } if (problemRequestor != null && problemRequestor.isActive()) { problemRequestor.beginReporting(); + final IASTProblem[] ppProblems= ast.getPreprocessorProblems(); IASTProblem[] problems= ppProblems; for (int i= 0; i < problems.length; i++) { IASTProblem problem= problems[i]; @@ -378,6 +369,8 @@ public class CModelBuilder2 implements IContributedModelBuilder { final IASTName name= inclusion.getName(); Include element= new Include(parent, ASTStringUtil.getSimpleName(name), inclusion.isSystemInclude()); element.setFullPathName(inclusion.getPath()); + element.setActive(inclusion.isActive()); + element.setResolved(inclusion.isResolved()); // add to parent parent.addChild(element); // set positions @@ -386,35 +379,6 @@ public class CModelBuilder2 implements IContributedModelBuilder { return element; } - private Include createProblemInclusion(Parent parent, IASTProblem problem) throws CModelException { - // create element - String name= problem.getArguments(); - if (name == null || name.length() == 0) { - return null; - } - String signature= problem.getRawSignature(); - int nameIdx= signature.indexOf(name); - boolean isStandard= false; - if (nameIdx > 0) { - isStandard= signature.charAt(nameIdx-1) == '<'; - } - Include element= new Include(parent, name, isStandard); - // add to parent - parent.addChild(element); - // set positions - if (nameIdx > 0) { - final IASTFileLocation problemLocation= problem.getFileLocation(); - if (problemLocation != null) { - final int startOffset= problemLocation.getNodeOffset(); - element.setIdPos(startOffset + nameIdx, name.length()); - } - } else { - setIdentifierPosition(element, problem); - } - setBodyPosition(element, problem); - return element; - } - private Macro createMacro(Parent parent, IASTPreprocessorMacroDefinition macro) throws CModelException{ // create element final IASTName name= macro.getName(); @@ -425,7 +389,6 @@ public class CModelBuilder2 implements IContributedModelBuilder { setIdentifierPosition(element, name); setBodyPosition(element, macro); return element; - } private void createDeclaration(Parent parent, IASTDeclaration declaration) throws CModelException, DOMException { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Include.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Include.java index 2f6d01cde4b..c3bf5cc70c4 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Include.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Include.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 QNX Software Systems and others. + * Copyright (c) 2000, 2007 QNX Software Systems 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 @@ -7,6 +7,7 @@ * * Contributors: * QNX Software Systems - Initial API and implementation + * Anton Leherbauer (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.model; @@ -18,7 +19,9 @@ public class Include extends SourceManipulation implements IInclude { private final boolean standard; private String fullPath; - + private boolean fIsActive= true; + private boolean fIsResolved= true; + public Include(ICElement parent, String name, boolean isStandard) { super(parent, name, ICElement.C_INCLUDE); standard = isStandard; @@ -54,4 +57,41 @@ public class Include extends SourceManipulation implements IInclude { this.fullPath = fullPath; } + public void setActive(boolean active) { + fIsActive= active; + } + + /* + * @see org.eclipse.cdt.core.model.IInclude#isActive() + */ + public boolean isActive() { + return fIsActive; + } + + public void setResolved(boolean resolved) { + fIsResolved= resolved; + } + + /* + * @see org.eclipse.cdt.core.model.IInclude#isResolved() + */ + public boolean isResolved() { + return fIsResolved; + } + + /* + * @see org.eclipse.cdt.internal.core.model.CElement#equals(java.lang.Object) + */ + public boolean equals(Object other) { + if (other instanceof IInclude) { + return equals(this, (IInclude) other); + } + return false; + } + + public static boolean equals(IInclude lhs, IInclude rhs) { + return CElement.equals(lhs, rhs) && + lhs.isActive() == rhs.isActive() && + lhs.isLocal() == rhs.isLocal(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTPreprocessorIncludeStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTPreprocessorIncludeStatement.java index 804b30a0264..acb46432f28 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTPreprocessorIncludeStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTPreprocessorIncludeStatement.java @@ -29,6 +29,7 @@ public interface IASTPreprocessorIncludeStatement extends /** * Returns the absolute location of the file found through #include. + * Only valid if {@link #isResolved()} returns true. */ public String getPath(); @@ -44,4 +45,16 @@ public interface IASTPreprocessorIncludeStatement extends * @since 4.0 */ public boolean isSystemInclude(); + + /** + * Returns whether this include directive was actually taken. + * @since 4.0 + */ + public boolean isActive(); + + /** + * Returns whether this include file was successfully resolved. + * @since 4.0 + */ + public boolean isResolved(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexInclude.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexInclude.java index 112d71114ed..e1ae97c291c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexInclude.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexInclude.java @@ -46,8 +46,13 @@ public interface IIndexInclude { IIndexFileLocation getIncludedByLocation() throws CoreException; /** - * Returns the IIndexFileLocation of the file that is included by this directive. - * @return the IIndexFileLocation of the file that is included by this directive + * Returns the IIndexFileLocation of the file that is included by this + * directive. In case of an unresolved or inactive include null + * will be returned. + * + * @return the IIndexFileLocation of the file that is included by this + * directive or null if the include is unresolved or + * inactive * @throws CoreException */ IIndexFileLocation getIncludesLocation() throws CoreException; @@ -72,4 +77,20 @@ public interface IIndexInclude { * @throws CoreException */ boolean isSystemInclude() throws CoreException; + + /** + * Test whether this include is in active code (not skipped by conditional preprocessing). + * + * @return whether this include is in active code + * @throws CoreException + */ + boolean isActive() throws CoreException; + + /** + * Test whether this include has been resolved (found in the file system). + * + * @return whether this is a resolved include + * @throws CoreException + */ + boolean isResolved() throws CoreException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CIndex.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CIndex.java index f99616e41da..ab40977811b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CIndex.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CIndex.java @@ -9,6 +9,7 @@ * Markus Schorn - initial API and implementation * Bryan Wilkinson (QNX) * Andrew Ferguson (Symbian) + * Anton Leherbauer (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.index; @@ -151,6 +152,9 @@ public class CIndex implements IIndex { } public IIndexFile resolveInclude(IIndexInclude include) throws CoreException { + if (!include.isResolved()) { + return null; + } IIndexFragmentInclude fragmentInclude = (IIndexFragmentInclude) include; IIndexFragment frag= fragmentInclude.getFragment(); if (isPrimaryFragment(frag)) { @@ -380,7 +384,7 @@ public class CIndex implements IIndex { List result = new ArrayList(); for (int i = 0; i < fFragments.length; i++) { IIndexFragmentBinding adapted = fFragments[i].adaptBinding(binding); - if (adapted instanceof IIndexFragmentBinding) { + if (adapted != null) { result.add(adapted); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexBasedCodeReaderFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexBasedCodeReaderFactory.java index b98cb6fe40a..71245edc0c9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexBasedCodeReaderFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexBasedCodeReaderFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2006 QNX Software Systems and others. + * Copyright (c) 2005, 2007 QNX Software Systems 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,6 +9,7 @@ * QNX - Initial API and implementation * Markus Schorn (Wind River Systems) * Andrew Ferguson (Symbian) + * Anton Leherbauer (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.index; @@ -16,10 +17,12 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; +import java.util.Set; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ICodeReaderFactory; @@ -49,6 +52,7 @@ public class IndexBasedCodeReaderFactory implements ICodeReaderFactory { private Map/**/ fileInfoCache; private Map/**/ iflCache; private List usedMacros = new ArrayList(); + private Set/**/ fIncluded= new HashSet(); /** The fallback code reader factory used in case a header file is not indexed */ private ICodeReaderFactory fFallBackFactory; @@ -118,6 +122,10 @@ public class IndexBasedCodeReaderFactory implements ICodeReaderFactory { IIndexFileLocation incLocation = findLocation(canonicalPath); FileInfo info= createInfo(incLocation, null); + if (isIncluded(info)) { + return new CodeReader(canonicalPath, EMPTY_CHARS); + } + // try to build macro dictionary off index if (info.fFile != null) { try { @@ -145,6 +153,7 @@ public class IndexBasedCodeReaderFactory implements ICodeReaderFactory { } catch (NeedToParseException e) { } } + setIncluded(info); } catch (CoreException e) { CCorePlugin.log(e); @@ -157,6 +166,23 @@ public class IndexBasedCodeReaderFactory implements ICodeReaderFactory { return ParserUtil.createReader(canonicalPath, null); } + /** + * Mark the given inclusion as included. + * @param info + */ + private void setIncluded(FileInfo info) { + fIncluded.add(info); + } + + /** + * Test whether the given inclusion is already included. + * @param info + * @return true if the inclusion is already included. + */ + private boolean isIncluded(FileInfo info) { + return fIncluded.contains(info); + } + private FileInfo createInfo(IIndexFileLocation location, IIndexFile file) throws CoreException { FileInfo info= (FileInfo) fileInfoCache.get(location); if (info == null) { @@ -171,10 +197,13 @@ public class IndexBasedCodeReaderFactory implements ICodeReaderFactory { if (!target.add(fileInfo)) { return; } + if (isIncluded(fileInfo)) { + return; + } if (fileInfo.fFile == null || fileInfo.isRequested()) { throw new NeedToParseException(); } - + // Follow the includes IIndexFile file= fileInfo.fFile; IIndexInclude[] includeDirectives= file.getIncludes(); @@ -185,6 +214,7 @@ public class IndexBasedCodeReaderFactory implements ICodeReaderFactory { getInfosForMacroDictionary(nextInfo, target); } } + setIncluded(fileInfo); } public void clearMacroAttachements() { @@ -198,6 +228,7 @@ public class IndexBasedCodeReaderFactory implements ICodeReaderFactory { } } usedMacros.clear(); + fIncluded.clear(); } public ICodeReaderCache getCodeReaderCache() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/BaseScanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/BaseScanner.java index af92f567b0e..6df3f5a489a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/BaseScanner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/BaseScanner.java @@ -2636,10 +2636,10 @@ abstract class BaseScanner implements IScanner { if (type != ppKeywords.undefined) { switch (type) { case ppInclude: - handlePPInclude(pos, false, startingLineNumber); + handlePPInclude(pos, false, startingLineNumber, true); return; case ppInclude_next: - handlePPInclude(pos, true, startingLineNumber); + handlePPInclude(pos, true, startingLineNumber, true); return; case ppDefine: handlePPDefine(pos, startingLineNumber); @@ -2760,7 +2760,7 @@ abstract class BaseScanner implements IScanner { protected abstract void processIf(int startPos, int endPos, boolean taken); protected void handlePPInclude(int pos2, boolean include_next, - int startingLineNumber) { + int startingLineNumber, boolean active) { char[] buffer = bufferStack[bufferStackPos]; int limit = bufferLimit[bufferStackPos]; @@ -2845,6 +2845,7 @@ abstract class BaseScanner implements IScanner { nameOffset= pos; int len= bufferPos[bufferStackPos] - nameOffset; nameEndOffset= nameOffset + len; + endOffset= nameEndOffset; bufferPos[bufferStackPos]--; Object expObject = definitions.get(buffer, nameOffset, len); @@ -2874,19 +2875,46 @@ abstract class BaseScanner implements IScanner { } if (filename == null || filename == EMPTY_STRING) { - handleProblem(IProblem.PREPROCESSOR_INVALID_DIRECTIVE, startOffset, - null); - return; + if (active) { + handleProblem(IProblem.PREPROCESSOR_INVALID_DIRECTIVE, startOffset, + null); + return; + } + filename= new String(buffer, nameOffset, nameEndOffset - nameOffset); } char[] fileNameArray = filename.toCharArray(); + // TODO else we need to do macro processing on the rest of the line endLine = getLineNumber(bufferPos[bufferStackPos]); skipToNewLine(); - findAndPushInclusion(filename, fileNameArray, local, include_next, startOffset, nameOffset, nameEndOffset, endOffset, startingLineNumber, nameLine, endLine); + if (active) { + findAndPushInclusion(filename, fileNameArray, local, include_next, startOffset, nameOffset, nameEndOffset, endOffset, startingLineNumber, nameLine, endLine); + } else { + processInclude(fileNameArray, local, active, startOffset, nameOffset, nameEndOffset, endOffset, startingLineNumber, nameLine, endLine); + } } /** + * Process an include directive without following the inclusion. + * + * @param fileName + * @param local + * @param active + * @param startOffset + * @param nameOffset + * @param nameEndOffset + * @param endOffset + * @param startingLineNumber + * @param nameLine + * @param endLine + */ + protected void processInclude(char[] fileName, boolean local, boolean active, int startOffset, int nameOffset, + int nameEndOffset, int endOffset, int startingLineNumber, int nameLine, int endLine) { + // default: do nothing + } + + /** * @param filename * @param fileNameArray * @param local @@ -2922,6 +2950,7 @@ abstract class BaseScanner implements IScanner { endLine, false))); return; } + processInclude(fileNameArray, local, true, startOffset, nameOffset, nameEndOffset, endOffset, startingLine, nameLine, endLine); handleProblem(IProblem.PREPROCESSOR_INCLUSION_NOT_FOUND, startOffset, fileNameArray); return; @@ -2981,6 +3010,7 @@ abstract class BaseScanner implements IScanner { } } } + processInclude(fileNameArray, local, true, startOffset, nameOffset, nameEndOffset, endOffset, startingLine, nameLine, endLine); handleProblem(IProblem.PREPROCESSOR_INCLUSION_NOT_FOUND, startOffset, fileNameArray); } @@ -3552,6 +3582,12 @@ abstract class BaseScanner implements IScanner { skipToNewLine(); } break; + case ppInclude: + handlePPInclude(startPos, false, getLineNumber(startPos), false); + break; + case ppInclude_next: + handlePPInclude(startPos, true, getLineNumber(startPos), false); + break; } } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DOMScanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DOMScanner.java index ddbe854303b..79a2f7b47dd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DOMScanner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DOMScanner.java @@ -171,6 +171,14 @@ public class DOMScanner extends BaseScanner { } + /* + * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processInclude(char[], boolean, boolean, int, int, int, int, int, int, int) + */ + protected void processInclude(char[] filename, boolean local, boolean active, int startOffset, int nameOffset, + int nameEndOffset, int endOffset, int startingLineNumber, int nameLine, int endLine) { + locationMap.encounterPoundInclude(getGlobalOffset(startOffset), getGlobalOffset(nameOffset), getGlobalOffset(nameEndOffset), getGlobalOffset(endOffset), filename, !local, active); + } + /* * (non-Javadoc) * diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/IScannerPreprocessorLog.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/IScannerPreprocessorLog.java index 81639c104c7..7999da95dff 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/IScannerPreprocessorLog.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/IScannerPreprocessorLog.java @@ -74,7 +74,9 @@ public interface IScannerPreprocessorLog { public void encounterPoundUndef(int startOffset, int endOffset, char[] symbol, int nameOffset, IMacroDefinition macroDefinition); - public void encounterProblem(IASTProblem problem); + public void encounterPoundInclude(int startOffset, int nameOffset, int nameEndOffset, int endOffset, char[] name, boolean systemInclude, boolean active); + + public void encounterProblem(IASTProblem problem); public IMacroDefinition registerBuiltinObjectStyleMacro(ObjectStyleMacro macro); @@ -83,5 +85,5 @@ public interface IScannerPreprocessorLog { public IMacroDefinition registerBuiltinDynamicFunctionStyleMacro(DynamicFunctionStyleMacro macro); public IMacroDefinition registerBuiltinDynamicStyleMacro(DynamicStyleMacro macro); - + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java index 98f716edeed..e488d2fa827 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java @@ -442,6 +442,33 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { } + /** + * Represents an include directive without sub-contexts. + * This allows to model inactive includes and unresolved includes. + */ + protected static class _Include extends _Context implements + _IPreprocessorIncludeDirective { + + public final int fNameOffset; + public final int fNameEndOffset; + public final char[] fName; + public final boolean fSystemInclude; + public final boolean fIsActive; + public final boolean fIsResolved; + + public _Include(_CompositeContext parent, int startOffset, int endOffset, int nameOffset, int nameEndoffset, + char[] name, boolean systemInclude, boolean active, boolean resolved) { + super(parent, startOffset, endOffset); + fNameOffset= nameOffset; + fNameEndOffset= nameEndoffset; + fName= name; + fSystemInclude= systemInclude; + fIsActive= active; + fIsResolved= resolved; + } + + } + /** * @author jcamelon */ @@ -454,7 +481,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { public int startOffset; public int endOffset; private boolean fSystemInclude; - + private boolean fIsActive= true; + private boolean fIsResolved= true; /** * @param cs @@ -463,11 +491,6 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { this.path = cs; } - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement#getPath() - */ public String getPath() { return new String(path); } @@ -491,6 +514,22 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { public void setSystemInclude(boolean val) { fSystemInclude= val; } + + public boolean isActive() { + return fIsActive; + } + + public void setActive(boolean val) { + fIsActive= val; + } + + public boolean isResolved() { + return fIsResolved; + } + + public void setResolved(boolean val) { + fIsResolved= val; + } } /** @@ -605,6 +644,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { public static interface _IPreprocessorDirective { } + public static interface _IPreprocessorIncludeDirective extends _IPreprocessorDirective { + } protected class _Undef extends _Context implements _IPreprocessorDirective { @@ -1216,7 +1257,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { } protected static class _Inclusion extends _CompositeFileContext implements - _IPreprocessorDirective { + _IPreprocessorIncludeDirective { public final int fNameOffset; public final int fNameEndOffset; @@ -1539,7 +1580,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { collectContexts(V_INCLUSIONS, tu, contexts, 0); IASTPreprocessorIncludeStatement[] result = new IASTPreprocessorIncludeStatement[size]; for (int i = 0; i < size; ++i) - result[i] = createASTInclusion(((_Inclusion) contexts[i])); + result[i] = (IASTPreprocessorIncludeStatement)createPreprocessorStatement(contexts[i]); return result; } @@ -1561,6 +1602,26 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { result.setParent(rootNode); result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT); result.setSystemInclude(inc.fSystemInclude); + result.setActive(true); + result.setResolved(true); + return result; + } + + private IASTPreprocessorIncludeStatement createASTInclusion(_Include inc) { + ASTInclusionStatement result = new ASTInclusionStatement(inc.fName); + result.setOffsetAndLength(inc.context_directive_start, inc.getDirectiveLength()); + result.startOffset = inc.getContextStart(); + result.endOffset = inc.context_directive_end; + ASTIncludeName name= new ASTIncludeName(inc.fName); + name.setPropertyInParent(IASTPreprocessorIncludeStatement.INCLUDE_NAME); + name.setParent(result); + name.setOffsetAndLength(inc.fNameOffset, inc.fNameEndOffset-inc.fNameOffset); + result.setName(name); + result.setParent(rootNode); + result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT); + result.setSystemInclude(inc.fSystemInclude); + result.setActive(inc.fIsActive); + result.setResolved(inc.fIsResolved); return result; } @@ -1587,6 +1648,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { IASTPreprocessorStatement result = null; if (context instanceof _Inclusion) result = createASTInclusion(((_Inclusion) context)); + else if (context instanceof _Include) + result = createASTInclusion(((_Include) context)); else if (context instanceof _MacroDefinition) result = createASTMacroDefinition((_MacroDefinition) context); else if (context instanceof _Undef) @@ -2171,6 +2234,14 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { endOffset)); } + /* + * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundInclude(int, int, int, int, char[], boolean, boolean) + */ + public void encounterPoundInclude(int startOffset, int nameOffset, int nameEndOffset, int endOffset, char[] name, + boolean systemInclude, boolean active) { + currentContext.addSubContext(new _Include(currentContext, startOffset, endOffset, nameOffset, nameEndOffset, name, systemInclude, active, false)); + } + /* * (non-Javadoc) * @@ -2256,7 +2327,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { ++count; break; case V_INCLUSIONS: - if (source instanceof _Inclusion) { + if (source instanceof _IPreprocessorIncludeDirective) { if (result != null) result[startAt++] = source; ++count; @@ -2264,7 +2335,6 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { break; case V_PROBLEMS: if (source instanceof _Problem) { - if (result != null) result[startAt++] = source; ++count; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMInclude.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMInclude.java index 927182f75a8..61488a4df73 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMInclude.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMInclude.java @@ -42,6 +42,8 @@ public class PDOMInclude implements IIndexFragmentInclude { private static final int FLAG_OFFSET = 26; private static final int FLAG_SYSTEM_INCLUDE = 1; + private static final int FLAG_INACTIVE_INCLUDE = 2; + private static final int FLAG_UNRESOLVED_INCLUDE = 4; private final int RECORD_SIZE = 27; @@ -67,6 +69,12 @@ public class PDOMInclude implements IIndexFragmentInclude { if (include.isSystemInclude()) { flags |= FLAG_SYSTEM_INCLUDE; } + if (!include.isActive()) { + flags |= FLAG_INACTIVE_INCLUDE; + } + if (!include.isResolved()) { + flags |= FLAG_UNRESOLVED_INCLUDE; + } return flags; } @@ -169,6 +177,14 @@ public class PDOMInclude implements IIndexFragmentInclude { return (getFlag() & FLAG_SYSTEM_INCLUDE) != 0; } + public boolean isActive() throws CoreException { + return (getFlag() & FLAG_INACTIVE_INCLUDE) == 0; + } + + public boolean isResolved() throws CoreException { + return (getFlag() & FLAG_UNRESOLVED_INCLUDE) == 0; + } + public int getNameOffset() throws CoreException { return pdom.getDB().getInt(record + NODE_OFFSET_OFFSET); } diff --git a/core/org.eclipse.cdt.ui/icons/ovr16/inactive_co.gif b/core/org.eclipse.cdt.ui/icons/ovr16/inactive_co.gif new file mode 100644 index 00000000000..d03b6a99d68 Binary files /dev/null and b/core/org.eclipse.cdt.ui/icons/ovr16/inactive_co.gif differ diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java index 3f3ac63aeb8..b9aa0716154 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java @@ -145,7 +145,7 @@ public class CPluginImages { public static final ImageDescriptor DESC_OBJS_PROTECTED_FIELD= createManaged(T_OBJ, IMG_OBJS_PROTECTED_FIELD); public static final ImageDescriptor DESC_OBJS_PRIVATE_FIELD= createManaged(T_OBJ, IMG_OBJS_PRIVATE_FIELD); public static final ImageDescriptor DESC_OBJS_KEYWORD= createManaged(T_OBJ, IMG_OBJS_KEYWORD); - + public static final ImageDescriptor DESC_OBJS_CLASS_ALT= createManaged(T_OBJ, IMG_OBJS_CLASS_ALT); public static final ImageDescriptor DESC_OBJS_STRUCT_ALT= createManaged(T_OBJ, IMG_OBJS_STRUCT_ALT); public static final ImageDescriptor DESC_OBJS_UNION_ALT= createManaged(T_OBJ, IMG_OBJS_UNION_ALT); @@ -251,6 +251,7 @@ public class CPluginImages { public static final ImageDescriptor DESC_OVR_REC_REFERENCEDBY= create(T_OVR, "rec_referencedby_co.gif"); //$NON-NLS-1$ public static final ImageDescriptor DESC_OVR_SYSTEM_INCLUDE= create(T_OVR, "systeminclude_co.gif"); //$NON-NLS-1$ public static final ImageDescriptor DESC_OVR_DEFINES= create(T_OVR, "defines_co.gif"); //$NON-NLS-1$ + public static final ImageDescriptor DESC_OVR_INACTIVE= create(T_OVR, "inactive_co.gif"); //$NON-NLS-1$ public static final ImageDescriptor DESC_OVR_WARNING= create(T_OVR, "warning_co.gif"); //$NON-NLS-1$ public static final ImageDescriptor DESC_OVR_ERROR= create(T_OVR, "error_co.gif"); //$NON-NLS-1$ diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBContentProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBContentProvider.java index dfc544cb904..f503be4711c 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBContentProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBContentProvider.java @@ -122,7 +122,7 @@ public class IBContentProvider extends AsyncTreeContentProvider { name, include.getNameOffset(), include.getNameLength(), include.getIncludedBy().getTimestamp()); - newnode.setIsActiveCode(true); + newnode.setIsActiveCode(include.isActive()); newnode.setIsSystemInclude(include.isSystemInclude()); result.add(newnode); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBLabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBLabelProvider.java index d194437a1a7..3e60d66744b 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBLabelProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBLabelProvider.java @@ -81,6 +81,9 @@ public class IBLabelProvider extends LabelProvider implements IColorProvider { if (node.isSystemInclude()) { flags |= CElementImageDescriptor.SYSTEM_INCLUDE; } + if (!node.isActiveCode()) { + flags |= CElementImageDescriptor.INACTIVE; + } if (node.isRecursive()) { flags |= CElementImageDescriptor.RECURSIVE_RELATION; @@ -94,7 +97,7 @@ public class IBLabelProvider extends LabelProvider implements IColorProvider { } } - if (node.getRepresentedTranslationUnit() == null) { + if (node.isActiveCode() && node.getRepresentedTranslationUnit() == null) { flags |= CElementImageDescriptor.WARNING; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/CElementImageProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/CElementImageProvider.java index 0619fe0cfc1..01092ee577d 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/CElementImageProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/CElementImageProvider.java @@ -12,25 +12,6 @@ *******************************************************************************/ package org.eclipse.cdt.internal.ui.viewsupport; -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.cdt.core.model.IBinary; -import org.eclipse.cdt.core.model.IBinaryModule; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.core.model.IContributedCElement; -import org.eclipse.cdt.core.model.IDeclaration; -import org.eclipse.cdt.core.model.IField; -import org.eclipse.cdt.core.model.IIncludeReference; -import org.eclipse.cdt.core.model.ILibraryReference; -import org.eclipse.cdt.core.model.IMethodDeclaration; -import org.eclipse.cdt.core.model.ISourceRoot; -import org.eclipse.cdt.core.model.ITemplate; -import org.eclipse.cdt.core.model.ITranslationUnit; -import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; -import org.eclipse.cdt.internal.ui.CPluginImages; -import org.eclipse.cdt.ui.CElementImageDescriptor; -import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IAdaptable; @@ -41,6 +22,28 @@ import org.eclipse.ui.ISharedImages; import org.eclipse.ui.ide.IDE; import org.eclipse.ui.model.IWorkbenchAdapter; +import org.eclipse.cdt.core.model.CModelException; +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.model.IBinary; +import org.eclipse.cdt.core.model.IBinaryModule; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.model.IContributedCElement; +import org.eclipse.cdt.core.model.IDeclaration; +import org.eclipse.cdt.core.model.IField; +import org.eclipse.cdt.core.model.IInclude; +import org.eclipse.cdt.core.model.IIncludeReference; +import org.eclipse.cdt.core.model.ILibraryReference; +import org.eclipse.cdt.core.model.IMethodDeclaration; +import org.eclipse.cdt.core.model.ISourceRoot; +import org.eclipse.cdt.core.model.ITemplate; +import org.eclipse.cdt.core.model.ITranslationUnit; +import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; +import org.eclipse.cdt.ui.CElementImageDescriptor; +import org.eclipse.cdt.ui.CUIPlugin; + +import org.eclipse.cdt.internal.ui.CPluginImages; + /** * Default strategy of the C plugin for the construction of C element icons. @@ -48,7 +51,7 @@ import org.eclipse.ui.model.IWorkbenchAdapter; public class CElementImageProvider { /** - * Flags for the CImageLabelProvider: + * Flags for the CElementImageProvider: * Generate images with overlays. */ public final static int OVERLAY_ICONS= 0x1; @@ -103,7 +106,7 @@ public class CElementImageProvider { * Returns the icon for a given element. The icon depends on the element type * and element properties. If configured, overlay icons are constructed for * ISourceReferences. - * @param flags Flags as defined by the JavaImageLabelProvider + * @param flags Flags as defined by the CElementImageProvider */ public Image getImageLabel(Object element, int flags) { ImageDescriptor descriptor= null; @@ -365,7 +368,6 @@ public class CElementImageProvider { case ICElement.C_TEMPLATE_METHOD: case ICElement.C_TEMPLATE_METHOD_DECLARATION: try { - IMethodDeclaration md= (IMethodDeclaration)celement; ASTAccessVisibility visibility =md.getVisibility(); return getMethodImageDescriptor(visibility); @@ -405,8 +407,9 @@ public class CElementImageProvider { case ICElement.C_USING: return getUsingImageDescriptor(); + default: + return getImageDescriptor(type); } - return null; } @@ -415,24 +418,32 @@ public class CElementImageProvider { private int computeCAdornmentFlags(ICElement element, int renderFlags) { int flags= computeBasicAdornmentFlags(element, renderFlags); - - try { - if (showOverlayIcons(renderFlags) && element instanceof IDeclaration) { - IDeclaration decl = (IDeclaration) element; - if(decl.isStatic()){ - flags |= CElementImageDescriptor.STATIC; - } - if(decl.isConst()){ - flags |= CElementImageDescriptor.CONSTANT; - } - if(decl.isVolatile()){ - flags |= CElementImageDescriptor.VOLATILE; - } - if(element instanceof ITemplate){ - flags |= CElementImageDescriptor.TEMPLATE; + if (showOverlayIcons(renderFlags)) { + try { + if (element instanceof IDeclaration) { + IDeclaration decl = (IDeclaration) element; + if(decl.isStatic()){ + flags |= CElementImageDescriptor.STATIC; + } + if(decl.isConst()){ + flags |= CElementImageDescriptor.CONSTANT; + } + if(decl.isVolatile()){ + flags |= CElementImageDescriptor.VOLATILE; + } + if(element instanceof ITemplate){ + flags |= CElementImageDescriptor.TEMPLATE; + } + } else if (element instanceof IInclude) { + IInclude include= (IInclude) element; + if (!include.isActive()) { + flags |= CElementImageDescriptor.INACTIVE; + } else if (!include.isResolved()) { + flags |= CElementImageDescriptor.WARNING; + } } + } catch (CModelException e) { } - } catch (CModelException e) { } return flags; } @@ -444,7 +455,7 @@ public class CElementImageProvider { } if ((renderFlags & OVERLAY_WARNING) !=0) { flags |= CElementImageDescriptor.WARNING; - } + } // if ((renderFlags & OVERLAY_OVERRIDE) !=0) { // flags |= CElementImageDescriptor.OVERRIDES; // } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/CUILabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/CUILabelProvider.java index ebcf331d24c..9095846a6db 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/CUILabelProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/CUILabelProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. + * Copyright (c) 2000, 2007 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 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Anton Leherbauer (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.ui.viewsupport; @@ -17,9 +18,13 @@ import org.eclipse.jface.viewers.IColorProvider; import org.eclipse.jface.viewers.ILabelDecorator; import org.eclipse.jface.viewers.ILabelProviderListener; import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Image; +import org.eclipse.cdt.core.model.IInclude; +import org.eclipse.cdt.ui.CUIPlugin; + public class CUILabelProvider extends LabelProvider implements IColorProvider { protected CElementImageProvider fImageLabelProvider; @@ -29,6 +34,7 @@ public class CUILabelProvider extends LabelProvider implements IColorProvider { private int fImageFlags; private int fTextFlags; + private Color fInactiveColor; /** * Creates a new label provider with default flags. @@ -38,8 +44,8 @@ public class CUILabelProvider extends LabelProvider implements IColorProvider { } /** - * @param textFlags Flags defined in JavaElementLabels. - * @param imageFlags Flags defined in JavaElementImageProvider. + * @param textFlags Flags defined in CElementLabels. + * @param imageFlags Flags defined in CElementImageProvider. */ public CUILabelProvider(int textFlags, int imageFlags) { fImageLabelProvider= new CElementImageProvider(); @@ -48,6 +54,7 @@ public class CUILabelProvider extends LabelProvider implements IColorProvider { fStorageLabelProvider= new StorageLabelProvider(); fImageFlags= imageFlags; fTextFlags= textFlags; + fInactiveColor= CUIPlugin.getStandardDisplay().getSystemColor(SWT.COLOR_DARK_GRAY); } /** @@ -220,6 +227,12 @@ public class CUILabelProvider extends LabelProvider implements IColorProvider { * @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object) */ public Color getForeground(Object element) { + if (element instanceof IInclude) { + IInclude include= (IInclude)element; + if (!include.isActive()) { + return fInactiveColor; + } + } return null; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CElementImageDescriptor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CElementImageDescriptor.java index 0bdf0225c62..4180f298107 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CElementImageDescriptor.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CElementImageDescriptor.java @@ -88,12 +88,15 @@ public class CElementImageDescriptor extends CompositeImageDescriptor { /** Flag to render the 'defines' adornment in the type hierarchy*/ public final static int DEFINES= 0x4000; + /** Flag to render the 'inactive' adornment for include directives */ + public final static int INACTIVE= 0x8000; + private ImageDescriptor fBaseImage; private int fFlags; private Point fSize; /** - * Create a new JavaElementImageDescriptor. + * Create a new CElementImageDescriptor. * * @param baseImage an image descriptor used as the base image * @param flags flags indicating which adornments are to be rendered. See setAdornments @@ -255,7 +258,7 @@ public class CElementImageDescriptor extends CompositeImageDescriptor { // x-= data.width; // drawImage(data, x, size.y - data.height); // } - } + } private void drawTopLeft() { ImageData data= null; @@ -263,8 +266,12 @@ public class CElementImageDescriptor extends CompositeImageDescriptor { data= CPluginImages.DESC_OVR_DEFINES.getImageData(); drawImage(data, 0, 0); } + if ((fFlags & INACTIVE) != 0) { + data= CPluginImages.DESC_OVR_INACTIVE.getImageData(); + drawImage(data, 0, 0); + } } - + private void drawBottomLeft() { Point size= getSize(); int x= 0;