mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-01 06:05:24 +02:00
Bug 377045 - Bogus transient errors in C/C++ editor soon after Eclipse
startup.
This commit is contained in:
parent
885f6f1b7e
commit
e7ef578e94
13 changed files with 98 additions and 13 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2009, 2011 Alena Laskavaia
|
* Copyright (c) 2009, 2012 Alena Laskavaia
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -70,10 +70,14 @@ public abstract class AbstractIndexAstChecker extends AbstractCheckerWithProblem
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
IASTTranslationUnit ast = modelCache.getAST();
|
// Run the checker only if the index is fully initialized. Otherwise it may produce
|
||||||
if (ast != null) {
|
// false positives.
|
||||||
synchronized (ast) {
|
if (modelCache.getIndex().isFullyInitialized()) {
|
||||||
processAst(ast);
|
IASTTranslationUnit ast = modelCache.getAST();
|
||||||
|
if (ast != null) {
|
||||||
|
synchronized (ast) {
|
||||||
|
processAst(ast);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
|
@ -83,16 +87,19 @@ public abstract class AbstractIndexAstChecker extends AbstractCheckerWithProblem
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* (non-Javadoc)
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see IRunnableInEditorChecker#processModel(Object, ICheckerInvocationContext)
|
* @see IRunnableInEditorChecker#processModel(Object, ICheckerInvocationContext)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public synchronized void processModel(Object model, ICheckerInvocationContext context) {
|
public synchronized void processModel(Object model, ICheckerInvocationContext context) {
|
||||||
if (model instanceof IASTTranslationUnit) {
|
if (model instanceof IASTTranslationUnit) {
|
||||||
setContext(context);
|
|
||||||
IASTTranslationUnit ast = (IASTTranslationUnit) model;
|
IASTTranslationUnit ast = (IASTTranslationUnit) model;
|
||||||
|
// Run the checker only if the index was fully initialized when the file was parsed.
|
||||||
|
// Otherwise the checker may produce false positives.
|
||||||
|
if (ast.isBasedOnIncompleteIndex())
|
||||||
|
return;
|
||||||
|
|
||||||
|
setContext(context);
|
||||||
synchronized (context) {
|
synchronized (context) {
|
||||||
modelCache = context.get(CxxModelsCache.class);
|
modelCache = context.get(CxxModelsCache.class);
|
||||||
if (modelCache == null) {
|
if (modelCache == null) {
|
||||||
|
|
|
@ -201,4 +201,9 @@ public class EmptyIndexFragment implements IIndexFragment {
|
||||||
public IIndexScope[] getInlineNamespaces() {
|
public IIndexScope[] getInlineNamespaces() {
|
||||||
return IIndexScope.EMPTY_INDEX_SCOPE_ARRAY;
|
return IIndexScope.EMPTY_INDEX_SCOPE_ARRAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isFullyInitialized() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2000, 2011 QNX Software Systems and others.
|
* Copyright (c) 2000, 2012 QNX Software Systems and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -817,6 +817,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
||||||
}
|
}
|
||||||
|
|
||||||
public IASTTranslationUnit getAST(IIndex index, int style, IProgressMonitor monitor) throws CoreException {
|
public IASTTranslationUnit getAST(IIndex index, int style, IProgressMonitor monitor) throws CoreException {
|
||||||
|
boolean incompleteIndex = index != null && !index.isFullyInitialized();
|
||||||
IIndexFile[] contextToHeader = getContextToHeader(index, style);
|
IIndexFile[] contextToHeader = getContextToHeader(index, style);
|
||||||
ITranslationUnit configureWith = getConfigureWith(contextToHeader);
|
ITranslationUnit configureWith = getConfigureWith(contextToHeader);
|
||||||
if (configureWith == this)
|
if (configureWith == this)
|
||||||
|
@ -860,6 +861,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
||||||
ASTTranslationUnit ast = (ASTTranslationUnit) ((AbstractLanguage) language).getASTTranslationUnit(
|
ASTTranslationUnit ast = (ASTTranslationUnit) ((AbstractLanguage) language).getASTTranslationUnit(
|
||||||
fileContent, scanInfo, crf, index, options, log);
|
fileContent, scanInfo, crf, index, options, log);
|
||||||
ast.setOriginatingTranslationUnit(this);
|
ast.setOriginatingTranslationUnit(this);
|
||||||
|
ast.setBasedOnIncompleteIndex(incompleteIndex);
|
||||||
return ast;
|
return ast;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2004, 2011 IBM Corporation and others.
|
* Copyright (c) 2004, 2012 IBM Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -8,6 +8,7 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Doug Schaefer (IBM) - Initial API and implementation
|
* Doug Schaefer (IBM) - Initial API and implementation
|
||||||
* Markus Schorn (Wind River Systems)
|
* Markus Schorn (Wind River Systems)
|
||||||
|
* Sergey Prigogin (Google)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.core.dom.ast;
|
package org.eclipse.cdt.core.dom.ast;
|
||||||
|
|
||||||
|
@ -347,6 +348,13 @@ public interface IASTTranslationUnit extends IASTDeclarationListOwner, IFileNomi
|
||||||
*/
|
*/
|
||||||
public ITranslationUnit getOriginatingTranslationUnit();
|
public ITranslationUnit getOriginatingTranslationUnit();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns {@code true} if the index was not fully initialized when the code of the translation
|
||||||
|
* unit was parsed.
|
||||||
|
* @since 5.4
|
||||||
|
*/
|
||||||
|
boolean isBasedOnIncompleteIndex();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since 5.4
|
* @since 5.4
|
||||||
* @noreference This method is not intended to be referenced by clients.
|
* @noreference This method is not intended to be referenced by clients.
|
||||||
|
|
|
@ -445,4 +445,11 @@ public interface IIndex {
|
||||||
* @since 5.3
|
* @since 5.3
|
||||||
*/
|
*/
|
||||||
public IScope[] getInlineNamespaces() throws CoreException;
|
public IScope[] getInlineNamespaces() throws CoreException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns {@code true} if the index is fully initialized. An index may not be fully initialized
|
||||||
|
* during Eclipse startup, or soon after adding a new project to the workspace.
|
||||||
|
* @since 5.4
|
||||||
|
*/
|
||||||
|
public boolean isFullyInitialized();
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,6 +80,7 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
|
||||||
private SizeofCalculator fSizeofCalculator;
|
private SizeofCalculator fSizeofCalculator;
|
||||||
/** The semaphore controlling exclusive access to the AST. */
|
/** The semaphore controlling exclusive access to the AST. */
|
||||||
private final Semaphore fSemaphore= new Semaphore(1);
|
private final Semaphore fSemaphore= new Semaphore(1);
|
||||||
|
private boolean fBasedOnIncompleteIndex;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final IASTTranslationUnit getTranslationUnit() {
|
public final IASTTranslationUnit getTranslationUnit() {
|
||||||
|
@ -341,6 +342,15 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
|
||||||
fForContentAssist= forContentAssist;
|
fForContentAssist= forContentAssist;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isBasedOnIncompleteIndex() {
|
||||||
|
return fBasedOnIncompleteIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBasedOnIncompleteIndex(boolean basedOnIncompleteIndex) {
|
||||||
|
fBasedOnIncompleteIndex = basedOnIncompleteIndex;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void skippedFile(int offset, InternalFileContent fileContent) {
|
public void skippedFile(int offset, InternalFileContent fileContent) {
|
||||||
if (fIndexFileSet != null) {
|
if (fIndexFileSet != null) {
|
||||||
|
|
|
@ -781,6 +781,15 @@ public class CIndex implements IIndex {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isFullyInitialized() {
|
||||||
|
for (IIndexFragment fragment : fFragments) {
|
||||||
|
if (!fragment.isFullyInitialized())
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A key used to uniquely identify an IIndexFragmentName object. Uniqueness is guaranteed only
|
* A key used to uniquely identify an IIndexFragmentName object. Uniqueness is guaranteed only
|
||||||
* for names corresponding to the same binding.
|
* for names corresponding to the same binding.
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
* Sergey Prigogin (Google)
|
* Sergey Prigogin (Google)
|
||||||
* Jens Elmenthaler - http://bugs.eclipse.org/173458 (camel case completion)
|
* Jens Elmenthaler - http://bugs.eclipse.org/173458 (camel case completion)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.core.index;
|
package org.eclipse.cdt.internal.core.index;
|
||||||
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
@ -204,4 +203,9 @@ final public class EmptyCIndex implements IIndex {
|
||||||
public IScope[] getInlineNamespaces() {
|
public IScope[] getInlineNamespaces() {
|
||||||
return new IScope[0];
|
return new IScope[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isFullyInitialized() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -349,4 +349,10 @@ public interface IIndexFragment {
|
||||||
* @throws CoreException
|
* @throws CoreException
|
||||||
*/
|
*/
|
||||||
IIndexScope[] getInlineNamespaces() throws CoreException;
|
IIndexScope[] getInlineNamespaces() throws CoreException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns {@code true} if the index fragment is fully initialized. An fragment may not be fully
|
||||||
|
* initialized during Eclipse startup, or soon after adding a new project to the workspace.
|
||||||
|
*/
|
||||||
|
boolean isFullyInitialized();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1650,4 +1650,9 @@ public class PDOM extends PlatformObject implements IPDOM {
|
||||||
}
|
}
|
||||||
return linkage.getInlineNamespaces();
|
return linkage.getInlineNamespaces();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isFullyInitialized() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -350,4 +350,10 @@ public class PDOMProxy implements IPDOM {
|
||||||
|
|
||||||
return IIndexScope.EMPTY_INDEX_SCOPE_ARRAY;
|
return IIndexScope.EMPTY_INDEX_SCOPE_ARRAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized boolean isFullyInitialized() {
|
||||||
|
return fDelegate != null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,7 @@ import org.eclipse.ui.texteditor.MarkerUtilities;
|
||||||
import org.eclipse.ui.texteditor.ResourceMarkerAnnotationModel;
|
import org.eclipse.ui.texteditor.ResourceMarkerAnnotationModel;
|
||||||
import org.eclipse.ui.texteditor.spelling.SpellingAnnotation;
|
import org.eclipse.ui.texteditor.spelling.SpellingAnnotation;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
import org.eclipse.cdt.core.model.ICModelMarker;
|
import org.eclipse.cdt.core.model.ICModelMarker;
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
|
@ -429,11 +430,22 @@ public class CDocumentProvider extends TextFileDocumentProvider {
|
||||||
public void acceptProblem(IProblem problem) {
|
public void acceptProblem(IProblem problem) {
|
||||||
if (isActive()) {
|
if (isActive()) {
|
||||||
ProblemRequestorState state= fProblemRequestorState.get();
|
ProblemRequestorState state= fProblemRequestorState.get();
|
||||||
if (state != null)
|
if (state != null && isReliable(problem)) {
|
||||||
state.fReportedProblems.add(problem);
|
state.fReportedProblems.add(problem);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A problem is not considered reliable if it belongs to an unreliable AST.
|
||||||
|
*/
|
||||||
|
private static boolean isReliable(IProblem problem) {
|
||||||
|
if (problem instanceof IASTNode) {
|
||||||
|
return !((IASTNode) problem).getTranslationUnit().isBasedOnIncompleteIndex();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void endReporting() {
|
public void endReporting() {
|
||||||
ProblemRequestorState state= fProblemRequestorState.get();
|
ProblemRequestorState state= fProblemRequestorState.get();
|
||||||
|
|
|
@ -1316,6 +1316,10 @@ public class SemanticHighlightings {
|
||||||
@Override
|
@Override
|
||||||
public boolean consumes(SemanticToken token) {
|
public boolean consumes(SemanticToken token) {
|
||||||
IASTNode node= token.getNode();
|
IASTNode node= token.getNode();
|
||||||
|
if (node.getTranslationUnit().isBasedOnIncompleteIndex()) {
|
||||||
|
// Do not highlight problems is the AST is unreliable.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (node instanceof IASTProblem) {
|
if (node instanceof IASTProblem) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue