mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-13 19:25:38 +02:00
Cosmetics
Change-Id: I32405afb8267377b8bf0465bbd8bdd46c8e8839d
This commit is contained in:
parent
a43f45e711
commit
5003622cbf
1 changed files with 21 additions and 35 deletions
|
@ -14,9 +14,6 @@ package org.eclipse.cdt.internal.pdom.tests;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import junit.framework.AssertionFailedError;
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ILinkage;
|
import org.eclipse.cdt.core.dom.ILinkage;
|
||||||
import org.eclipse.cdt.core.dom.IName;
|
import org.eclipse.cdt.core.dom.IName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||||
|
@ -38,16 +35,16 @@ import org.eclipse.cdt.internal.core.index.IIndexFragmentName;
|
||||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
import org.eclipse.jface.text.BadLocationException;
|
import org.eclipse.jface.text.BadLocationException;
|
||||||
|
|
||||||
|
import junit.framework.AssertionFailedError;
|
||||||
|
import junit.framework.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that PDOM correctly track declarations, definitions and references of
|
* Test that PDOM correctly track declarations, definitions and references of objects.
|
||||||
* objects
|
|
||||||
*
|
*
|
||||||
* @author ELaskavaia@qnx.com
|
* @author ELaskavaia@qnx.com
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class DefDeclTests extends PDOMTestBase {
|
public class DefDeclTests extends PDOMTestBase {
|
||||||
private String projectName = null;
|
private String projectName = null;
|
||||||
|
@ -72,36 +69,31 @@ public class DefDeclTests extends PDOMTestBase {
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
pdom.releaseReadLock();
|
pdom.releaseReadLock();
|
||||||
if (cproject != null) {
|
if (cproject != null) {
|
||||||
cproject.getProject().delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, new NullProgressMonitor());
|
cproject.getProject().delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IBinding findSingleBinding(String elName) throws CoreException {
|
private IBinding findSingleBinding(String elName) throws CoreException {
|
||||||
IBinding[] binds = pdom.findBindings(Pattern.compile(elName), true,
|
IBinding[] binds = pdom.findBindings(Pattern.compile(elName), true, IndexFilter.ALL, null);
|
||||||
IndexFilter.ALL, new NullProgressMonitor());
|
|
||||||
assertEquals(1, binds.length);
|
assertEquals(1, binds.length);
|
||||||
assertEquals(elName, binds[0].getName());
|
assertEquals(elName, binds[0].getName());
|
||||||
IBinding element = binds[0];
|
IBinding element = binds[0];
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkReference(IBinding element, String mark, int checkCount)
|
private void checkReference(IBinding element, String mark, int checkCount) throws Exception {
|
||||||
throws Exception {
|
|
||||||
checkUsage(element, mark, checkCount, IIndex.FIND_REFERENCES);
|
checkUsage(element, mark, checkCount, IIndex.FIND_REFERENCES);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkDeclaration(IBinding element, String mark, int num)
|
private void checkDeclaration(IBinding element, String mark, int num) throws Exception {
|
||||||
throws Exception {
|
|
||||||
checkUsage(element, mark, num, IIndex.FIND_DECLARATIONS);
|
checkUsage(element, mark, num, IIndex.FIND_DECLARATIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkDefinition(IBinding element, String mark, int countNum)
|
private void checkDefinition(IBinding element, String mark, int countNum) throws Exception {
|
||||||
throws Exception {
|
|
||||||
checkUsage(element, mark, countNum, IIndex.FIND_DEFINITIONS);
|
checkUsage(element, mark, countNum, IIndex.FIND_DEFINITIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkUsage(IBinding element, String mark, int countNum,
|
private void checkUsage(IBinding element, String mark, int countNum, int flags) throws Exception {
|
||||||
int flags) throws Exception {
|
|
||||||
if (mark == null || countNum == 0) {
|
if (mark == null || countNum == 0) {
|
||||||
getFirstUsage(element, 0, flags);
|
getFirstUsage(element, 0, flags);
|
||||||
} else {
|
} else {
|
||||||
|
@ -123,8 +115,7 @@ public class DefDeclTests extends PDOMTestBase {
|
||||||
}
|
}
|
||||||
int nodeLine = getLineNumber(loc.getNodeOffset(), fileName);
|
int nodeLine = getLineNumber(loc.getNodeOffset(), fileName);
|
||||||
if (markLine != nodeLine) {
|
if (markLine != nodeLine) {
|
||||||
fail = "Marker at line " + markLine + ", actual at line "
|
fail = "Marker at line " + markLine + ", actual at line " + nodeLine;
|
||||||
+ nodeLine;
|
|
||||||
} else {
|
} else {
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
|
@ -143,8 +134,7 @@ public class DefDeclTests extends PDOMTestBase {
|
||||||
* @return first references or null of non
|
* @return first references or null of non
|
||||||
* @throws CoreException
|
* @throws CoreException
|
||||||
*/
|
*/
|
||||||
private IName getFirstUsage(IBinding binding, int k, int flags)
|
private IName getFirstUsage(IBinding binding, int k, int flags) throws CoreException {
|
||||||
throws CoreException {
|
|
||||||
IName[] decls = pdom.findNames(binding, flags);
|
IName[] decls = pdom.findNames(binding, flags);
|
||||||
if (k >= 0)
|
if (k >= 0)
|
||||||
assertEquals(k, decls.length);
|
assertEquals(k, decls.length);
|
||||||
|
@ -156,28 +146,24 @@ public class DefDeclTests extends PDOMTestBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void assertAtMark(IASTFileLocation loc, String mark)
|
protected void assertAtMark(IASTFileLocation loc, String mark) throws Exception {
|
||||||
throws Exception {
|
|
||||||
String fileName = new File(loc.getFileName()).getName();
|
String fileName = new File(loc.getFileName()).getName();
|
||||||
int markLine = getMarkLine(mark, fileName);
|
int markLine = getMarkLine(mark, fileName);
|
||||||
int nodeLine = getLineNumber(loc.getNodeOffset(), fileName);
|
int nodeLine = getLineNumber(loc.getNodeOffset(), fileName);
|
||||||
assertEquals(markLine, nodeLine);
|
assertEquals(markLine, nodeLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getMarkLine(String mark, String fileName) throws Exception,
|
private int getMarkLine(String mark, String fileName) throws Exception, BadLocationException {
|
||||||
BadLocationException {
|
|
||||||
int markLine = getLineNumber(offset(fileName, mark), fileName);
|
int markLine = getLineNumber(offset(fileName, mark), fileName);
|
||||||
return markLine;
|
return markLine;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int getLineNumber(int position, String projectRelativePath)
|
protected int getLineNumber(int position, String projectRelativePath) throws Exception {
|
||||||
throws Exception {
|
|
||||||
Path fullPath = new Path(projectName + "/" + projectRelativePath);
|
Path fullPath = new Path(projectName + "/" + projectRelativePath);
|
||||||
return TestSourceReader.getLineNumber(position, fullPath);
|
return TestSourceReader.getLineNumber(position, fullPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void assertDefDeclRef(String name, String testNum, int def,
|
public void assertDefDeclRef(String name, String testNum, int def, int decl, int ref) throws Exception {
|
||||||
int decl, int ref) throws Exception {
|
|
||||||
String elName = name + testNum;
|
String elName = name + testNum;
|
||||||
IBinding binding = findSingleBinding(elName);
|
IBinding binding = findSingleBinding(elName);
|
||||||
checkDefinition(binding, "def" + testNum, def);
|
checkDefinition(binding, "def" + testNum, def);
|
||||||
|
@ -190,6 +176,7 @@ public class DefDeclTests extends PDOMTestBase {
|
||||||
assertEquals(1, files.length);
|
assertEquals(1, files.length);
|
||||||
return files[0];
|
return files[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------ Tests Started Here ------------------------ */
|
/* ------------------ Tests Started Here ------------------------ */
|
||||||
public void testInit() {
|
public void testInit() {
|
||||||
// will fail if setUp fails, maybe timelimit is too small for warm-up
|
// will fail if setUp fails, maybe timelimit is too small for warm-up
|
||||||
|
@ -221,7 +208,7 @@ public class DefDeclTests extends PDOMTestBase {
|
||||||
|
|
||||||
public void testWrongMatchedStaticDefinition() throws Exception {
|
public void testWrongMatchedStaticDefinition() throws Exception {
|
||||||
String elName = "foo" + "07";
|
String elName = "foo" + "07";
|
||||||
IIndexBinding[] binds = pdom.findBindings(Pattern.compile(elName), true, IndexFilter.ALL, new NullProgressMonitor());
|
IIndexBinding[] binds = pdom.findBindings(Pattern.compile(elName), true, IndexFilter.ALL, null);
|
||||||
assertEquals(2, binds.length);
|
assertEquals(2, binds.length);
|
||||||
assertTrue(binds[0].isFileLocal() != binds[1].isFileLocal());
|
assertTrue(binds[0].isFileLocal() != binds[1].isFileLocal());
|
||||||
if (binds[0].isFileLocal()) {
|
if (binds[0].isFileLocal()) {
|
||||||
|
@ -288,8 +275,7 @@ public class DefDeclTests extends PDOMTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDefDeclUse_v14() throws Exception {
|
public void testDefDeclUse_v14() throws Exception {
|
||||||
// Hmm. This test seems to work, but Find Declaration in the UI does not
|
// Hmm. This test seems to work, but Find Declaration in the UI does not work.
|
||||||
// work
|
|
||||||
assertDefDeclRef("var", "_v14", 1, 1, 1);
|
assertDefDeclRef("var", "_v14", 1, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,7 +295,7 @@ public class DefDeclTests extends PDOMTestBase {
|
||||||
String num = "_t04";
|
String num = "_t04";
|
||||||
String elName = "type" + num;
|
String elName = "type" + num;
|
||||||
|
|
||||||
IBinding[] bindings = pdom.findBindings(Pattern.compile(elName), false, IndexFilter.ALL, new NullProgressMonitor());
|
IBinding[] bindings = pdom.findBindings(Pattern.compile(elName), false, IndexFilter.ALL, null);
|
||||||
assertEquals(2,bindings.length);
|
assertEquals(2,bindings.length);
|
||||||
|
|
||||||
IBinding typedef = bindings[0] instanceof ITypedef ? bindings[0] : bindings[1];
|
IBinding typedef = bindings[0] instanceof ITypedef ? bindings[0] : bindings[1];
|
||||||
|
|
Loading…
Add table
Reference in a new issue