mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 06:02:11 +02:00
Moved to JDK 1.8.
Change-Id: I415625d3cebe3ff38454bd6722c31da07eb466c4
This commit is contained in:
parent
744765be6f
commit
00e7081b17
4 changed files with 251 additions and 265 deletions
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<classpath>
|
<classpath>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||||
<classpathentry kind="src" path="src"/>
|
<classpathentry kind="src" path="src"/>
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#Fri Apr 25 15:22:29 EDT 2008
|
|
||||||
eclipse.preferences.version=1
|
eclipse.preferences.version=1
|
||||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||||
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
|
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
|
||||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||||
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
|
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
|
||||||
|
@ -62,4 +62,4 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=enab
|
||||||
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
|
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
|
||||||
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
|
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
|
||||||
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
|
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
|
||||||
org.eclipse.jdt.core.compiler.source=1.7
|
org.eclipse.jdt.core.compiler.source=1.8
|
||||||
|
|
|
@ -12,4 +12,4 @@ Require-Bundle: org.eclipse.core.runtime,
|
||||||
Export-Package: org.eclipse.cdt.core.lrparser.tests
|
Export-Package: org.eclipse.cdt.core.lrparser.tests
|
||||||
Bundle-Vendor: %Bundle-Vendor.0
|
Bundle-Vendor: %Bundle-Vendor.0
|
||||||
Bundle-Localization: plugin
|
Bundle-Localization: plugin
|
||||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
|
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2006, 2009 IBM Corporation and others.
|
* Copyright (c) 2006, 2009 IBM Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM Corporation - initial API and implementation
|
* IBM Corporation - initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.core.lrparser.tests;
|
package org.eclipse.cdt.core.lrparser.tests;
|
||||||
|
@ -15,9 +15,6 @@ import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
import junit.framework.TestSuite;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
|
import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
|
@ -28,6 +25,8 @@ import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||||
import org.eclipse.cdt.core.dom.lrparser.gnu.GCCLanguage;
|
import org.eclipse.cdt.core.dom.lrparser.gnu.GCCLanguage;
|
||||||
import org.eclipse.cdt.core.model.ILanguage;
|
import org.eclipse.cdt.core.model.ILanguage;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reuse the completion parse tests from the old parser for now.
|
* Reuse the completion parse tests from the old parser for now.
|
||||||
|
@ -38,379 +37,366 @@ public class LRCompletionParseTest extends TestCase {
|
||||||
public static TestSuite suite() {
|
public static TestSuite suite() {
|
||||||
return new TestSuite(LRCompletionParseTest.class);
|
return new TestSuite(LRCompletionParseTest.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LRCompletionParseTest() {
|
||||||
public LRCompletionParseTest() { }
|
}
|
||||||
public LRCompletionParseTest(String name) { super(name); }
|
|
||||||
|
public LRCompletionParseTest(String name) {
|
||||||
|
super(name);
|
||||||
|
}
|
||||||
|
|
||||||
protected IASTCompletionNode parse(String code, int offset) throws Exception {
|
protected IASTCompletionNode parse(String code, int offset) throws Exception {
|
||||||
return ParseHelper.getCompletionNode(code, getCLanguage(), offset);
|
return ParseHelper.getCompletionNode(code, getCLanguage(), offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static final Comparator<IBinding> BINDING_COMPARATOR = new Comparator<IBinding>() {
|
private static final Comparator<IBinding> BINDING_COMPARATOR = new Comparator<IBinding>() {
|
||||||
@Override
|
@Override
|
||||||
public int compare(IBinding b1, IBinding b2) {
|
public int compare(IBinding b1, IBinding b2) {
|
||||||
return b1.getName().compareTo(b2.getName());
|
return b1.getName().compareTo(b2.getName());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
public static IBinding[] getBindings(IASTName[] names) {
|
public static IBinding[] getBindings(IASTName[] names) {
|
||||||
List<IBinding> bindings = new ArrayList<IBinding>();
|
List<IBinding> bindings = new ArrayList<>();
|
||||||
|
|
||||||
for(IASTName name : names) {
|
for (IASTName name : names) {
|
||||||
if(name.getTranslationUnit() == null)
|
if (name.getTranslationUnit() == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for(IBinding binding : name.getCompletionContext().findBindings(name, true))
|
for (IBinding binding : name.getCompletionContext().findBindings(name, true)) {
|
||||||
bindings.add(binding);
|
bindings.add(binding);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Collections.sort(bindings, BINDING_COMPARATOR);
|
Collections.sort(bindings, BINDING_COMPARATOR);
|
||||||
return bindings.toArray(new IBinding[bindings.size()]);
|
return bindings.toArray(new IBinding[bindings.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected ILanguage getCLanguage() {
|
protected ILanguage getCLanguage() {
|
||||||
return GCCLanguage.getDefault();
|
return GCCLanguage.getDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// First steal tests from CompletionParseTest
|
// First steal tests from CompletionParseTest
|
||||||
|
|
||||||
|
|
||||||
public void testCompletionStructField() throws Exception {
|
public void testCompletionStructField() throws Exception {
|
||||||
String code =
|
String code =
|
||||||
"int aVar; " +
|
"int aVar; " +
|
||||||
"struct D{ " +
|
"struct D{ " +
|
||||||
" int aField1; " +
|
" int aField1; " +
|
||||||
" int aField2; " +
|
" int aField2; " +
|
||||||
"}; " +
|
"}; " +
|
||||||
"void foo(){" +
|
"void foo() {" +
|
||||||
" struct D d; " +
|
" struct D d; " +
|
||||||
" d.a " +
|
" d.a " +
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
int index = code.indexOf( "d.a" );
|
int index = code.indexOf("d.a");
|
||||||
|
|
||||||
IASTCompletionNode node = parse( code, index + 3 );
|
IASTCompletionNode node = parse(code, index + 3);
|
||||||
assertNotNull( node );
|
assertNotNull(node);
|
||||||
|
|
||||||
String prefix = node.getPrefix();
|
String prefix = node.getPrefix();
|
||||||
assertNotNull( prefix );
|
assertNotNull(prefix);
|
||||||
assertEquals( prefix, "a" );
|
assertEquals(prefix, "a");
|
||||||
|
|
||||||
IASTName[] names = node.getNames();
|
IASTName[] names = node.getNames();
|
||||||
assertEquals(1, names.length);
|
assertEquals(1, names.length);
|
||||||
|
|
||||||
IBinding[] bindings = getBindings(names);
|
IBinding[] bindings = getBindings(names);
|
||||||
|
|
||||||
assertEquals(2, bindings.length);
|
assertEquals(2, bindings.length);
|
||||||
assertEquals("aField1", ((IField)bindings[0]).getName());
|
assertEquals("aField1", ((IField)bindings[0]).getName());
|
||||||
assertEquals("aField2", ((IField)bindings[1]).getName());
|
assertEquals("aField2", ((IField)bindings[1]).getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCompletionStructFieldPointer() throws Exception {
|
public void testCompletionStructFieldPointer() throws Exception {
|
||||||
String code =
|
String code =
|
||||||
"struct Cube { " +
|
"struct Cube { " +
|
||||||
" int nLen; " +
|
" int nLen; " +
|
||||||
" int nWidth; " +
|
" int nWidth; " +
|
||||||
" int nHeight; " +
|
" int nHeight; " +
|
||||||
"}; " +
|
"}; " +
|
||||||
"int volume( struct Cube * pCube ) { " +
|
"int volume(struct Cube * pCube) { " +
|
||||||
" pCube->SP ";
|
" pCube->SP ";
|
||||||
|
|
||||||
|
IASTCompletionNode node = parse(code, code.indexOf("SP"));
|
||||||
|
|
||||||
IASTCompletionNode node = parse( code, code.indexOf("SP"));
|
|
||||||
|
|
||||||
IASTName[] names = node.getNames();
|
IASTName[] names = node.getNames();
|
||||||
assertEquals(1, names.length);
|
assertEquals(1, names.length);
|
||||||
|
|
||||||
IBinding[] bindings = getBindings(names);
|
IBinding[] bindings = getBindings(names);
|
||||||
|
|
||||||
assertEquals(3, bindings.length);
|
assertEquals(3, bindings.length);
|
||||||
assertEquals("nHeight", ((IField)bindings[0]).getName());
|
assertEquals("nHeight", ((IField)bindings[0]).getName());
|
||||||
assertEquals("nLen", ((IField)bindings[1]).getName());
|
assertEquals("nLen", ((IField)bindings[1]).getName());
|
||||||
assertEquals("nWidth", ((IField)bindings[2]).getName());
|
assertEquals("nWidth", ((IField)bindings[2]).getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testCompletionParametersAsLocalVariables() throws Exception{
|
public void testCompletionParametersAsLocalVariables() throws Exception{
|
||||||
String code =
|
String code =
|
||||||
"int foo( int aParameter ){" +
|
"int foo(int aParameter) {" +
|
||||||
" int aLocal;" +
|
" int aLocal;" +
|
||||||
" if( aLocal != 0 ){" +
|
" if (aLocal != 0) {" +
|
||||||
" int aBlockLocal;" +
|
" int aBlockLocal;" +
|
||||||
" a \n";
|
" a \n";
|
||||||
|
|
||||||
int index = code.indexOf( " a " );
|
int index = code.indexOf(" a ");
|
||||||
|
|
||||||
IASTCompletionNode node = parse( code, index + 2 );
|
IASTCompletionNode node = parse(code, index + 2);
|
||||||
assertNotNull( node );
|
assertNotNull(node);
|
||||||
|
|
||||||
assertEquals("a", node.getPrefix()); //$NON-NLS-1$
|
assertEquals("a", node.getPrefix()); //$NON-NLS-1$
|
||||||
|
|
||||||
IASTName[] names = node.getNames();
|
IASTName[] names = node.getNames();
|
||||||
assertEquals(2, names.length);
|
assertEquals(2, names.length);
|
||||||
|
|
||||||
IBinding[] bindings = getBindings(names);
|
IBinding[] bindings = getBindings(names);
|
||||||
|
|
||||||
assertEquals(3, bindings.length);
|
assertEquals(3, bindings.length);
|
||||||
assertEquals("aBlockLocal", ((IVariable)bindings[0]).getName());
|
assertEquals("aBlockLocal", ((IVariable) bindings[0]).getName());
|
||||||
assertEquals("aLocal", ((IVariable)bindings[1]).getName());
|
assertEquals("aLocal", ((IVariable) bindings[1]).getName());
|
||||||
assertEquals("aParameter", ((IVariable)bindings[2]).getName());
|
assertEquals("aParameter", ((IVariable) bindings[2]).getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testCompletionTypedef() throws Exception {
|
public void testCompletionTypedef() throws Exception {
|
||||||
String code =
|
String code =
|
||||||
"typedef int Int; " +
|
"typedef int Int; " +
|
||||||
"InSP";
|
"InSP";
|
||||||
|
|
||||||
int index = code.indexOf( "SP" );
|
int index = code.indexOf("SP");
|
||||||
|
|
||||||
IASTCompletionNode node = parse( code, index );
|
IASTCompletionNode node = parse(code, index);
|
||||||
assertNotNull(node);
|
assertNotNull(node);
|
||||||
|
|
||||||
IASTName[] names = node.getNames();
|
IASTName[] names = node.getNames();
|
||||||
assertEquals(1, names.length);
|
assertEquals(1, names.length);
|
||||||
|
|
||||||
assertEquals("In", node.getPrefix());
|
assertEquals("In", node.getPrefix());
|
||||||
|
|
||||||
IBinding[] bindings = getBindings(names);
|
IBinding[] bindings = getBindings(names);
|
||||||
|
|
||||||
assertEquals(1, bindings.length);
|
assertEquals(1, bindings.length);
|
||||||
assertEquals("Int", ((ITypedef)bindings[0]).getName());
|
assertEquals("Int", ((ITypedef) bindings[0]).getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCompletion() throws Exception {
|
public void testCompletion() throws Exception {
|
||||||
String code =
|
String code =
|
||||||
"#define GL_T 0x2001\n" +
|
"#define GL_T 0x2001\n" +
|
||||||
"#define GL_TRUE 0x1\n" +
|
"#define GL_TRUE 0x1\n" +
|
||||||
"typedef unsigned char GLboolean;\n" +
|
"typedef unsigned char GLboolean;\n" +
|
||||||
"static GLboolean should_rotate = GL_T";
|
"static GLboolean should_rotate = GL_T";
|
||||||
|
|
||||||
int index = code.indexOf("= GL_T");
|
int index = code.indexOf("= GL_T");
|
||||||
|
|
||||||
IASTCompletionNode node = parse( code, index + 6);
|
IASTCompletionNode node = parse(code, index + 6);
|
||||||
assertNotNull(node);
|
assertNotNull(node);
|
||||||
|
|
||||||
assertEquals("GL_T", node.getPrefix()); //$NON-NLS-1$
|
assertEquals("GL_T", node.getPrefix()); //$NON-NLS-1$
|
||||||
|
|
||||||
IASTName[] names = node.getNames();
|
IASTName[] names = node.getNames();
|
||||||
assertEquals(1, names.length);
|
assertEquals(1, names.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCompletionInTypeDef() throws Exception {
|
public void testCompletionInTypeDef() throws Exception {
|
||||||
String code =
|
String code =
|
||||||
"struct A { int name; }; \n" +
|
"struct A { int name; }; \n" +
|
||||||
"typedef struct A * PA; \n" +
|
"typedef struct A * PA; \n" +
|
||||||
"int main() { \n" +
|
"int main() { \n" +
|
||||||
" PA a; \n" +
|
" PA a; \n" +
|
||||||
" a->SP \n" +
|
" a->SP \n" +
|
||||||
"} \n";
|
"} \n";
|
||||||
|
|
||||||
int index = code.indexOf("SP"); //$NON-NLS-1$
|
int index = code.indexOf("SP"); //$NON-NLS-1$
|
||||||
|
|
||||||
IASTCompletionNode node = parse( code, index );
|
IASTCompletionNode node = parse(code, index);
|
||||||
assertNotNull( node );
|
assertNotNull(node);
|
||||||
|
|
||||||
|
|
||||||
IASTName[] names = node.getNames();
|
IASTName[] names = node.getNames();
|
||||||
assertEquals(1, names.length);
|
assertEquals(1, names.length);
|
||||||
|
|
||||||
IBinding[] bindings = getBindings(names);
|
IBinding[] bindings = getBindings(names);
|
||||||
|
|
||||||
assertEquals(1, bindings.length);
|
assertEquals(1, bindings.length);
|
||||||
assertEquals("name", ((IField)bindings[0]).getName());
|
assertEquals("name", ((IField) bindings[0]).getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void _testCompletionFunctionCall() throws Exception {
|
public void _testCompletionFunctionCall() throws Exception {
|
||||||
String code =
|
String code =
|
||||||
"struct A { \n" +
|
"struct A { \n" +
|
||||||
" int f2; \n" +
|
" int f2; \n" +
|
||||||
" int f4; \n" +
|
" int f4; \n" +
|
||||||
"}; \n" +
|
"}; \n" +
|
||||||
"const A * foo(){} \n" +
|
"const A * foo() {} \n" +
|
||||||
"void main( ) \n" +
|
"void main() \n" +
|
||||||
"{ \n" +
|
"{ \n" +
|
||||||
" foo()->SP \n";
|
" foo()->SP \n";
|
||||||
|
|
||||||
int index = code.indexOf( "SP" );
|
int index = code.indexOf("SP");
|
||||||
|
|
||||||
IASTCompletionNode node = parse( code, index );
|
IASTCompletionNode node = parse(code, index);
|
||||||
assertNotNull( node );
|
assertNotNull(node);
|
||||||
|
|
||||||
IASTName[] names = node.getNames();
|
IASTName[] names = node.getNames();
|
||||||
assertEquals(1, names.length);
|
assertEquals(1, names.length);
|
||||||
|
|
||||||
IBinding[] bindings = getBindings(names);
|
IBinding[] bindings = getBindings(names);
|
||||||
|
|
||||||
assertEquals(2, bindings.length);
|
assertEquals(2, bindings.length);
|
||||||
assertEquals("f2", ((IField)bindings[0]).getName());
|
assertEquals("f2", ((IField) bindings[0]).getName());
|
||||||
assertEquals("f4", ((IField)bindings[1]).getName());
|
assertEquals("f4", ((IField) bindings[1]).getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void _testCompletionSizeof() throws Exception {
|
public void _testCompletionSizeof() throws Exception {
|
||||||
String code =
|
String code =
|
||||||
"int f() {\n" +
|
"int f() {\n" +
|
||||||
"short blah;\n" +
|
"short blah;\n" +
|
||||||
"int x = sizeof(bl";
|
"int x = sizeof(bl";
|
||||||
|
|
||||||
int index = code.indexOf( "of(bl" );
|
int index = code.indexOf("of(bl");
|
||||||
|
|
||||||
IASTCompletionNode node = parse( code, index + 5);
|
IASTCompletionNode node = parse(code, index + 5);
|
||||||
assertNotNull( node );
|
assertNotNull(node);
|
||||||
|
|
||||||
IASTName[] names = node.getNames();
|
IASTName[] names = node.getNames();
|
||||||
assertEquals(1, names.length);
|
assertEquals(1, names.length);
|
||||||
|
|
||||||
IBinding[] bindings = getBindings(names);
|
IBinding[] bindings = getBindings(names);
|
||||||
|
|
||||||
assertEquals(1, bindings.length);
|
assertEquals(1, bindings.length);
|
||||||
assertEquals("blah", ((IVariable)bindings[0]).getName());
|
assertEquals("blah", ((IVariable) bindings[0]).getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testCompletionForLoop() throws Exception {
|
public void testCompletionForLoop() throws Exception {
|
||||||
String code =
|
String code =
|
||||||
"int f() {\n" +
|
"int f() {\n" +
|
||||||
" int biSizeImage = 5;\n" +
|
" int biSizeImage = 5;\n" +
|
||||||
"for (int i = 0; i < bi ";
|
"for (int i = 0; i < bi ";
|
||||||
|
|
||||||
int index = code.indexOf("< bi");
|
int index = code.indexOf("< bi");
|
||||||
|
|
||||||
IASTCompletionNode node = parse( code, index + 4);
|
IASTCompletionNode node = parse(code, index + 4);
|
||||||
assertNotNull( node );
|
assertNotNull(node);
|
||||||
|
|
||||||
IASTName[] names = node.getNames();
|
IASTName[] names = node.getNames();
|
||||||
assertEquals(1, names.length);
|
assertEquals(1, names.length);
|
||||||
|
|
||||||
IBinding[] bindings = getBindings(names);
|
IBinding[] bindings = getBindings(names);
|
||||||
|
|
||||||
assertEquals(1, bindings.length);
|
assertEquals(1, bindings.length);
|
||||||
assertEquals("biSizeImage", ((IVariable)bindings[0]).getName());
|
assertEquals("biSizeImage", ((IVariable) bindings[0]).getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void testCompletionStructPointer() throws Exception {
|
public void testCompletionStructPointer() throws Exception {
|
||||||
String code =
|
String code =
|
||||||
" struct Temp { char * total; };" +
|
" struct Temp { char * total; };" +
|
||||||
" int f(struct Temp * t) {" +
|
" int f(struct Temp * t) {" +
|
||||||
" t->t[5] = t->";
|
" t->t[5] = t->";
|
||||||
|
|
||||||
int index = code.indexOf("= t->");
|
int index = code.indexOf("= t->");
|
||||||
|
|
||||||
IASTCompletionNode node = parse( code, index + 5);
|
IASTCompletionNode node = parse(code, index + 5);
|
||||||
assertNotNull( node );
|
assertNotNull(node);
|
||||||
|
|
||||||
IASTName[] names = node.getNames();
|
IASTName[] names = node.getNames();
|
||||||
assertEquals(1, names.length);
|
assertEquals(1, names.length);
|
||||||
|
|
||||||
IBinding[] bindings = getBindings(names);
|
IBinding[] bindings = getBindings(names);
|
||||||
|
|
||||||
assertEquals(1, bindings.length);
|
assertEquals(1, bindings.length);
|
||||||
assertEquals("total", ((IVariable)bindings[0]).getName());
|
assertEquals("total", ((IVariable) bindings[0]).getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testCompletionEnum() throws Exception {
|
public void testCompletionEnum() throws Exception {
|
||||||
String code =
|
String code =
|
||||||
"typedef int DWORD;\n" +
|
"typedef int DWORD;\n" +
|
||||||
"typedef char BYTE;\n" +
|
"typedef char BYTE;\n" +
|
||||||
"#define MAKEFOURCC(ch0, ch1, ch2, ch3) \\\n" +
|
"#define MAKEFOURCC(ch0, ch1, ch2, ch3) \\\n" +
|
||||||
"((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) | \\\n" +
|
"((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) | \\\n" +
|
||||||
"((DWORD)(BYTE)(ch2) << 16) | ((DWORD)(BYTE)(ch3) << 24 ))\n" +
|
"((DWORD)(BYTE)(ch2) << 16) | ((DWORD)(BYTE)(ch3) << 24))\n" +
|
||||||
"enum e {\n" +
|
"enum e {\n" +
|
||||||
"blah1 = 5,\n" +
|
"blah1 = 5,\n" +
|
||||||
"blah2 = MAKEFOURCC('a', 'b', 'c', 'd'),\n" +
|
"blah2 = MAKEFOURCC('a', 'b', 'c', 'd'),\n" +
|
||||||
"blah3\n" +
|
"blah3\n" +
|
||||||
"};\n" +
|
"};\n" +
|
||||||
"e mye = bl\n";
|
"e mye = bl\n";
|
||||||
|
|
||||||
int index = code.indexOf("= bl");
|
int index = code.indexOf("= bl");
|
||||||
|
|
||||||
IASTCompletionNode node = parse( code, index + 4);
|
IASTCompletionNode node = parse(code, index + 4);
|
||||||
assertNotNull( node );
|
assertNotNull(node);
|
||||||
|
|
||||||
IASTName[] names = node.getNames();
|
IASTName[] names = node.getNames();
|
||||||
assertEquals(1, names.length);
|
assertEquals(1, names.length);
|
||||||
|
|
||||||
IBinding[] bindings = getBindings(names);
|
IBinding[] bindings = getBindings(names);
|
||||||
|
|
||||||
assertEquals(3, bindings.length);
|
assertEquals(3, bindings.length);
|
||||||
assertEquals("blah1", ((IEnumerator)bindings[0]).getName());
|
assertEquals("blah1", ((IEnumerator) bindings[0]).getName());
|
||||||
assertEquals("blah2", ((IEnumerator)bindings[1]).getName());
|
assertEquals("blah2", ((IEnumerator) bindings[1]).getName());
|
||||||
assertEquals("blah3", ((IEnumerator)bindings[2]).getName());
|
assertEquals("blah3", ((IEnumerator) bindings[2]).getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testCompletionStructArray() throws Exception {
|
||||||
public void testCompletionStructArray() throws Exception {
|
|
||||||
String code =
|
String code =
|
||||||
"struct packet { int a; int b; };\n" +
|
"struct packet { int a; int b; };\n" +
|
||||||
"struct packet buffer[5];\n" +
|
"struct packet buffer[5];\n" +
|
||||||
"int main(int argc, char **argv) {\n" +
|
"int main(int argc, char **argv) {\n" +
|
||||||
" buffer[2].";
|
" buffer[2].";
|
||||||
|
|
||||||
int index = code.indexOf("[2].");
|
int index = code.indexOf("[2].");
|
||||||
|
|
||||||
IASTCompletionNode node = parse( code, index + 4);
|
IASTCompletionNode node = parse(code, index + 4);
|
||||||
assertNotNull( node );
|
assertNotNull(node);
|
||||||
|
|
||||||
IASTName[] names = node.getNames();
|
IASTName[] names = node.getNames();
|
||||||
assertEquals(1, names.length);
|
assertEquals(1, names.length);
|
||||||
|
|
||||||
IBinding[] bindings = getBindings(names);
|
IBinding[] bindings = getBindings(names);
|
||||||
|
|
||||||
assertEquals(2, bindings.length);
|
assertEquals(2, bindings.length);
|
||||||
assertEquals("a", ((IField)bindings[0]).getName());
|
assertEquals("a", ((IField) bindings[0]).getName());
|
||||||
assertEquals("b", ((IField)bindings[1]).getName());
|
assertEquals("b", ((IField) bindings[1]).getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testCompletionPreprocessorDirective() throws Exception {
|
public void testCompletionPreprocessorDirective() throws Exception {
|
||||||
IASTCompletionNode node = parse("#", 1);
|
IASTCompletionNode node = parse("#", 1);
|
||||||
assertNotNull( node );
|
assertNotNull(node);
|
||||||
|
|
||||||
IASTName[] names = node.getNames();
|
IASTName[] names = node.getNames();
|
||||||
assertEquals(1, names.length);
|
assertEquals(1, names.length);
|
||||||
|
|
||||||
//assertEquals("#", node.getPrefix());
|
//assertEquals("#", node.getPrefix());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCompletionPreprocessorMacro() throws Exception {
|
public void testCompletionPreprocessorMacro() throws Exception {
|
||||||
String code =
|
String code =
|
||||||
"#define AMACRO 99 \n" +
|
"#define AMACRO 99 \n" +
|
||||||
"int main() { \n" +
|
"int main() { \n" +
|
||||||
" int AVAR; \n" +
|
" int AVAR; \n" +
|
||||||
" int x = A \n";
|
" int x = A \n";
|
||||||
|
|
||||||
int index = code.indexOf("= A");
|
int index = code.indexOf("= A");
|
||||||
|
|
||||||
IASTCompletionNode node = parse( code, index + 3);
|
IASTCompletionNode node = parse(code, index + 3);
|
||||||
assertNotNull( node );
|
assertNotNull(node);
|
||||||
|
|
||||||
IASTName[] names = node.getNames();
|
IASTName[] names = node.getNames();
|
||||||
assertEquals(1, names.length);
|
assertEquals(1, names.length);
|
||||||
assertEquals("A", node.getPrefix());
|
assertEquals("A", node.getPrefix());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testCompletionInsidePreprocessorDirective() throws Exception {
|
public void testCompletionInsidePreprocessorDirective() throws Exception {
|
||||||
String code =
|
String code =
|
||||||
"#define MAC1 99 \n" +
|
"#define MAC1 99 \n" +
|
||||||
"#define MAC2 99 \n" +
|
"#define MAC2 99 \n" +
|
||||||
"#ifdef MA";
|
"#ifdef MA";
|
||||||
|
|
||||||
int index = code.length();
|
int index = code.length();
|
||||||
|
|
||||||
IASTCompletionNode node = parse( code, index );
|
IASTCompletionNode node = parse(code, index);
|
||||||
assertNotNull( node );
|
assertNotNull(node);
|
||||||
|
|
||||||
assertEquals("MA", node.getPrefix());
|
assertEquals("MA", node.getPrefix());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue