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

Fixes a few JUnit test failures.

This commit is contained in:
Markus Schorn 2012-01-04 12:14:50 +01:00
parent 463d52d01b
commit e560beb08a
10 changed files with 115 additions and 41 deletions

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008 Symbian Software Systems and others.
* Copyright (c) 2008, 2012 Symbian 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
@ -86,7 +86,8 @@ public class SemanticsTests extends AST2BaseTest {
// operator A(); // conversion
// operator B(); // conversion
// };
public void testGetDeclaredConversionOperators() throws Exception {
public void testConversionOperators() throws Exception {
// Test getDeclaredConversionOperators()
BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true);
ICPPClassType c= ba.assertNonProblem("X {", 1, ICPPClassType.class);
ICPPMethod[] cops= SemanticUtil.getDeclaredConversionOperators(c);
@ -96,11 +97,8 @@ public class SemanticsTests extends AST2BaseTest {
Set expected= new HashSet();
expected.add("operator A"); expected.add("operator B");
assertEquals(expected, actual);
}
public void testIsConversionOperator() throws Exception {
BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true);
ICPPClassType c= ba.assertNonProblem("X {", 1, ICPPClassType.class);
// Test isConversionOperator()
ICPPMethod[] dms= c.getDeclaredMethods();
assertEquals(48, dms.length);

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007, 2010 Symbian Software Systems and others.
* Copyright (c) 2007, 2012 Symbian 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
@ -283,9 +283,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
assertInstance(b0, ICPPMethod.class);
assertEquals(1, getIndex().findNames(b0, IIndex.FIND_REFERENCES).length);
IParameter[] parameters = ((ICPPMethod) b0).getParameters();
System.out.println(String.valueOf(parameters));
IFunctionType type = ((ICPPMethod) b0).getType();
System.out.println(String.valueOf(type));
}
// template<typename T>

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2010 Wind River Systems, Inc. and others.
* Copyright (c) 2008, 2012 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -12,6 +12,7 @@
package org.eclipse.cdt.core.index;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.internal.core.index.IIndexFragment;
import org.eclipse.cdt.internal.core.index.IndexFileSet;
import org.eclipse.core.runtime.CoreException;
@ -60,4 +61,11 @@ public interface IIndexFileSet {
* @noreference This method is not intended to be referenced by clients.
*/
void remove(IIndexFile indexFile);
/**
* Checks whether the given binding has a non-local declaration in
* another index fragment.
* @noreference This method is not intended to be referenced by clients.
*/
boolean containsNonLocalDeclaration(IBinding binding, IIndexFragment ignore);
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2011 Wind River Systems, Inc. and others.
* Copyright (c) 2006, 2012 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.dom.parser;
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.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IScope;
@ -22,6 +23,7 @@ import org.eclipse.cdt.internal.core.dom.parser.c.ICInternalBinding;
import org.eclipse.cdt.internal.core.dom.parser.c.ICInternalFunction;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction;
import org.eclipse.cdt.internal.core.index.IIndexFragment;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.core.runtime.CoreException;
@ -72,7 +74,7 @@ public class ASTInternal {
}
}
public static IASTNode getDeclaredInSourceFileOnly(IBinding binding, boolean requireDefinition, PDOMBinding nonLocal) {
public static IASTNode getDeclaredInSourceFileOnly(IIndexFragment forFragment, IBinding binding, boolean requireDefinition, PDOMBinding nonLocal) {
IASTNode[] decls;
IASTNode def;
if (binding instanceof ICPPInternalBinding) {
@ -105,6 +107,9 @@ public class ASTInternal {
}
}
}
if (result == null)
return null;
if (requireDefinition && nonLocal != null) {
try {
if (nonLocal.hasDeclaration())
@ -112,6 +117,12 @@ public class ASTInternal {
} catch (CoreException e) {
}
}
IASTTranslationUnit tu= result.getTranslationUnit();
if (tu != null) {
if (tu.getIndexFileSet().containsNonLocalDeclaration(binding, forFragment))
return null;
}
return result;
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2011 Wind River Systems, Inc. and others.
* Copyright (c) 2006, 2012 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -58,6 +58,7 @@ public interface IIndexFragment {
*/
final int FIND_ALL_OCCURRENCES = IIndex.FIND_ALL_OCCURRENCES;
final int FIND_NON_LOCAL_ONLY= 0x10000;
/**
* Property key for the fragment ID. The fragment ID should uniquely identify the fragments
* usage within a logical index.
@ -223,8 +224,8 @@ public interface IIndexFragment {
* Searches for all names that resolve to the given binding. You can limit the result to
* references, declarations or definitions, or a combination of those.
* @param binding a binding for which names are searched for
* @param flags a combination of {@link #FIND_DECLARATIONS}, {@link #FIND_DEFINITIONS} and
* {@link #FIND_REFERENCES}
* @param flags a combination of {@link #FIND_DECLARATIONS}, {@link #FIND_DEFINITIONS},
* {@link #FIND_REFERENCES} and {@link #FIND_NON_LOCAL_ONLY}
* @return an array of names
* @throws CoreException
*/

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2010 Wind River Systems, Inc. and others.
* Copyright (c) 2008, 2012 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -29,6 +29,7 @@ public class IndexFileSet implements IIndexFileSet {
public IndexFileSet() {
}
@Override
public void add(IIndexFile indexFile) {
final IIndexFragmentFile fragFile = (IIndexFragmentFile) indexFile;
final IIndexFragment frag= fragFile.getIndexFragment();
@ -40,6 +41,7 @@ public class IndexFileSet implements IIndexFileSet {
subSet.add(fragFile);
}
@Override
public void remove(IIndexFile indexFile) {
final IIndexFragmentFile fragFile = (IIndexFragmentFile) indexFile;
final IIndexFragment frag= fragFile.getIndexFragment();
@ -49,21 +51,16 @@ public class IndexFileSet implements IIndexFileSet {
}
}
@Override
public boolean containsDeclaration(IIndexBinding binding) {
return containsDeclaration(binding, false);
}
boolean containsDeclaration(IIndexBinding binding, boolean inverse) {
for (Map.Entry<IIndexFragment, IIndexFragmentFileSet> entry : fSubSets.entrySet()) {
try {
IIndexFragmentName[] names =
entry.getKey().findNames(binding, IIndexFragment.FIND_DECLARATIONS_DEFINITIONS);
for (IIndexFragmentName name : names) {
try {
final boolean foundDecl = entry.getValue().contains((IIndexFragmentFile) name.getFile());
if (foundDecl != inverse) {
if (entry.getValue().contains((IIndexFragmentFile) name.getFile()))
return true;
}
} catch (CoreException e) {
CCorePlugin.log(e);
}
@ -75,6 +72,33 @@ public class IndexFileSet implements IIndexFileSet {
return false;
}
@Override
public boolean containsNonLocalDeclaration(IBinding binding, IIndexFragment ignore) {
for (Map.Entry<IIndexFragment, IIndexFragmentFileSet> entry : fSubSets.entrySet()) {
try {
final IIndexFragment fragment = entry.getKey();
final IIndexFragmentFileSet subset = entry.getValue();
if (fragment != ignore) {
IIndexFragmentName[] names =
fragment.findNames(binding, IIndexFragment.FIND_DECLARATIONS_DEFINITIONS | IIndexFragment.FIND_NON_LOCAL_ONLY);
for (IIndexFragmentName name : names) {
try {
if (subset.contains((IIndexFragmentFile) name.getFile())) {
return true;
}
} catch (CoreException e) {
CCorePlugin.log(e);
}
}
}
} catch (CoreException e) {
CCorePlugin.log(e);
}
}
return false;
}
@Override
public IBinding[] filterFileLocalBindings(IBinding[] bindings) {
return filterFileLocalBindings(bindings, false);
}
@ -131,6 +155,7 @@ public class IndexFileSet implements IIndexFileSet {
return result;
}
@Override
public boolean contains(IIndexFile file) throws CoreException {
return contains(file, false);
}
@ -150,29 +175,40 @@ public class IndexFileSet implements IIndexFileSet {
/* (non-Javadoc)
* @see org.eclipse.cdt.core.index.IIndexFileSet#invert()
*/
@Override
public IIndexFileSet invert() {
if (fInverse == null) {
fInverse= new IIndexFileSet() {
@Override
public IIndexFileSet invert() {
return IndexFileSet.this;
}
@Override
public IBinding[] filterFileLocalBindings(IBinding[] bindings) {
return IndexFileSet.this.filterFileLocalBindings(bindings, true);
}
@Override
public boolean containsDeclaration(IIndexBinding binding) {
return IndexFileSet.this.containsDeclaration(binding, true);
throw new UnsupportedOperationException();
}
@Override
public boolean containsNonLocalDeclaration(IBinding binding, IIndexFragment ignore) {
throw new UnsupportedOperationException();
}
@Override
public boolean contains(IIndexFile file) throws CoreException {
return IndexFileSet.this.contains(file, true);
}
@Override
public void add(IIndexFile indexFile) {
Assert.isLegal(false);
}
@Override
public void remove(IIndexFile indexFile) {
Assert.isLegal(false);
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2011 QNX Software Systems and others.
* Copyright (c) 2005, 2012 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
@ -532,7 +532,7 @@ public class PDOM extends PlatformObject implements IPDOM {
if (binding != null) {
PDOMLinkage linkage= adaptLinkage(name.getLinkage());
if (linkage != null) {
return findBindingInLinkage(linkage, binding);
return findBindingInLinkage(linkage, binding, true);
}
} else if (name.getPropertyInParent() == IASTPreprocessorStatement.MACRO_NAME) {
PDOMLinkage linkage= adaptLinkage(name.getLinkage());
@ -993,6 +993,10 @@ public class PDOM extends PlatformObject implements IPDOM {
@Override
public IIndexFragmentBinding adaptBinding(IBinding binding) throws CoreException {
return adaptBinding(binding, true);
}
private IIndexFragmentBinding adaptBinding(IBinding binding, boolean includeLocal) throws CoreException {
if (binding == null) {
return null;
}
@ -1003,16 +1007,16 @@ public class PDOM extends PlatformObject implements IPDOM {
PDOMLinkage linkage= adaptLinkage(binding.getLinkage());
if (linkage != null) {
return findBindingInLinkage(linkage, binding);
return findBindingInLinkage(linkage, binding, includeLocal);
}
return null;
}
private IIndexFragmentBinding findBindingInLinkage(PDOMLinkage linkage, IBinding binding) throws CoreException {
private IIndexFragmentBinding findBindingInLinkage(PDOMLinkage linkage, IBinding binding, boolean includeLocal) throws CoreException {
if (binding instanceof IMacroBinding || binding instanceof IIndexMacroContainer) {
return linkage.findMacroContainer(binding.getNameCharArray());
}
return linkage.adaptBinding(binding);
return linkage.adaptBinding(binding, includeLocal);
}
public IIndexFragmentBinding findBinding(IIndexFragmentName indexName) throws CoreException {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2011 QNX Software Systems and others.
* Copyright (c) 2005, 2012 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
@ -146,9 +146,11 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
getIndex().accept((IBTreeVisitor) visitor);
} else {
getIndex().accept(new IBTreeVisitor() {
@Override
public int compare(long record) throws CoreException {
return 0;
}
@Override
public boolean visit(long record) throws CoreException {
PDOMNode node= getNode(record);
if (node != null) {
@ -217,7 +219,11 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
return (PDOMBinding) fPDOM.getCachedResult(binding);
}
public abstract PDOMBinding adaptBinding(IBinding binding) throws CoreException;
public final PDOMBinding adaptBinding(IBinding binding) throws CoreException {
return adaptBinding(binding, true);
}
public abstract PDOMBinding adaptBinding(IBinding binding, boolean includeLocal) throws CoreException;
public abstract PDOMBinding addBinding(IASTName name) throws CoreException;
@ -256,7 +262,7 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
}
if (checkIfInSourceOnly) {
IASTNode node= ASTInternal.getDeclaredInSourceFileOnly(binding, requireDefinition, glob);
IASTNode node= ASTInternal.getDeclaredInSourceFileOnly(getPDOM(), binding, requireDefinition, glob);
if (node != null) {
return wpdom.getFileForASTNode(getLinkageID(), node);
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2010 QNX Software Systems and others.
* Copyright (c) 2006, 2012 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
@ -62,10 +62,12 @@ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants {
return LINKAGE;
}
@Override
public String getLinkageName() {
return C_LINKAGE_NAME;
}
@Override
public int getLinkageID() {
return C_LINKAGE_ID;
}
@ -226,8 +228,8 @@ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants {
}
@Override
public final PDOMBinding adaptBinding(final IBinding inputBinding) throws CoreException {
return adaptBinding(null, inputBinding, FILE_LOCAL_REC_DUMMY);
public final PDOMBinding adaptBinding(final IBinding inputBinding, boolean includeLocal) throws CoreException {
return adaptBinding(null, inputBinding, includeLocal ? FILE_LOCAL_REC_DUMMY : null);
}
private final PDOMBinding adaptBinding(final PDOMNode parent, IBinding inputBinding, long[] localToFileHolder) throws CoreException {
@ -264,6 +266,9 @@ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants {
final int[] bindingTypes = new int[] {getBindingType(binding)};
final char[] nameChars = binding.getNameCharArray();
PDOMBinding nonLocal= FindBinding.findBinding(getIndex(), this, nameChars, bindingTypes, 0);
if (localToFileHolder == null)
return nonLocal;
long localToFileRec= getLocalToFileRec(parent, binding, nonLocal);
if (localToFileRec == 0)
return nonLocal;
@ -274,6 +279,9 @@ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants {
final int[] bindingTypes = new int[] {getBindingType(binding)};
final char[] nameChars = binding.getNameCharArray();
PDOMBinding nonLocal= FindBinding.findBinding(parent, this, nameChars, bindingTypes, 0);
if (localToFileHolder == null)
return nonLocal;
long localToFileRec= getLocalToFileRec(parent, binding, nonLocal);
if (localToFileRec == 0)
return nonLocal;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2011 QNX Software Systems and others.
* Copyright (c) 2005, 2012 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
@ -609,8 +609,8 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
}
@Override
public final PDOMBinding adaptBinding(final IBinding inputBinding) throws CoreException {
return adaptBinding(null, inputBinding, FILE_LOCAL_REC_DUMMY);
public final PDOMBinding adaptBinding(final IBinding inputBinding, boolean includeLocal) throws CoreException {
return adaptBinding(null, inputBinding, includeLocal ? FILE_LOCAL_REC_DUMMY : null);
}
private final PDOMBinding adaptBinding(final PDOMNode parent, IBinding inputBinding, long[] fileLocalRecHolder) throws CoreException {
@ -661,6 +661,8 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
}
if (parent == this) {
PDOMBinding glob= CPPFindBinding.findBinding(getIndex(), this, binding, 0);
if (fileLocalRecHolder == null)
return glob;
final long loc= getLocalToFileRec(parent, binding, glob);
if (loc == 0)
return glob;
@ -670,6 +672,8 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
if (parent instanceof PDOMCPPNamespace) {
final BTree btree = ((PDOMCPPNamespace) parent).getIndex();
PDOMBinding glob= CPPFindBinding.findBinding(btree, this, binding, 0);
if (fileLocalRecHolder == null)
return glob;
final long loc= getLocalToFileRec(parent, binding, glob);
if (loc == 0)
return glob;
@ -993,7 +997,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
file= wpdom.getFileForASTNode(getLinkageID(), node);
}
} else if (binding instanceof ICPPNamespaceAlias) {
IASTNode node= ASTInternal.getDeclaredInSourceFileOnly(binding, false, glob);
IASTNode node= ASTInternal.getDeclaredInSourceFileOnly(getPDOM(), binding, false, glob);
if (node != null) {
file= wpdom.getFileForASTNode(getLinkageID(), node);
}
@ -1002,7 +1006,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
IBinding owner= binding.getOwner();
if (owner instanceof ICPPNamespace) {
if (owner.getNameCharArray().length == 0) {
IASTNode node= ASTInternal.getDeclaredInSourceFileOnly(owner, false, glob);
IASTNode node= ASTInternal.getDeclaredInSourceFileOnly(getPDOM(), owner, false, glob);
if (node != null) {
file= wpdom.getFileForASTNode(getLinkageID(), node);
}