diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index 7ee28813f70..23d42cca070 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -9526,4 +9526,16 @@ public class AST2CPPTests extends AST2BaseTest { ICPPClassType c= bh.assertNonProblem("A", 1); assertEquals(0, ClassTypeHelper.getPureVirtualMethods(c).length); } + + // template struct CT1 {}; + // template struct CT2 {}; + // typedef char Tdef; + // template<> struct CT1< CT2 > { + // CT1 x; // Ambiguity causes lookup in CT1< CT2 > + // }; + // template<> struct CT2 { // Accessed before ambiguity is resolved + // }; + public void testAmbiguityResolution_Bug359364() throws Exception { + parseAndCheckBindings(); + } } 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 e9acad9167f..2fda9e95f00 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 @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.index.tests; @@ -48,8 +48,8 @@ public class IndexIncludeTest extends IndexTestBase { return suite; } - private ICProject fProject= null; - private IIndex fIndex= null; + private ICProject fProject; + private IIndex fIndex; public IndexIncludeTest(String name) { super(name); @@ -61,8 +61,8 @@ public class IndexIncludeTest extends IndexTestBase { if (fProject == null) { fProject= createProject(true, "resources/indexTests/includes"); IPathEntry[] entries= new IPathEntry[] { - CoreModel.newIncludeEntry(fProject.getPath(), - null, fProject.getResource().getLocation())}; + CoreModel.newIncludeEntry(fProject.getPath(), null, + fProject.getResource().getLocation()) }; fProject.setRawPathEntries(entries, npm()); } fIndex= CCorePlugin.getIndexManager().getIndex(fProject); @@ -141,7 +141,7 @@ public class IndexIncludeTest extends IndexTestBase { // #include public void testIncludeProperties() throws Exception { waitForIndexer(); - TestScannerProvider.sIncludes= new String[]{fProject.getProject().getLocation().toOSString()}; + TestScannerProvider.sIncludes= new String[] { fProject.getProject().getLocation().toOSString() }; String content= readTaggedComment("source20061107"); TestSourceReader.createFile(fProject.getProject(), "user20061107.h", ""); TestSourceReader.createFile(fProject.getProject(), "system20061107.h", ""); @@ -163,7 +163,7 @@ public class IndexIncludeTest extends IndexTestBase { } public void testIncludeProperties_2() throws Exception { - TestScannerProvider.sIncludes= new String[]{fProject.getProject().getLocation().toOSString()}; + TestScannerProvider.sIncludes= new String[] { fProject.getProject().getLocation().toOSString() }; TestSourceReader.createFile(fProject.getProject(), "header20061107.h", ""); String content = "// comment \n#include \"header20061107.h\"\n"; IFile file= TestSourceReader.createFile(fProject.getProject(), "intermed20061107.h", content); @@ -186,7 +186,7 @@ public class IndexIncludeTest extends IndexTestBase { } public void testInactiveInclude() throws Exception { - TestScannerProvider.sIncludes= new String[]{fProject.getProject().getLocation().toOSString()}; + TestScannerProvider.sIncludes= new String[] { fProject.getProject().getLocation().toOSString() }; String content = "#if 0\n#include \"inactive20070213.h\"\n#endif\n"; IFile file= TestSourceReader.createFile(fProject.getProject(), "source20070213.cpp", content); CCorePlugin.getIndexManager().reindex(fProject); @@ -207,7 +207,7 @@ public class IndexIncludeTest extends IndexTestBase { } public void testUnresolvedInclude() throws Exception { - TestScannerProvider.sIncludes= new String[]{fProject.getProject().getLocation().toOSString()}; + TestScannerProvider.sIncludes= new String[] { fProject.getProject().getLocation().toOSString() }; String content = "#include \"unresolved20070213.h\"\n"; IFile file= TestSourceReader.createFile(fProject.getProject(), "source20070214.cpp", content); CCorePlugin.getIndexManager().reindex(fProject); @@ -318,7 +318,7 @@ public class IndexIncludeTest extends IndexTestBase { // #include "resolved20070426.h" public void testFixedContext() throws Exception { - TestScannerProvider.sIncludes= new String[]{fProject.getProject().getLocation().toOSString()}; + TestScannerProvider.sIncludes= new String[] { fProject.getProject().getLocation().toOSString() }; String source= getContentsForTest(1)[0].toString(); IFile header= TestSourceReader.createFile(fProject.getProject(), "resolved20070426.h", ""); IFile s1= TestSourceReader.createFile(fProject.getProject(), "s1.cpp", source); @@ -404,7 +404,7 @@ public class IndexIncludeTest extends IndexTestBase { // #include "unesolved20070427.h" public void testUpdateIncludes() throws Exception { waitForIndexer(); - TestScannerProvider.sIncludes= new String[]{fProject.getProject().getLocation().toOSString()}; + TestScannerProvider.sIncludes= new String[] { fProject.getProject().getLocation().toOSString() }; CharSequence[] source= getContentsForTest(4); IFile header= TestSourceReader.createFile(fProject.getProject(), "resolved20070427.h", ""); IFile s1= TestSourceReader.createFile(fProject.getProject(), "s20070427.cpp", @@ -446,7 +446,6 @@ public class IndexIncludeTest extends IndexTestBase { source[0].toString() + "\nint h20070427;"); TestSourceReader.waitUntilFileIsIndexed(fIndex, s1, INDEXER_WAIT_TIME); standardCheckUpdateIncludes(header, s1, "h20070427"); - } private void standardCheckUpdateIncludes(IFile header, IFile s1, String tag) throws Exception { diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexNamesTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexNamesTests.java index 2b220298a8d..123318398e4 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexNamesTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexNamesTests.java @@ -6,9 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation *******************************************************************************/ - package org.eclipse.cdt.internal.index.tests; import java.io.IOException; @@ -129,8 +128,7 @@ public class IndexNamesTests extends BaseTestCase { enclosing= enclosed[1].getEnclosingDefinition(); assertNotNull(enclosing); assertName("main", enclosing); - } - finally { + } finally { fIndex.releaseReadLock(); } } @@ -223,8 +221,7 @@ public class IndexNamesTests extends BaseTestCase { enclosing= enclosed[2].getEnclosingDefinition(); assertNotNull(enclosing); assertName("func", enclosing); - } - finally { + } finally { fIndex.releaseReadLock(); } } @@ -274,8 +271,7 @@ public class IndexNamesTests extends BaseTestCase { assertEquals(couldbepolymorphic[j], indexName.couldBePolymorphicMethodCall()); assertEquals(container[j], CPPVisitor.getQualifiedName(fIndex.findBinding(indexName))[0]); j++; - } - else { + } else { assertEquals(false, indexName.couldBePolymorphicMethodCall()); } } @@ -285,7 +281,6 @@ public class IndexNamesTests extends BaseTestCase { } } - // int _i, ri, wi, rwi; // int* rp; int* wp; int* rwp; // const int* cip= &ri; @@ -339,14 +334,12 @@ public class IndexNamesTests extends BaseTestCase { assertEquals("Read access for " + msg, isRead, indexName.isReadAccess()); assertEquals("Write access for " + msg, isWrite, indexName.isWriteAccess()); j++; - } - else { + } else { assertEquals(false, indexName.couldBePolymorphicMethodCall()); } } assertEquals(count, j); - } - finally { + } finally { fIndex.releaseReadLock(); } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexUpdateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexUpdateTests.java index 879b11ef2e2..2f9a59e801a 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexUpdateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexUpdateTests.java @@ -1432,5 +1432,36 @@ public class IndexUpdateTests extends IndexTestBase { fIndex.releaseReadLock(); } } + + // struct S {}; + + // struct S {S(int){}}; + public void testImplicitDefaultCtor_Bug359376() throws Exception { + setupFile(2, true); + fIndex.acquireReadLock(); + try { + final ICPPClassType s = (ICPPClassType) findBinding("S"); + assertNotNull(s); + final ICPPConstructor[] ctors = s.getConstructors(); + assertEquals(2, ctors.length); // 2 implicit ctors + assertTrue(ctors[0].isImplicit()); + assertTrue(ctors[1].isImplicit()); + } finally { + fIndex.releaseReadLock(); + } + updateFile(); + + fIndex.acquireReadLock(); + try { + final ICPPClassType s = (ICPPClassType) findBinding("S"); + assertNotNull(s); + final ICPPConstructor[] ctors = s.getConstructors(); + assertEquals(2, ctors.length); // 1 explicit and one implicit ctor + assertTrue(ctors[0].isImplicit() != ctors[1].isImplicit()); + } finally { + fIndex.releaseReadLock(); + } + } + } diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java index ce685b82fae..6718f076766 100644 --- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java +++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java @@ -6,10 +6,9 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation - * Andrew Ferguson (Symbian) + * Markus Schorn - initial API and implementation + * Andrew Ferguson (Symbian) *******************************************************************************/ - package org.eclipse.cdt.core.testplugin.util; import java.io.BufferedReader; @@ -69,21 +68,22 @@ public class TestSourceReader { * test in the source code. * @throws IOException */ - public static StringBuilder[] getContentsForTest(Bundle bundle, String srcRoot, Class clazz, final String testName, int sections) throws IOException { + public static StringBuilder[] getContentsForTest(Bundle bundle, String srcRoot, Class clazz, + final String testName, int sections) throws IOException { String fqn = clazz.getName().replace('.', '/'); - fqn = fqn.indexOf("$")==-1 ? fqn : fqn.substring(0,fqn.indexOf("$")); + fqn = fqn.indexOf("$") == -1 ? fqn : fqn.substring(0, fqn.indexOf("$")); String classFile = fqn + ".java"; IPath filePath= new Path(srcRoot + '/' + classFile); InputStream in; try { - if (bundle != null) + if (bundle != null) { in = FileLocator.openStream(bundle, filePath, false); - else { - in = clazz.getResourceAsStream('/'+classFile); + } else { + in = clazz.getResourceAsStream('/' + classFile); } - } catch(IOException e) { - if(clazz.getSuperclass()!=null && !clazz.equals(TestCase.class)) { + } catch (IOException e) { + if (clazz.getSuperclass() != null && !clazz.equals(TestCase.class)) { return getContentsForTest(bundle, srcRoot, clazz.getSuperclass(), testName, sections); } throw e; @@ -91,30 +91,30 @@ public class TestSourceReader { BufferedReader br = new BufferedReader(new InputStreamReader(in)); - List contents = new ArrayList(); + List contents = new ArrayList(); StringBuilder content = new StringBuilder(); - for(String line = br.readLine(); line!=null; line = br.readLine()) { + for (String line = br.readLine(); line != null; line = br.readLine()) { line = line.replaceFirst("^\\s*", ""); // replace leading whitespace, preserve trailing - if(line.startsWith("//")) { - content.append(line.substring(2)+"\n"); + if (line.startsWith("//")) { + content.append(line.substring(2) + "\n"); } else { - if(content.length()>0) { + if (content.length() > 0) { contents.add(content); - if(contents.size()==sections+1) + if (contents.size() == sections + 1) contents.remove(0); content = new StringBuilder(); } int idx= line.indexOf(testName); - if( idx != -1 && !Character.isJavaIdentifierPart(line.charAt(idx+testName.length()))) { - return (StringBuilder[]) contents.toArray(new StringBuilder[contents.size()]); + if (idx != -1 && !Character.isJavaIdentifierPart(line.charAt(idx + testName.length()))) { + return contents.toArray(new StringBuilder[contents.size()]); } } } - if(clazz.getSuperclass()!=null && !clazz.equals(TestCase.class)) { + if (clazz.getSuperclass() != null && !clazz.equals(TestCase.class)) { return getContentsForTest(bundle, srcRoot, clazz.getSuperclass(), testName, sections); } - throw new IOException("Test data not found for "+clazz+" "+testName); + throw new IOException("Test data not found for " + clazz + " " + testName); } /** @@ -139,15 +139,15 @@ public class TestSourceReader { if (c == '\n') { int idx= buf.indexOf(lookfor); if (idx >= 0) { - return idx+offset; + return idx + offset; } - offset+=buf.length(); + offset += buf.length(); buf.setLength(0); } } int idx= buf.indexOf(lookfor); if (idx >= 0) { - return idx+offset; + return idx + offset; } return -1; } finally { @@ -196,8 +196,8 @@ public class TestSourceReader { } else { line= line.trim(); if (line.startsWith("{" + tag)) { - if (line.length() == tag.length()+1 || - !Character.isJavaIdentifierPart(line.charAt(tag.length()+1))) { + if (line.length() == tag.length() + 1 || + !Character.isJavaIdentifierPart(line.charAt(tag.length() + 1))) { found= true; } } @@ -207,8 +207,7 @@ public class TestSourceReader { } line= reader.readLine(); } - } - finally { + } finally { reader.close(); } Assert.assertTrue("Tag '" + tag + "' is not defined inside of '" + filePath + "'.", found); @@ -239,7 +238,7 @@ public class TestSourceReader { long timestamp= file.getLocalTimeStamp(); file.setContents(stream, false, false, new NullProgressMonitor()); if (file.getLocalTimeStamp() == timestamp) { - file.setLocalTimeStamp(timestamp+1000); + file.setLocalTimeStamp(timestamp + 1000); } } else { createFolders(file); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java index 5275241ab9d..285ad1ef1b9 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java @@ -71,8 +71,8 @@ final class DeltaProcessor { CModelInfo rootInfo = (CModelInfo)manager.peekAtInfo(root); if (rootInfo != null) { ICElement[] celements = rootInfo.getChildren(); - for (int i = 0; i < celements.length; i++) { - IResource r = celements[i].getResource(); + for (ICElement celement : celements) { + IResource r = celement.getResource(); if (project.equals(r)) { shouldProcess = true; } @@ -97,10 +97,10 @@ final class DeltaProcessor { IBinaryContainer bin = cproj.getBinaryContainer(); if (bin.isOpen()) { children = ((CElement)bin).getElementInfo().getChildren(); - for (int i = 0; i < children.length; i++) { - IResource res = children[i].getResource(); + for (ICElement element : children) { + IResource res = element.getResource(); if (resource.equals(res)) { - celement = children[i]; + celement = element; break; } } @@ -116,10 +116,10 @@ final class DeltaProcessor { IArchiveContainer ar = cproj.getArchiveContainer(); if (ar.isOpen()) { children = ((CElement)ar).getElementInfo().getChildren(); - for (int i = 0; i < children.length; i++) { - IResource res = children[i].getResource(); + for (ICElement element : children) { + IResource res = element.getResource(); if (resource.equals(res)) { - celement = children[i]; + celement = element; break; } } @@ -192,8 +192,8 @@ final class DeltaProcessor { if (pinfo != null && pinfo.vBin != null) { if (factory.peekAtInfo(pinfo.vBin) != null) { ICElement[] bins = pinfo.vBin.getChildren(); - for (int i = 0; i < bins.length; i++) { - if (celement.getPath().isPrefixOf(bins[i].getPath())) { + for (ICElement bin : bins) { + if (celement.getPath().isPrefixOf(bin.getPath())) { fCurrentDelta.changed(pinfo.vBin, ICElementDelta.CHANGED); } } @@ -202,8 +202,8 @@ final class DeltaProcessor { if (pinfo != null && pinfo.vLib != null) { if (factory.peekAtInfo(pinfo.vLib) != null) { ICElement[] ars = pinfo.vLib.getChildren(); - for (int i = 0; i < ars.length; i++) { - if (celement.getPath().isPrefixOf(ars[i].getPath())) { + for (ICElement ar : ars) { + if (celement.getPath().isPrefixOf(ar.getPath())) { fCurrentDelta.changed(pinfo.vBin, ICElementDelta.CHANGED); } } @@ -468,8 +468,8 @@ final class DeltaProcessor { } if (updateChildren){ IResourceDelta [] children = delta.getAffectedChildren(); - for (int i = 0; i < children.length; i++) { - traverseDelta(parent, children[i]); + for (IResourceDelta element : children) { + traverseDelta(parent, element); } } } @@ -506,10 +506,10 @@ final class DeltaProcessor { } // deal with project == sourceroot. For that case the parent could have been the sourceroot // so we must update the sourceroot nonCResource array also. - for (int i = 0; i < roots.length; i++) { - IResource r = roots[i].getResource(); + for (ISourceRoot root : roots) { + IResource r = root.getResource(); if (r instanceof IProject) { - CElementInfo cinfo = (CElementInfo) CModelManager.getDefault().peekAtInfo(roots[i]); + CElementInfo cinfo = (CElementInfo) CModelManager.getDefault().peekAtInfo(root); if (cinfo instanceof CContainerInfo) { ((CContainerInfo)cinfo).setNonCResources(null); } @@ -546,8 +546,8 @@ final class DeltaProcessor { if (delta.getKind() == IResourceDelta.ADDED) return true; IResourceDelta[] children= delta.getAffectedChildren(); - for (int i = 0; i < children.length; i++) { - if (isFolderAddition(children[i])) { + for (IResourceDelta element : children) { + if (isFolderAddition(element)) { return true; } } @@ -571,14 +571,18 @@ final class DeltaProcessor { if (element instanceof ICContainer) { ICContainer container = (ICContainer) element; ICProject cProject = container.getCProject(); + // Always check whether the container is open. + if (container.isOpen()) + return true; + + // Check binary container, if the new folder is on an output entry, + // there may be new binaries to add if (cProject.isOnOutputEntry(resource)) { - // if new folder is on output entry there might be new binaries to add IBinaryContainer bin = cProject.getBinaryContainer(); IArchiveContainer archive = cProject.getArchiveContainer(); - // traverse further if a binary container is open return bin.isOpen() || archive.isOpen(); } - return container.isOpen(); + return false; } else if (element instanceof ICProject) { return ((ICProject) element).isOpen(); } else if (element instanceof IBinary) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguityResolver.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguityResolver.java index 4fb6e5ec736..d31041261e3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguityResolver.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguityResolver.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import java.util.HashSet; import java.util.LinkedList; +import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; @@ -29,7 +30,10 @@ import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateSpecialization; import org.eclipse.cdt.internal.core.dom.parser.ASTAmbiguousNode; import org.eclipse.cdt.internal.core.dom.parser.ASTQueries; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics; @@ -101,6 +105,14 @@ final class CPPASTAmbiguityResolver extends ASTVisitor { public int leave(IASTDeclSpecifier declSpec) { if (declSpec instanceof ICPPASTCompositeTypeSpecifier) { fDeferFunctions--; + + // Resolve class type definitions, such that the scope is available + // during ambiguity resolution. + ((ICPPASTCompositeTypeSpecifier) declSpec).getName().resolveBinding(); + + // Trigger computation of implicit members. + if (declSpec instanceof CPPASTCompositeTypeSpecifier) + ((CPPASTCompositeTypeSpecifier) declSpec).setAmbiguitiesResolved(); } return PROCESS_CONTINUE; } @@ -128,17 +140,30 @@ final class CPPASTAmbiguityResolver extends ASTVisitor { if (fRepopulate.remove(declaration)) { repopulateScope(declaration); } - // Explicit and partial class template specializations need to be resolved right away, - // otherwise we fail to correctly resolve qualified names that depend on a partial specialization. + // We need to create class bindings for all definitions and for the specializations. + // Otherwise, name resolution cannot access members or correct specialization. if (declaration instanceof IASTSimpleDeclaration) { IASTSimpleDeclaration sdecl= (IASTSimpleDeclaration) declaration; + IASTName name= null; IASTDeclSpecifier declspec = sdecl.getDeclSpecifier(); - if (declspec instanceof IASTCompositeTypeSpecifier && sdecl.getDeclarators().length == 0) { - IASTName name= ((IASTCompositeTypeSpecifier) declspec).getName().getLastName(); - if (name instanceof ICPPASTTemplateId) { - name.resolveBinding(); + if (declspec instanceof IASTCompositeTypeSpecifier) { + // Definition of a class[template[specialization]] + name= ((IASTCompositeTypeSpecifier) declspec).getName().getLastName(); + } else if (declspec instanceof ICPPASTElaboratedTypeSpecifier + && sdecl.getDeclarators().length == 0) { + ASTNodeProperty prop = declaration.getPropertyInParent(); + if (prop == ICPPASTTemplateDeclaration.OWNED_DECLARATION + || prop == ICPPASTTemplateSpecialization.OWNED_DECLARATION) { + ICPPASTElaboratedTypeSpecifier elab= (ICPPASTElaboratedTypeSpecifier) declspec; + if (!elab.isFriend()) { + // Declaration of a class template specialization. + name= elab.getName().getLastName(); + } } } + if (name instanceof ICPPASTTemplateId) { + name.resolveBinding(); + } } return PROCESS_CONTINUE; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompositeTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompositeTypeSpecifier.java index 6209de3ac31..c7752367055 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompositeTypeSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompositeTypeSpecifier.java @@ -30,12 +30,13 @@ public class CPPASTCompositeTypeSpecifier extends CPPASTBaseDeclSpecifier private int fKey; private IASTName fName; - private ICPPClassScope fScope; + private CPPClassScope fScope; private IASTDeclaration[] fAllDeclarations; private IASTDeclaration[] fActiveDeclarations; private int fDeclarationsPos=-1; private ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier[] baseSpecs = null; private int baseSpecsPos = -1; + private boolean fAmbiguitiesResolved= false; public CPPASTCompositeTypeSpecifier() { @@ -46,6 +47,13 @@ public class CPPASTCompositeTypeSpecifier extends CPPASTBaseDeclSpecifier setName(n); } + public void setAmbiguitiesResolved() { + if (!fAmbiguitiesResolved && fScope != null) { + fScope.createImplicitMembers(); + } + fAmbiguitiesResolved= true; + } + public CPPASTCompositeTypeSpecifier copy() { return copy(CopyStyle.withoutLocations); } @@ -140,15 +148,15 @@ public class CPPASTCompositeTypeSpecifier extends CPPASTBaseDeclSpecifier } public ICPPClassScope getScope() { - if (fScope == null) + if (fScope == null) { fScope = new CPPClassScope(this); + if (fAmbiguitiesResolved) { + fScope.createImplicitMembers(); + } + } return fScope; } - - public void setScope(ICPPClassScope scope) { - this.fScope = scope; - } - + @Override public boolean accept(ASTVisitor action) { if (action.shouldVisitDeclSpecifiers) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateId.java index ae367bf1e92..44c7ab3c778 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateId.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateId.java @@ -15,8 +15,10 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; +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.IASTTypeId; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.ISemanticProblem; @@ -128,7 +130,11 @@ public class CPPASTTemplateId extends CPPASTNameBase implements ICPPASTTemplateI if (needComma) buf.append(", "); //$NON-NLS-1$ needComma= true; - if (arg instanceof IASTExpression) { + IASTNodeLocation[] nodeLocs = arg.getNodeLocations(); + if (nodeLocs.length == 1 && nodeLocs[0] instanceof IASTFileLocation) { + buf.append(arg.getRawSignature()); + cleanupWhitespace= true; + } else if (arg instanceof IASTExpression) { IValue value= Value.create((IASTExpression) arg, Value.MAX_RECURSION_DEPTH); if (value != Value.UNKNOWN && !Value.isDependentValue(value)) { buf.append(value.getSignature()); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java index 618c29500d2..382288893f0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java @@ -71,18 +71,18 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope { public CPPClassScope(ICPPASTCompositeTypeSpecifier physicalNode) { super(physicalNode); - ((CPPASTCompositeTypeSpecifier) physicalNode).setScope(this); - createImplicitMembers(); } public EScopeKind getKind() { return EScopeKind.eClassType; } - // 12.1 The default constructor, copy constructor, copy assignment operator, and destructor are - //special member functions. The implementation will implicitly declare these member functions - //for a class type when the program does not declare them. - private void createImplicitMembers() { + /** + * Add in default constructor, copy constructor, copy assignment operator and destructor, + * if appropriate. + * Method will be called after ambiguity resolution. + */ + public void createImplicitMembers() { //create bindings for the implicit members, if the user declared them then those declarations //will resolve to these bindings. ICPPASTCompositeTypeSpecifier compTypeSpec = (ICPPASTCompositeTypeSpecifier) getPhysicalNode(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java index 6e2447413ea..53a3453f8be 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java @@ -12,22 +12,15 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; -import org.eclipse.cdt.core.dom.ast.ASTVisitor; -import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; -import org.eclipse.cdt.core.dom.ast.IASTDeclaration; -import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; -import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IField; import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; @@ -35,7 +28,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPField; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; @@ -51,7 +43,6 @@ public class CPPClassSpecialization extends CPPSpecialization private ICPPClassSpecializationScope specScope; private ObjectMap specializationMap= ObjectMap.EMPTY_MAP; - private boolean checked; public CPPClassSpecialization(ICPPClassType specialized, IBinding owner, ICPPTemplateParameterMap argumentMap) { super(specialized, owner, argumentMap); @@ -82,84 +73,8 @@ public class CPPClassSpecialization extends CPPSpecialization } } - private class FindDeclarationDefinitionAction extends ASTVisitor { - private char [] nameArray = CPPClassSpecialization.this.getNameCharArray(); - public IASTName foundDef = null; - public IASTName foundDecl = null; - - { - shouldVisitNames = true; - shouldVisitDeclarations = true; - shouldVisitDeclSpecifiers = true; - shouldVisitDeclarators = true; - } - - @Override - public int visit(IASTName name) { - final IASTNode parent = name.getParent(); - final boolean isDef = parent instanceof ICPPASTCompositeTypeSpecifier; - final boolean isDecl = !isDef && parent instanceof ICPPASTElaboratedTypeSpecifier - && parent.getParent() instanceof IASTSimpleDeclaration; - if (isDef || isDecl) { - name= name.getLastName(); - if (CharArrayUtils.equals(name.getLookupKey(), nameArray)) { - IBinding binding = name.resolveBinding(); - if (binding == CPPClassSpecialization.this) { - if (isDef) { - foundDef= name; - return PROCESS_ABORT; - } - if (foundDecl == null) - foundDecl= name; - } - } - } - // Don't look at members of qualified names or template ids. - return PROCESS_SKIP; - } - - @Override - public int visit( IASTDeclaration declaration ){ - if(declaration instanceof IASTSimpleDeclaration || declaration instanceof ICPPASTTemplateDeclaration) - return PROCESS_CONTINUE; - return PROCESS_SKIP; - } - @Override - public int visit( IASTDeclSpecifier declSpec ){ - return (declSpec instanceof ICPPASTCompositeTypeSpecifier ) ? PROCESS_CONTINUE : PROCESS_SKIP; - } - @Override - public int visit( IASTDeclarator declarator ) { return PROCESS_SKIP; } - } - public void checkForDefinition() { - if( !checked && definition == null ) { - IBinding orig= getSpecializedBinding(); - IASTTranslationUnit tu= null; - while (orig != null) { - if (orig instanceof ICPPInternalBinding) { - IASTNode node= ((ICPPInternalBinding) orig).getDefinition(); - if (node != null) { - tu= node.getTranslationUnit(); - if (tu != null) - break; - } - } - if (!(orig instanceof ICPPSpecialization)) - break; - orig= ((ICPPSpecialization) orig).getSpecializedBinding(); - } - if (tu != null) { - FindDeclarationDefinitionAction action= new FindDeclarationDefinitionAction(); - tu.accept( action ); - definition = action.foundDef; - if (definition == null && action.foundDecl != null) { - addDeclaration(action.foundDecl); - } - } - checked = true; - } - return; + // Ambiguity resolution ensures that declarations and definitions are resolved. } public ICPPASTCompositeTypeSpecifier getCompositeTypeSpecifier() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplate.java index 409de0c5536..09640c55525 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplate.java @@ -14,14 +14,9 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; -import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.DOMException; -import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; -import org.eclipse.cdt.core.dom.ast.IASTDeclaration; -import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; -import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IField; @@ -31,8 +26,6 @@ import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate; @@ -46,9 +39,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.parser.util.ArrayUtil; -import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; -import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; /** * Represents a class template. @@ -58,56 +49,7 @@ public class CPPClassTemplate extends CPPTemplateDefinition implements ICPPClass private ICPPClassTemplate fIndexBinding= null; private boolean checkedIndex= false; - private boolean checkedDefinition= false; - private class FindDefinitionAction extends ASTVisitor { - private char[] nameArray = CPPClassTemplate.this.getNameCharArray(); - public IASTName result = null; - - FindDefinitionAction() { - shouldVisitNames = true; - shouldVisitDeclarations = true; - shouldVisitDeclSpecifiers = true; - shouldVisitDeclarators = true; - } - - @Override - public int visit(IASTName name) { - if (name instanceof ICPPASTTemplateId || name instanceof ICPPASTQualifiedName) - return PROCESS_CONTINUE; - char[] c = name.getLookupKey(); - if (name.getParent() instanceof ICPPASTTemplateId) - name = (IASTName) name.getParent(); - if (name.getParent() instanceof ICPPASTQualifiedName) { - IASTName[] ns = ((ICPPASTQualifiedName) name.getParent()).getNames(); - if (ns[ns.length - 1] != name) - return PROCESS_CONTINUE; - name = (IASTName) name.getParent(); - } - - if (name.getParent() instanceof ICPPASTCompositeTypeSpecifier && CharArrayUtils.equals(c, nameArray)) { - IBinding binding = name.resolveBinding(); - if (binding == CPPClassTemplate.this) { - result = name.getLastName(); - return PROCESS_ABORT; - } - } - return PROCESS_CONTINUE; - } - - @Override - public int visit(IASTDeclaration declaration) { - if (declaration instanceof IASTSimpleDeclaration || declaration instanceof ICPPASTTemplateDeclaration) - return PROCESS_CONTINUE; - return PROCESS_SKIP; - } - @Override - public int visit(IASTDeclSpecifier declSpec) { - return (declSpec instanceof ICPPASTCompositeTypeSpecifier) ? PROCESS_CONTINUE : PROCESS_SKIP; - } - @Override - public int visit(IASTDeclarator declarator) { return PROCESS_SKIP; } - } private ICPPClassTemplatePartialSpecialization[] partialSpecializations = null; private ICPPDeferredClassInstance fDeferredInstance; @@ -117,24 +59,7 @@ public class CPPClassTemplate extends CPPTemplateDefinition implements ICPPClass } public void checkForDefinition() { - if (checkedDefinition) - return; - - checkedDefinition= true; - if (definition != null) - return; - - FindDefinitionAction action = new FindDefinitionAction(); - IASTNode node = CPPVisitor.getContainingBlockItem(declarations[0]).getParent(); - while (node instanceof ICPPASTTemplateDeclaration) - node = node.getParent(); - node.accept(action); - definition = action.result; - - if (definition == null) { - node.getTranslationUnit().accept(action); - definition = action.result; - } + // Ambiguity resolution ensures that definitions are resolved. } public void addPartialSpecialization(ICPPClassTemplatePartialSpecialization spec) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java index f48af6c28ac..4b9064f2ef8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java @@ -15,16 +15,11 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ILinkage; -import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; -import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; -import org.eclipse.cdt.core.dom.ast.IASTDeclaration; -import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; -import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IField; import org.eclipse.cdt.core.dom.ast.IScope; @@ -33,8 +28,6 @@ import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; @@ -46,7 +39,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.parser.util.ArrayUtil; -import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.dom.Linkage; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; @@ -103,58 +95,6 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp } } - private class FindDefinitionAction extends ASTVisitor { - private char[] nameArray = CPPClassType.this.getNameCharArray(); - public IASTName result = null; - - { - shouldVisitNames = true; - shouldVisitDeclarations = true; - shouldVisitDeclSpecifiers = true; - shouldVisitDeclarators = true; - } - - @Override - public int visit(IASTName name) { - if (name instanceof ICPPASTTemplateId) - return PROCESS_SKIP; - if (name instanceof ICPPASTQualifiedName) - return PROCESS_CONTINUE; - char[] c = name.getLookupKey(); - - if (name.getParent() instanceof ICPPASTQualifiedName) { - IASTName[] ns = ((ICPPASTQualifiedName) name.getParent()).getNames(); - if (ns[ns.length - 1] != name) - return PROCESS_CONTINUE; - name = (IASTName) name.getParent(); - } - - if (name.getParent() instanceof ICPPASTCompositeTypeSpecifier && CharArrayUtils.equals(c, nameArray)) { - IBinding binding = name.resolveBinding(); - if (binding == CPPClassType.this) { - result= name.getLastName(); - return PROCESS_ABORT; - } - } - return PROCESS_CONTINUE; - } - - @Override - public int visit(IASTDeclaration declaration) { - if (declaration instanceof IASTSimpleDeclaration || declaration instanceof ICPPASTTemplateDeclaration) - return PROCESS_CONTINUE; - return PROCESS_SKIP; - } - @Override - public int visit(IASTDeclSpecifier declSpec) { - return (declSpec instanceof ICPPASTCompositeTypeSpecifier) ? PROCESS_CONTINUE : PROCESS_SKIP; - } - @Override - public int visit(IASTDeclarator declarator) { - return PROCESS_SKIP; - } - } - private IASTName definition; private IASTName[] declarations; private boolean checked = false; @@ -188,30 +128,16 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp } public void checkForDefinition() { - if (!checked && definition == null) { - FindDefinitionAction action = new FindDefinitionAction(); - IASTNode node = CPPVisitor.getContainingBlockItem(getPhysicalNode()).getParent(); - - if (node instanceof ICPPASTCompositeTypeSpecifier) - node = CPPVisitor.getContainingBlockItem(node.getParent()); - while(node instanceof ICPPASTTemplateDeclaration) - node = node.getParent(); - node.accept(action); - definition = action.result; - - if (definition == null) { - final IASTTranslationUnit translationUnit = node.getTranslationUnit(); - translationUnit.accept(action); - definition = action.result; - if (definition == null && typeInIndex == null) { - IIndex index= translationUnit.getIndex(); - if (index != null) { - typeInIndex= (ICPPClassType) index.adaptBinding(this); - } + // Ambiguity resolution ensures that definitions are resolved. + if (!checked) { + if (definition == null && typeInIndex == null) { + IIndex index= getPhysicalNode().getTranslationUnit().getIndex(); + if (index != null) { + typeInIndex= (ICPPClassType) index.adaptBinding(this); } } + checked = true; } - checked = true; } public ICPPASTCompositeTypeSpecifier getCompositeTypeSpecifier() { @@ -291,26 +217,30 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp } public void addDefinition(IASTNode node) { - if (node instanceof ICPPASTCompositeTypeSpecifier) + if (node instanceof ICPPASTCompositeTypeSpecifier) { definition = ((ICPPASTCompositeTypeSpecifier)node).getName(); + } else { + assert false; + } } public void addDeclaration(IASTNode node) { - if (!(node instanceof ICPPASTElaboratedTypeSpecifier)) - return; + if (node instanceof ICPPASTElaboratedTypeSpecifier) { + IASTName name = ((ICPPASTElaboratedTypeSpecifier) node).getName(); - IASTName name = ((ICPPASTElaboratedTypeSpecifier) node).getName(); + if (declarations == null) { + declarations = new IASTName[] { name }; + return; + } - if (declarations == null) { - declarations = new IASTName[] { name }; - return; - } - - // Keep the lowest offset declaration in [0] - if (declarations.length > 0 && ((ASTNode)node).getOffset() < ((ASTNode) declarations[0]).getOffset()) { - declarations = (IASTName[]) ArrayUtil.prepend(IASTName.class, declarations, name); + // Keep the lowest offset declaration in [0] + if (declarations.length > 0 && ((ASTNode)node).getOffset() < ((ASTNode) declarations[0]).getOffset()) { + declarations = (IASTName[]) ArrayUtil.prepend(IASTName.class, declarations, name); + } else { + declarations = (IASTName[]) ArrayUtil.append(IASTName.class, declarations, name); + } } else { - declarations = (IASTName[]) ArrayUtil.append(IASTName.class, declarations, name); + assert false; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java index c074fcfc1b0..5799476eeb0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java @@ -222,26 +222,29 @@ public class CPPVisitor extends ASTQueries { IASTNode parent = name.getParent(); IBinding binding = null; if (parent instanceof IASTNamedTypeSpecifier || - parent instanceof ICPPASTQualifiedName || parent instanceof ICPPASTBaseSpecifier || parent instanceof ICPPASTConstructorChainInitializer || name.getPropertyInParent() == ICPPASTNamespaceAlias.MAPPING_NAME) { if (name.getLookupKey().length == 0) return null; - - binding = CPPSemantics.resolveBinding(name); - if (binding instanceof IProblemBinding && parent instanceof ICPPASTQualifiedName && - !(parent.getParent() instanceof ICPPASTNamespaceAlias)) { - final ICPPASTQualifiedName qname = (ICPPASTQualifiedName) parent; - final IASTName[] ns = qname.getNames(); - if (ns[ns.length - 1] != name) - return binding; - - if (ns.length > 1 && ns[ns.length - 2].getBinding() instanceof IProblemBinding) - return binding; - - parent = parent.getParent(); - if (((IProblemBinding) binding).getID() == IProblemBinding.SEMANTIC_MEMBER_DECLARATION_NOT_FOUND) { + + return CPPSemantics.resolveBinding(name); + } else if (parent instanceof ICPPASTQualifiedName) { + if (name.getLookupKey().length == 0) + return null; + + final ICPPASTQualifiedName qname = (ICPPASTQualifiedName) parent; + if (name != qname.getLastName()) + return CPPSemantics.resolveBinding(name); + + parent = parent.getParent(); + binding = CPPSemantics.resolveBinding(name); + if (binding instanceof IProblemBinding && !(parent instanceof ICPPASTNamespaceAlias)) { + final IASTName[] ns = qname.getNames(); + if (ns.length > 1 && ns[ns.length - 2].getBinding() instanceof IProblemBinding) + return binding; + + if (((IProblemBinding) binding).getID() == IProblemBinding.SEMANTIC_MEMBER_DECLARATION_NOT_FOUND) { IASTNode node = getContainingBlockItem(name.getParent()); ASTNodeProperty prop= node.getPropertyInParent(); while (prop == ICPPASTTemplateDeclaration.OWNED_DECLARATION) { @@ -264,8 +267,13 @@ public class CPPVisitor extends ASTQueries { return binding; } } else { - if (binding instanceof ICPPClassType && binding instanceof IIndexBinding && name.isDefinition()) { - parent= parent.getParent(); // need to create an ast binding. + if (parent instanceof IASTCompositeTypeSpecifier) { + if (binding instanceof IIndexBinding) { + // Need to create an AST binding + } else { + ASTInternal.addDefinition(binding, parent); + return binding; + } } else { return binding; } @@ -428,7 +436,7 @@ public class CPPVisitor extends ASTQueries { (elabType.getName() instanceof ICPPASTQualifiedName || elabType.getKind() == IASTElaboratedTypeSpecifier.k_enum)) { return binding; } - + try { boolean template = false; ICPPScope scope = (ICPPScope) getContainingScope(name); @@ -457,21 +465,46 @@ public class CPPVisitor extends ASTQueries { } } } - if (!(binding instanceof ICPPInternalBinding) || !(binding instanceof ICPPClassType) && name.isActive()) { - if (elabType.getKind() != IASTElaboratedTypeSpecifier.k_enum) { - if (template) - binding = new CPPClassTemplate(name); - else - binding = new CPPClassType(name, binding); - // name may live in a different scope, so make sure to add it to the owner scope, as well. - ASTInternal.addName(scope, elabType.getName()); - } - } else { - if ((binding instanceof ICPPClassTemplate) == template) { - ASTInternal.addDeclaration(binding, elabType); - } else { - binding = new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_REDECLARATION); - } + if (binding instanceof ICPPInternalBinding) { + if (!name.isActive()) + return binding; + + if (binding instanceof ICPPClassType) { + final ICPPInternalBinding ib = (ICPPInternalBinding) binding; + if ((binding instanceof ICPPClassTemplate) == template) { + ib.addDeclaration(elabType); + return binding; + } + if (CPPSemantics.declaredBefore(binding, name, false)) { + return new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_REDECLARATION); + } + + // Mark the other declarations as problem and create the binding + final IASTNode[] decls = ib.getDeclarations(); + if (decls != null) { + for (IASTNode decl : decls) { + if (decl instanceof IASTName) { + final IASTName n = (IASTName) decl; + n.setBinding(new ProblemBinding(n, IProblemBinding.SEMANTIC_INVALID_REDECLARATION)); + } + } + } + IASTNode decl= ib.getDefinition(); + if (decl instanceof IASTName) { + final IASTName n = (IASTName) decl; + n.setBinding(new ProblemBinding(n, IProblemBinding.SEMANTIC_INVALID_REDEFINITION)); + } + } + } + + // Create a binding + if (elabType.getKind() != IASTElaboratedTypeSpecifier.k_enum) { + if (template) + binding = new CPPClassTemplate(name); + else + binding = new CPPClassType(name, binding); + // name may live in a different scope, so make sure to add it to the owner scope, as well. + ASTInternal.addName(scope, elabType.getName()); } } catch (DOMException e) { binding = e.getProblem(); @@ -2314,7 +2347,7 @@ public class CPPVisitor extends ASTQueries { } public static IBinding findNameOwner(IASTName name, boolean allowFunction) { - IASTNode node= name; + IASTNode node= name.getLastName(); while (node instanceof IASTName) { if (node instanceof ICPPASTQualifiedName) { IASTName[] qn= ((ICPPASTQualifiedName) node).getNames(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java index 53bbedadd8e..e9d85a73bd2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java @@ -85,6 +85,7 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceChangeEvent; +import org.eclipse.core.resources.ProjectScope; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; @@ -481,6 +482,8 @@ public class PDOMManager implements IWritableIndexManager, IListener { String newid= IndexerPreferences.get(prj, IndexerPreferences.KEY_INDEXER_ID, IPDOMManager.ID_NO_INDEXER); Properties props= IndexerPreferences.getProperties(prj); + // Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=359485 + synchronized (new ProjectScope(prj).getNode(CCorePlugin.PLUGIN_ID)) { synchronized (fUpdatePolicies) { if (fClosingProjects.contains(prj.getName())) { return; @@ -504,7 +507,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { } enqueue(new PDOMRebuildTask(indexer)); } - } + }} if (oldIndexer != null) { stopIndexer(oldIndexer); @@ -537,6 +540,8 @@ public class PDOMManager implements IWritableIndexManager, IListener { assert !Thread.holdsLock(fProjectToPDOM); try { + // Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=359485 + synchronized (new ProjectScope(prj).getNode(CCorePlugin.PLUGIN_ID)) { synchronized (fUpdatePolicies) { if (fClosingProjects.contains(name)) { if (fTraceIndexerSetup) @@ -586,12 +591,14 @@ public class PDOMManager implements IWritableIndexManager, IListener { } return; } - } + }} // rebuild is required, try import first. TeamPDOMImportOperation operation= new TeamPDOMImportOperation(project); operation.run(pm); + // Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=359485 + synchronized (new ProjectScope(prj).getNode(CCorePlugin.PLUGIN_ID)) { synchronized (fUpdatePolicies) { if (fClosingProjects.contains(name)) { if (fTraceIndexerSetup) @@ -618,7 +625,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { task= new PDOMRebuildTask(indexer); } enqueue(task); - } + }} } catch (CoreException e) { // Ignore if project is no longer open if (prj.isOpen()) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java index 8b7dab40caf..eb3c04ceb0e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java @@ -13,6 +13,8 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; +import java.util.ArrayList; +import java.util.Arrays; import java.util.LinkedList; import java.util.List; @@ -473,6 +475,13 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { final long fileLocalRec= type.getLocalToFileRec(); IScope scope = binding.getCompositeScope(); if (scope instanceof ICPPClassScope) { + List old= new ArrayList(); + if (type instanceof ICPPClassType) { + IScope oldScope = ((ICPPClassType)type).getCompositeScope(); + if (oldScope instanceof ICPPClassScope) { + old.addAll(Arrays.asList(((ICPPClassScope) oldScope).getImplicitMethods())); + } + } ICPPMethod[] implicit= ((ICPPClassScope) scope).getImplicitMethods(); for (ICPPMethod method : implicit) { if (!(method instanceof IProblemBinding)) { @@ -481,9 +490,14 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { pdomBinding = createBinding(type, method, fileLocalRec); } else if (!getPDOM().hasLastingDefinition(pdomBinding)) { pdomBinding.update(this, method); + old.remove(pdomBinding); } } } + for (ICPPMethod method : old) { + if (method instanceof PDOMBinding) + ((PDOMBinding) method).update(this, null); + } } } catch (DOMException e) { CCorePlugin.log(e); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethod.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethod.java index 0a5d2e03466..9262f137782 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethod.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethod.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2010 QNX Software Systems and others. + * Copyright (c) 2006, 2011 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 @@ -80,7 +80,7 @@ class PDOMCPPMethod extends PDOMCPPFunction implements ICPPMethod { } @Override - public void update(final PDOMLinkage linkage, IBinding newBinding) throws CoreException { + public final void update(final PDOMLinkage linkage, IBinding newBinding) throws CoreException { if (newBinding instanceof ICPPMethod) { ICPPMethod method= (ICPPMethod) newBinding; super.update(linkage, newBinding); @@ -92,6 +92,11 @@ class PDOMCPPMethod extends PDOMCPPFunction implements ICPPMethod { } catch (DOMException e) { throw new CoreException(Util.createStatus(e)); } + } else if (newBinding == null && isImplicit()) { + // Clear the implicit flag, such that the binding will no longer be picked up. + byte annot= (byte) (getAnnotation1() ^ (1 << PDOMCPPAnnotation.IMPLICIT_METHOD_OFFSET)); + getDB().putByte(record + ANNOTATION1, annot); + annotation1= annot; } } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/BaseUITestCase.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/BaseUITestCase.java index 56a7a7f0349..c0f5047458b 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/BaseUITestCase.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/BaseUITestCase.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.ui.tests; @@ -125,7 +125,7 @@ public class BaseUITestCase extends BaseTestCase { while (firstTime || System.currentTimeMillis() < endTime) { if (!firstTime) { Thread.sleep(sleep); - sleep= Math.min(250, sleep*2); + sleep= Math.min(250, sleep * 2); } firstTime= false; @@ -143,7 +143,7 @@ public class BaseUITestCase extends BaseTestCase { } } finally { index.releaseReadLock(); - int time= (int) (endTime- System.currentTimeMillis()); + int time= (int) (endTime - System.currentTimeMillis()); if (time > 0) { CCorePlugin.getIndexManager().joinIndexer(time, npm()); } @@ -153,10 +153,11 @@ public class BaseUITestCase extends BaseTestCase { } protected void runEventQueue(int time) { - final long endTime= System.currentTimeMillis()+time; - while(true) { - while (Display.getCurrent().readAndDispatch()); - long diff= endTime-System.currentTimeMillis(); + final long endTime= System.currentTimeMillis() + time; + while (true) { + while (Display.getCurrent().readAndDispatch()) + ; + long diff= endTime - System.currentTimeMillis(); if (diff <= 0) { break; } @@ -169,18 +170,18 @@ public class BaseUITestCase extends BaseTestCase { } protected void expandTreeItem(Tree tree, int idx) { - expandTreeItem(tree, new int[] {idx}); + expandTreeItem(tree, new int[] { idx }); } protected void expandTreeItem(Tree tree, int idx1, int idx2) { - expandTreeItem(tree, new int[] {idx1, idx2}); + expandTreeItem(tree, new int[] { idx1, idx2 }); } protected void expandTreeItem(Tree tree, int[] idxs) { TreeItem item= tree.getItem(idxs[0]); assertNotNull(item); expandTreeItem(item); - for (int i=1; i < idxs.length; i++) { + for (int i= 1; i < idxs.length; i++) { item= item.getItem(idxs[i]); assertNotNull(item); expandTreeItem(item); @@ -206,7 +207,7 @@ public class BaseUITestCase extends BaseTestCase { protected void selectTreeItem(Tree tree, int[] idxs) { TreeItem item= tree.getItem(idxs[0]); assertNotNull(item); - for (int i=1; i < idxs.length; i++) { + for (int i= 1; i < idxs.length; i++) { item= item.getItem(idxs[i]); assertNotNull(item); } @@ -317,7 +318,7 @@ public class BaseUITestCase extends BaseTestCase { final protected TreeItem checkTreeNode(Tree tree, int i0, String label) { TreeItem root= null; - for (int millis=0; millis < 5000; millis= millis==0 ? 1 : millis*2) { + for (int millis= 0; millis < 5000; millis= millis == 0 ? 1 : millis * 2) { runEventQueue(millis); try { root= tree.getItem(i0); @@ -340,7 +341,7 @@ public class BaseUITestCase extends BaseTestCase { String itemText= null; SWTException ex= null; String firstItemText= null; - for (int millis=0; millis < 5000; millis= millis==0 ? 1 : millis*2) { + for (int millis= 0; millis < 5000; millis= millis == 0 ? 1 : millis * 2) { runEventQueue(millis); TreeItem root= tree.getItem(i0); if (!root.getExpanded()) { diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/includebrowser/BasicIncludeBrowserTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/includebrowser/BasicIncludeBrowserTest.java index a4785eddcb2..6c82b07a5bf 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/includebrowser/BasicIncludeBrowserTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/includebrowser/BasicIncludeBrowserTest.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.ui.tests.includebrowser; @@ -34,13 +34,12 @@ public class BasicIncludeBrowserTest extends IncludeBrowserBaseTest { return suite(BasicIncludeBrowserTest.class); } - // // source // #include "user.h" // #include public void testSimpleInclusion() throws Exception { - TestScannerProvider.sIncludes= new String[]{getProject().getProject().getLocation().toOSString()}; + TestScannerProvider.sIncludes= new String[] { getProject().getProject().getLocation().toOSString() }; StringBuilder[] contents= getContentsForTest(1); IProject project= getProject().getProject(); @@ -55,7 +54,7 @@ public class BasicIncludeBrowserTest extends IncludeBrowserBaseTest { checkTreeNode(tree, 0, 0, "user.h"); checkTreeNode(tree, 0, 1, "system.h"); - // the tree has to be reversed + // The tree has to be reversed openIncludeBrowser(user, true); checkTreeNode(tree, 0, "user.h"); checkTreeNode(tree, 0, 0, "source.cpp"); @@ -72,9 +71,9 @@ public class BasicIncludeBrowserTest extends IncludeBrowserBaseTest { public void testInclusionAccrossProjects() throws Exception { ICProject op= CProjectHelper.createCCProject("__ibTest_other__", "bin", IPDOMManager.ID_FAST_INDEXER); try { - fIndex= CCorePlugin.getIndexManager().getIndex(new ICProject[] {getProject(), op}); + fIndex= CCorePlugin.getIndexManager().getIndex(new ICProject[] { getProject(), op }); - TestScannerProvider.sIncludes= new String[]{op.getProject().getLocation().toOSString()}; + TestScannerProvider.sIncludes= new String[] { op.getProject().getLocation().toOSString() }; StringBuilder[] contents= getContentsForTest(1); IFile user= createFile(op.getProject(), "user.h", ""); @@ -89,7 +88,7 @@ public class BasicIncludeBrowserTest extends IncludeBrowserBaseTest { checkTreeNode(tree, 0, 0, "user.h"); checkTreeNode(tree, 0, 1, "system.h"); - // the tree has to be reversed + // The tree has to be reversed openIncludeBrowser(user, true); checkTreeNode(tree, 0, "user.h"); checkTreeNode(tree, 0, 0, "source.cpp"); @@ -97,10 +96,8 @@ public class BasicIncludeBrowserTest extends IncludeBrowserBaseTest { openIncludeBrowser(system); checkTreeNode(tree, 0, "system.h"); checkTreeNode(tree, 0, 0, "source.cpp"); - } finally { CProjectHelper.delete(op); } } - } 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 fe3b3328ff9..6c92fbf840e 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 @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.ui.includebrowser; @@ -34,7 +34,6 @@ import org.eclipse.cdt.internal.ui.viewsupport.AsyncTreeContentProvider; * This is the content provider for the include browser. */ public class IBContentProvider extends AsyncTreeContentProvider { - private static final IProgressMonitor NPM = new NullProgressMonitor(); private boolean fComputeIncludedBy = true; @@ -66,7 +65,7 @@ public class IBContentProvider extends AsyncTreeContentProvider { return NO_CHILDREN; } } - // allow for async computation + // Allow for asynchronous computation return null; } @@ -98,8 +97,7 @@ public class IBContentProvider extends AsyncTreeContentProvider { IIndexInclude[] includes; if (fComputeIncludedBy) { includes= findIncludedBy(index, ifl, NPM); - } - else { + } else { includes= findIncludesTo(index, ifl, NPM); directiveFile= node.getRepresentedFile(); } @@ -110,13 +108,11 @@ public class IBContentProvider extends AsyncTreeContentProvider { try { if (fComputeIncludedBy) { directiveFile= targetFile= new IBFile(project, include.getIncludedByLocation()); - } - else { + } else { IIndexFileLocation includesPath= include.getIncludesLocation(); if (includesPath == null) { targetFile= new IBFile(include.getFullName()); - } - else { + } else { targetFile= new IBFile(project, includesPath); } } @@ -127,24 +123,20 @@ public class IBContentProvider extends AsyncTreeContentProvider { newnode.setIsActiveCode(include.isActive()); newnode.setIsSystemInclude(include.isSystemInclude()); result.add(newnode); - } - catch (CoreException e) { + } catch (CoreException e) { CUIPlugin.log(e); } } return result.toArray(); } - } - finally { + } finally { index.releaseReadLock(); } } return NO_CHILDREN; } - - public void setComputeIncludedBy(boolean value) { fComputeIncludedBy = value; } @@ -152,8 +144,7 @@ public class IBContentProvider extends AsyncTreeContentProvider { public boolean getComputeIncludedBy() { return fComputeIncludedBy; } - - + private IIndexInclude[] findIncludedBy(IIndex index, IIndexFileLocation ifl, IProgressMonitor pm) { try { if (ifl != null) { @@ -176,8 +167,7 @@ public class IBContentProvider extends AsyncTreeContentProvider { return list.toArray(new IIndexInclude[list.size()]); } } - } - catch (CoreException e) { + } catch (CoreException e) { CUIPlugin.log(e); } return new IIndexInclude[0]; @@ -205,8 +195,7 @@ public class IBContentProvider extends AsyncTreeContentProvider { return list.toArray(new IIndexInclude[list.size()]); } } - } - catch (CoreException e) { + } catch (CoreException e) { CUIPlugin.log(e); } return new IIndexInclude[0]; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBViewPart.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBViewPart.java index 62f18110555..5ab7c835746 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBViewPart.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBViewPart.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation - * Ed Swartz (Nokia) + * Markus Schorn - initial API and implementation + * Ed Swartz (Nokia) *******************************************************************************/ package org.eclipse.cdt.internal.ui.includebrowser; @@ -104,9 +104,7 @@ import org.eclipse.cdt.internal.ui.viewsupport.WorkingSetFilterUI; /** * The view part for the include browser. */ -public class IBViewPart extends ViewPart - implements IShowInSource, IShowInTarget, IShowInTargetList { - +public class IBViewPart extends ViewPart implements IShowInSource, IShowInTarget, IShowInTargetList { private static final int MAX_HISTORY_SIZE = 10; private static final String TRUE = "true"; //$NON-NLS-1$ private static final String FALSE = "false"; //$NON-NLS-1$ @@ -183,8 +181,7 @@ public class IBViewPart extends ViewPart if (CCorePlugin.getIndexManager().isIndexerIdle()) { setInputIndexerIdle(input); - } - else { + } else { setMessage(IBMessages.IBViewPart_waitingOnIndexerMessage); fSetInputJob.setInput(input); fSetInputJob.schedule(); @@ -202,8 +199,7 @@ public class IBViewPart extends ViewPart fIncludesToAction.setChecked(!isHeader); fIncludedByAction.setEnabled(false); updateSorter(); - } - else { + } else { fIncludedByAction.setEnabled(true); } fTreeViewer.setInput(input); @@ -349,14 +345,12 @@ public class IBViewPart extends ViewPart } } - @Override public void init(IViewSite site, IMemento memento) throws PartInitException { fMemento= memento; super.init(site, memento); } - @Override public void saveState(IMemento memento) { putDialogSettings(); @@ -501,8 +495,7 @@ public class IBViewPart extends ViewPart public void run() { if (isChecked()) { fTreeViewer.addFilter(fInactiveFilter); - } - else { + } else { fTreeViewer.removeFilter(fInactiveFilter); } } @@ -525,8 +518,7 @@ public class IBViewPart extends ViewPart public void run() { if (isChecked()) { fTreeViewer.addFilter(fSystemFilter); - } - else { + } else { fTreeViewer.removeFilter(fSystemFilter); } } @@ -675,8 +667,7 @@ public class IBViewPart extends ViewPart private void updateSorter() { if (fIncludedByAction.isChecked()) { fTreeViewer.setComparator(fSorterAlphaNumeric); - } - else { + } else { fTreeViewer.setComparator(fSorterReferencePosition); } } @@ -693,15 +684,13 @@ public class IBViewPart extends ViewPart file= path.lastSegment() + "(" + path.removeLastSegments(1) + ")"; //$NON-NLS-1$//$NON-NLS-2$ if (fWorkingSetFilter == null) { scope= IBMessages.IBViewPart_workspaceScope; - } - else { + } else { scope= fWorkingSetFilter.getLabel(); } if (fIncludedByAction.isChecked()) { format= IBMessages.IBViewPart_IncludedByContentDescription; - } - else { + } else { format= IBMessages.IBViewPart_IncludesToContentDescription; } message= Messages.format(format, file, scope); @@ -717,12 +706,10 @@ public class IBViewPart extends ViewPart fTreeViewer.removeFilter(fWorkingSetFilter); fWorkingSetFilter= null; } - } - else { + } else { if (fWorkingSetFilter != null) { fTreeViewer.refresh(); - } - else { + } else { fWorkingSetFilter= new IBWorkingSetFilter(filterUI); fTreeViewer.addFilter(fWorkingSetFilter); } @@ -777,7 +764,6 @@ public class IBViewPart extends ViewPart } }); } - } } m.add(new Separator(IContextMenuConstants.GROUP_ADDITIONS)); @@ -797,8 +783,7 @@ public class IBViewPart extends ViewPart IFile f= ibf.getResource(); if (f != null) { EditorOpener.open(page, f, region, timestamp); - } - else { + } else { IIndexFileLocation ifl = ibf.getLocation(); if (ifl != null) { IPath location= IndexLocationFactory.getAbsolutePath(ifl); @@ -807,8 +792,7 @@ public class IBViewPart extends ViewPart } } } - } - else { + } else { ITranslationUnit tu= IBConversions.selectionToTU(selection); if (tu != null) { IResource r= tu.getResource(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IncludeBrowserUI.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IncludeBrowserUI.java index cc81a5971bb..0421681c7a8 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IncludeBrowserUI.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IncludeBrowserUI.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.ui.includebrowser; @@ -39,7 +39,7 @@ public class IncludeBrowserUI { ITranslationUnit tu= convertToTranslationUnit(input); if (tu != null) { IWorkbenchPage page= window.getActivePage(); - IBViewPart result= (IBViewPart)page.showView(CUIPlugin.ID_INCLUDE_BROWSER); + IBViewPart result= (IBViewPart) page.showView(CUIPlugin.ID_INCLUDE_BROWSER); result.setInput(tu); } } catch (CoreException e) { @@ -52,7 +52,7 @@ public class IncludeBrowserUI { public static void open(final ITextEditor editor, final ITextSelection sel) { if (editor != null) { ICElement inputCElement = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editor.getEditorInput()); - open (editor.getSite().getWorkbenchWindow(), inputCElement); + open(editor.getSite().getWorkbenchWindow(), inputCElement); } } @@ -80,8 +80,7 @@ public class IncludeBrowserUI { return CoreModelUtil.findTranslationUnitForLocation(loc, project); } } - } - finally { + } finally { index.releaseReadLock(); } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/AbstractLangsListTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/AbstractLangsListTab.java index f99a7040885..5706b7ce4b0 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/AbstractLangsListTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/AbstractLangsListTab.java @@ -423,15 +423,15 @@ public abstract class AbstractLangsListTab extends AbstractCPropertyTab { private String getLanguageName(ICLanguageSetting langSetting) { String langId = langSetting.getLanguageId(); String langName = null; - if (langId != null && !langId.isEmpty()) { + if (langId != null && langId.length() != 0) { // Bug #178033: get language name via LangManager. ILanguageDescriptor langDes = LanguageManager.getInstance().getLanguageDescriptor(langId); if (langDes != null) langName = langDes.getName(); } - if (langName == null || langName.isEmpty()) + if (langName == null || langName.length() == 0) langName = langSetting.getName(); - if (langName == null || langName.isEmpty()) + if (langName == null || langName.length() == 0) langName = langId; return langName; }