From 01323153a07bf6582b0b97c3b5fa11c97976903e Mon Sep 17 00:00:00 2001 From: Anton Leherbauer Date: Tue, 15 Jan 2008 14:39:19 +0000 Subject: [PATCH] Fix and test for macro expansion handling in model builder --- .../model/failedTests/FailedMacroTests.java | 77 ++-------------- .../cdt/core/model/tests/AllCoreTests.java | 4 +- .../cdt/core/model/tests/MacroTests.java | 90 +++++++++++++++++-- .../internal/core/model/CModelBuilder2.java | 29 +++--- .../SemanticHighlightingReconciler.java | 2 +- .../internal/ui/search/OccurrencesFinder.java | 14 +-- 6 files changed, 115 insertions(+), 101 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/model/failedTests/FailedMacroTests.java b/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/model/failedTests/FailedMacroTests.java index 30564e7e600..704bca45fd1 100644 --- a/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/model/failedTests/FailedMacroTests.java +++ b/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/model/failedTests/FailedMacroTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. + * Copyright (c) 2002, 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 @@ -10,13 +10,9 @@ *******************************************************************************/ package org.eclipse.cdt.core.model.failedTests; -import java.util.Stack; +import junit.framework.Test; +import junit.framework.TestSuite; -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.ICElement; -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.tests.IntegratedCModelTest; /** @@ -25,6 +21,11 @@ import org.eclipse.cdt.core.model.tests.IntegratedCModelTest; */ public class FailedMacroTests extends IntegratedCModelTest { + public static Test suite() { + TestSuite suite= new TestSuite("FailedMacroTests"); + return suite; + } + /** * */ @@ -56,66 +57,4 @@ public class FailedMacroTests extends IntegratedCModelTest return "MacroTests.cpp"; } - private final static boolean failedTest = true; - /* This is a list of elements in the test .c file. It will be used - * in a number of places in the tests - */ - String[] expectedStringList= {"Z", "X", "Y", - "SomeName", "", "A::BCD", "DEFA", "DB", "B::SomeName", - "PINT", "myPINT", "foobar"}; - int[] expectedOffsets={ 8,26,39,55,75,89,114,130,152,187,212,227}; - int[] expectedLengths={ 1, 1, 1, 1, 1, 8, 4, 2, 18, 4, 6, 6}; - /* This is a list of that the types of the above list of elements is - * expected to be. - */ - int[] expectedTypes= { ICElement.C_MACRO, ICElement.C_MACRO, - ICElement.C_MACRO, ICElement.C_STRUCT, - ICElement.C_STRUCT, ICElement.C_VARIABLE, ICElement.C_MACRO, - ICElement.C_MACRO, ICElement.C_VARIABLE, ICElement.C_MACRO, - ICElement.C_VARIABLE, ICElement.C_FUNCTION_DECLARATION}; - - - public void testBug40759 () throws CModelException { - ITranslationUnit myTranslationUnit = getTU(); - ICElement myElement; - Stack missing=new Stack(); - int x; - - for (x=0;x fVisibilityStack; private IProgressMonitor fProgressMonitor; /** @@ -282,11 +282,11 @@ public class CModelBuilder2 implements IContributedModelBuilder { */ private void buildModel(IASTTranslationUnit ast) throws CModelException, DOMException { fTranslationUnitFileName= ast.getFilePath(); - fVisibilityStack= new Stack(); + fVisibilityStack= new Stack(); // includes final IASTPreprocessorIncludeStatement[] includeDirectives= ast.getIncludeDirectives(); - Set allIncludes= new HashSet(); + Set allIncludes= new HashSet(); for (int i= 0; i < includeDirectives.length; i++) { IASTPreprocessorIncludeStatement includeDirective= includeDirectives[i]; if (isLocalToFile(includeDirective)) { @@ -311,12 +311,12 @@ public class CModelBuilder2 implements IContributedModelBuilder { } // sort by offset - final List children= fTranslationUnit.getElementInfo().internalGetChildren(); - Collections.sort(children, new Comparator() { - public int compare(Object o1, Object o2) { + final List children= fTranslationUnit.getElementInfo().internalGetChildren(); + Collections.sort(children, new Comparator() { + public int compare(SourceManipulation o1, SourceManipulation o2) { try { - final SourceManipulationInfo info1= ((SourceManipulation)o1).getSourceManipulationInfo(); - final SourceManipulationInfo info2= ((SourceManipulation)o2).getSourceManipulationInfo(); + final SourceManipulationInfo info1= o1.getSourceManipulationInfo(); + final SourceManipulationInfo info2= o2.getSourceManipulationInfo(); int delta= info1.getStartPos() - info2.getStartPos(); if (delta == 0) { delta= info1.getIdStartPos() - info2.getIdStartPos(); @@ -358,7 +358,7 @@ public class CModelBuilder2 implements IContributedModelBuilder { return fTranslationUnitFileName.equals(node.getContainingFilename()); } - private Include createInclusion(Parent parent, IASTPreprocessorIncludeStatement inclusion, Set allIncludes) throws CModelException{ + private Include createInclusion(Parent parent, IASTPreprocessorIncludeStatement inclusion, Set allIncludes) throws CModelException{ // create element final IASTName name= inclusion.getName(); Include element= new Include(parent, ASTStringUtil.getSimpleName(name), inclusion.isSystemInclude()); @@ -1212,12 +1212,7 @@ public class CModelBuilder2 implements IContributedModelBuilder { * @param astName */ private void setIdentifierPosition(SourceManipulationInfo info, IASTNode astName) { - final IASTFileLocation location; - if (astName instanceof IASTName) { - location= ((IASTName)astName).getImageLocation(); - } else { - location= astName.getFileLocation(); - } + final IASTFileLocation location= astName.getFileLocation(); if (location != null) { info.setIdPos(location.getNodeOffset(), location.getNodeLength()); } else { @@ -1293,7 +1288,7 @@ public class CModelBuilder2 implements IContributedModelBuilder { */ private void popDefaultVisibility() { if (!fVisibilityStack.isEmpty()) { - setCurrentVisibility((ASTAccessVisibility)fVisibilityStack.pop()); + setCurrentVisibility(fVisibilityStack.pop()); } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SemanticHighlightingReconciler.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SemanticHighlightingReconciler.java index 258f101bb26..148eccc53e0 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SemanticHighlightingReconciler.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SemanticHighlightingReconciler.java @@ -391,7 +391,7 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener { */ private void addNameLocation(IASTName name, HighlightingStyle highlightingStyle) { IASTImageLocation imageLocation= name.getImageLocation(); - if (imageLocation == null) { + if (imageLocation == null || !fFilePath.equals(imageLocation.getFileName())) { addNodeLocation(name.getFileLocation(), highlightingStyle); } else { int offset= imageLocation.getNodeOffset(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/OccurrencesFinder.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/OccurrencesFinder.java index a241e38671b..86e92a412a6 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/OccurrencesFinder.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/OccurrencesFinder.java @@ -14,9 +14,9 @@ package org.eclipse.cdt.internal.ui.search; import java.util.ArrayList; import java.util.List; +import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; -import org.eclipse.cdt.core.dom.ast.IASTNodeLocation; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; @@ -107,13 +107,13 @@ public class OccurrencesFinder implements IOccurrencesFinder { if (binding != null /* && Bindings.equals(binding, fTarget) */) { int flag= 0; String description= fDescription; - IASTNodeLocation nodeLocation= node.getImageLocation(); - if (nodeLocation == null) { - nodeLocation= node.getFileLocation(); + IASTFileLocation fileLocation= node.getImageLocation(); + if (fileLocation == null || !fRoot.getFilePath().equals(fileLocation.getFileName())) { + fileLocation= node.getFileLocation(); } - if (nodeLocation != null) { - final int offset= nodeLocation.getNodeOffset(); - final int length= nodeLocation.getNodeLength(); + if (fileLocation != null) { + final int offset= fileLocation.getNodeOffset(); + final int length= fileLocation.getNodeLength(); if (offset >= 0 && length > 0) { fResult.add(new OccurrenceLocation(offset, length, flag, description)); }