ISourceParser interface change
diff --git a/tests/org.eclipse.dltk.python.tests/src/org/eclipse/dltk/python/tests/model/ComplexConstructsTests.java b/tests/org.eclipse.dltk.python.tests/src/org/eclipse/dltk/python/tests/model/ComplexConstructsTests.java
index b3714f7..6298f26 100644
--- a/tests/org.eclipse.dltk.python.tests/src/org/eclipse/dltk/python/tests/model/ComplexConstructsTests.java
+++ b/tests/org.eclipse.dltk.python.tests/src/org/eclipse/dltk/python/tests/model/ComplexConstructsTests.java
@@ -10,10 +10,10 @@
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Path;
import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
import org.eclipse.dltk.ast.expressions.Expression;
import org.eclipse.dltk.ast.statements.Block;
+import org.eclipse.dltk.compiler.env.ModuleSource;
import org.eclipse.dltk.core.IModelElement;
import org.eclipse.dltk.core.IScriptProject;
import org.eclipse.dltk.core.ISourceModule;
@@ -23,26 +23,22 @@
import org.eclipse.dltk.python.parser.ast.PythonWithStatement;
import org.eclipse.dltk.python.tests.PythonTestsPlugin;
-public class ComplexConstructsTests extends AbstractModelTests
-{
+public class ComplexConstructsTests extends AbstractModelTests {
private static final String PROJECT_NAME = "pytests";
private static final String FOLDER = "src";
private static final String ASSIGNMENT_TESTS_FILE_NAME = "assignment_tests.py";
private static final String SCRIPT_SOURCE = "a,b=1,2;c=d=1;x=y=lambda z:z;";
-
- public ComplexConstructsTests(String name)
- {
- super(PythonTestsPlugin.PLUGIN_NAME, name);
+
+ public ComplexConstructsTests(String name) {
+ super(PythonTestsPlugin.PLUGIN_NAME, name);
}
- public static Test suite()
- {
- return new Suite( ComplexConstructsTests.class);
+ public static Test suite() {
+ return new Suite(ComplexConstructsTests.class);
}
- public void setUpSuite() throws Exception
- {
+ public void setUpSuite() throws Exception {
super.setUpSuite();
IScriptProject sp = this.setUpScriptProject(PROJECT_NAME);
IProject prj = sp.getProject();
@@ -52,16 +48,17 @@
InputStream source = new ByteArrayInputStream(SCRIPT_SOURCE.getBytes());
testFile.create(source, true, new NullProgressMonitor());
}
- public void tearDownSuite() throws Exception
- {
+
+ public void tearDownSuite() throws Exception {
super.tearDownSuite();
deleteProject(PROJECT_NAME);
}
- //this is a model test
- public void testAssignment() throws Exception
- {
- IScriptProject project = getScriptProject( PROJECT_NAME );
- ISourceModule module = this.getSourceModule( PROJECT_NAME, FOLDER, ASSIGNMENT_TESTS_FILE_NAME);
+
+ // this is a model test
+ public void testAssignment() throws Exception {
+ IScriptProject project = getScriptProject(PROJECT_NAME);
+ ISourceModule module = this.getSourceModule(PROJECT_NAME, FOLDER,
+ ASSIGNMENT_TESTS_FILE_NAME);
IModelElement[] children = module.getChildren();
ModelTestUtils.getAssertField(children, "a");
ModelTestUtils.getAssertField(children, "b");
@@ -70,19 +67,22 @@
ModelTestUtils.getAssertMethod(children, "x", 1);
ModelTestUtils.getAssertMethod(children, "y", 1);
}
- //this is a parser test
- public void testWithStatement()
- {
+
+ // this is a parser test
+ public void testWithStatement() {
final String script = "with a as b : pass";
PythonSourceParser parser = new PythonSourceParser();
- ModuleDeclaration module = parser.parse(null, script.toCharArray(), null);
- List children = ((Block)module.getChilds().get(0)).getChilds();
+ ModuleDeclaration module = (ModuleDeclaration) parser.parse(new ModuleSource(script), null);
+ List children = ((Block) module.getChilds().get(0)).getChilds();
Object pws = children.get(0);
- assertTrue("with...as... statement expected.",pws instanceof PythonWithStatement);
- children = ((PythonWithStatement)pws).getChilds();
+ assertTrue("with...as... statement expected.",
+ pws instanceof PythonWithStatement);
+ children = ((PythonWithStatement) pws).getChilds();
assertTrue("Three children expected", 3 == children.size());
- assertTrue("Expression expected.", children.get(0) instanceof Expression);
- assertTrue("Expression expected.", children.get(1) instanceof Expression);
+ assertTrue("Expression expected.",
+ children.get(0) instanceof Expression);
+ assertTrue("Expression expected.",
+ children.get(1) instanceof Expression);
assertTrue("Block expected.", children.get(2) instanceof Block);
}
}
diff --git a/tests/org.eclipse.dltk.python.tests/src/org/eclipse/dltk/python/tests/model/TokenPostitionsParserTests.java b/tests/org.eclipse.dltk.python.tests/src/org/eclipse/dltk/python/tests/model/TokenPostitionsParserTests.java
index a263d00..ba3076b 100644
--- a/tests/org.eclipse.dltk.python.tests/src/org/eclipse/dltk/python/tests/model/TokenPostitionsParserTests.java
+++ b/tests/org.eclipse.dltk.python.tests/src/org/eclipse/dltk/python/tests/model/TokenPostitionsParserTests.java
@@ -11,6 +11,7 @@
import org.eclipse.dltk.ast.expressions.NumericLiteral;
import org.eclipse.dltk.ast.references.VariableReference;
import org.eclipse.dltk.ast.statements.Block;
+import org.eclipse.dltk.compiler.env.ModuleSource;
import org.eclipse.dltk.core.tests.model.SuiteOfTestCases;
import org.eclipse.dltk.python.internal.core.parser.PythonSourceParser;
import org.eclipse.dltk.python.parser.ast.PythonClassDeclaration;
@@ -23,55 +24,56 @@
import org.eclipse.dltk.python.parser.ast.expressions.PythonTestListExpression;
import org.eclipse.dltk.python.parser.ast.expressions.PythonTupleExpression;
+@SuppressWarnings("restriction")
public class TokenPostitionsParserTests extends SuiteOfTestCases {
private static final String whileScript = "a=1; while a>0 : a=a-1;";
private static final String whileElseScript = "a=1; while a>0 : a=a-1; else : a = 1;";
private static final String testExprScript = "print \"Hello,\", \"World!\"";
private static final String testDictExprScript = "{ { }:{} }";
- private static final String testTupleExprScript = "( 1, () )";
+ private static final String testTupleExprScript = "( 1, () )";
private static final String testListExprScript = "[ [],[] ]";
- private static final String testBackQuotesScript = "` 0 `";
+ private static final String testBackQuotesScript = "` 0 `";
private static final String testSuperClassDeclScript = "class A (object) : pass";
private static final String testForList = "[i for i in []]";
-
+
private static final String msg = "Invalid token displacement";
public static Test suite() {
return new Suite(TokenPostitionsParserTests.class);
}
-
+
public TokenPostitionsParserTests() {
super("Token positions parser test case");
}
- private static void testWhileStatements(String script) throws Exception
- {
+
+ private static void testWhileStatements(String script) throws Exception {
PythonSourceParser parser = new PythonSourceParser();
- ModuleDeclaration module = parser.parse(null, script.toCharArray(), null);
- List children = ((ASTNode)module.getChilds().iterator().next()).getChilds();
+ ModuleDeclaration module = (ModuleDeclaration) parser.parse(
+ new ModuleSource(script), null);
+ List children = ((ASTNode) module.getChilds().iterator().next())
+ .getChilds();
Iterator iter = children.iterator();
- while (iter.hasNext())
- {
- ASTNode node = (ASTNode)iter.next();
- if (node instanceof PythonWhileStatement)
- {
- PythonWhileStatement whileStmt = (PythonWhileStatement)node;
- if (null != whileStmt.getElseStatement())
- {
- assertTrue(msg,whileStmt.sourceStart() < whileStmt.sourceEnd());
- assertTrue(msg, whileStmt.sourceEnd() == whileStmt.getElseStatement().sourceEnd());
+ while (iter.hasNext()) {
+ ASTNode node = (ASTNode) iter.next();
+ if (node instanceof PythonWhileStatement) {
+ PythonWhileStatement whileStmt = (PythonWhileStatement) node;
+ if (null != whileStmt.getElseStatement()) {
+ assertTrue(msg, whileStmt.sourceStart() < whileStmt
+ .sourceEnd());
+ assertTrue(msg, whileStmt.sourceEnd() == whileStmt
+ .getElseStatement().sourceEnd());
return;
- }
- else
- {
+ } else {
Iterator j = whileStmt.getChilds().iterator();
- while (j.hasNext())
- {
- ASTNode child = (ASTNode)j.next();
+ while (j.hasNext()) {
+ ASTNode child = (ASTNode) j.next();
if (child instanceof Block) {
Block block = (Block) child;
- assertTrue(msg,whileStmt.sourceStart() < whileStmt.sourceEnd());
- assertTrue(msg, whileStmt.sourceEnd() == block.sourceEnd());
+ assertTrue(msg, whileStmt.sourceStart() < whileStmt
+ .sourceEnd());
+ assertTrue(msg, whileStmt.sourceEnd() == block
+ .sourceEnd());
}
}
return;
@@ -80,78 +82,98 @@
}
throw new Exception("Ths test is invalid.");
}
- public void testWhileStatement() throws Exception
- {
+
+ public void testWhileStatement() throws Exception {
testWhileStatements(whileScript);
}
- public void testWhileEsleStatement() throws Exception
- {
+
+ public void testWhileEsleStatement() throws Exception {
testWhileStatements(whileElseScript);
}
- public void testTestListExpr()
- {
+
+ public void testTestListExpr() {
PythonSourceParser parser = new PythonSourceParser();
- ModuleDeclaration module = parser.parse(null, testExprScript.toCharArray(), null);
- List children = ((ASTNode)module.getChilds().iterator().next()).getChilds();
- PrintExpression printExpr = (PrintExpression)children.get(0);
- PythonTestListExpression testListExpr = (PythonTestListExpression) printExpr.getChilds().get(0);
- assertTrue(msg, testListExpr.sourceEnd() > testListExpr.sourceStart() && testListExpr.sourceStart() > printExpr.sourceStart());
+ ModuleDeclaration module = (ModuleDeclaration) parser.parse(
+ new ModuleSource(testExprScript), null);
+ List children = ((ASTNode) module.getChilds().iterator().next())
+ .getChilds();
+ PrintExpression printExpr = (PrintExpression) children.get(0);
+ PythonTestListExpression testListExpr = (PythonTestListExpression) printExpr
+ .getChilds().get(0);
+ assertTrue(msg, testListExpr.sourceEnd() > testListExpr.sourceStart()
+ && testListExpr.sourceStart() > printExpr.sourceStart());
}
- public void testDictExpression()
- {
+
+ public void testDictExpression() {
PythonSourceParser parser = new PythonSourceParser();
- ModuleDeclaration module = parser.parse(null, testDictExprScript.toCharArray(), null);
+ ModuleDeclaration module = (ModuleDeclaration) parser.parse(
+ new ModuleSource(testDictExprScript), null);
List children = module.getChilds();
- PythonDictExpression expr = (PythonDictExpression)((Block)children.get(0)).getChilds().get(0);
+ PythonDictExpression expr = (PythonDictExpression) ((Block) children
+ .get(0)).getChilds().get(0);
assertTrue(msg, expr.sourceStart() == 0 && expr.sourceEnd() == 12);
}
- public void testTupleExpression()
- {
+
+ public void testTupleExpression() {
PythonSourceParser parser = new PythonSourceParser();
- ModuleDeclaration module = parser.parse(null, testTupleExprScript.toCharArray(), null);
+ ModuleDeclaration module = (ModuleDeclaration) parser.parse(
+ new ModuleSource(testTupleExprScript), null);
List children = module.getChilds();
- PythonTupleExpression expr = (PythonTupleExpression)((Block)children.get(0)).getChilds().get(0);
+ PythonTupleExpression expr = (PythonTupleExpression) ((Block) children
+ .get(0)).getChilds().get(0);
assertTrue(msg, expr.sourceStart() == 0 && expr.sourceEnd() == 9);
}
- public void testListExpression()
- {
+
+ public void testListExpression() {
PythonSourceParser parser = new PythonSourceParser();
- ModuleDeclaration module = parser.parse(null, testListExprScript.toCharArray(), null);
+ ModuleDeclaration module = (ModuleDeclaration) parser.parse(
+ new ModuleSource(testListExprScript), null);
List children = module.getChilds();
- PythonListExpression expr = (PythonListExpression)((Block)children.get(0)).getChilds().get(0);
+ PythonListExpression expr = (PythonListExpression) ((Block) children
+ .get(0)).getChilds().get(0);
assertTrue(msg, expr.sourceStart() == 0 && expr.sourceEnd() == 9);
}
- public void testBackQuotesExpression()
- {
+
+ public void testBackQuotesExpression() {
PythonSourceParser parser = new PythonSourceParser();
- ModuleDeclaration module = parser.parse(null, testBackQuotesScript.toCharArray(), null);
+ ModuleDeclaration module = (ModuleDeclaration) parser.parse(
+ new ModuleSource(testBackQuotesScript), null);
List children = module.getChilds();
- NumericLiteral expr = (NumericLiteral)((Block)children.get(0)).getChilds().get(0);
+ NumericLiteral expr = (NumericLiteral) ((Block) children.get(0))
+ .getChilds().get(0);
assertTrue(msg, expr.sourceStart() == 0 && expr.sourceEnd() == 5);
}
- public void testSuperClassDecl()
- {
+
+ public void testSuperClassDecl() {
PythonSourceParser parser = new PythonSourceParser();
- ModuleDeclaration module = parser.parse(null, testSuperClassDeclScript.toCharArray(), null);
+ ModuleDeclaration module = (ModuleDeclaration) parser.parse(
+ new ModuleSource(testSuperClassDeclScript), null);
List children = module.getChilds();
- ASTListNode supers = ((PythonClassDeclaration)((Block)children.get(0)).getChilds().get(0)).getSuperClasses();
- assertTrue(msg,9 == supers.sourceStart() && 15 == supers.sourceEnd());
+ ASTListNode supers = ((PythonClassDeclaration) ((Block) children.get(0))
+ .getChilds().get(0)).getSuperClasses();
+ assertTrue(msg, 9 == supers.sourceStart() && 15 == supers.sourceEnd());
}
+
public void testForList() {
PythonSourceParser parser = new PythonSourceParser();
- ModuleDeclaration module = parser.parse(null, testForList.toCharArray(), null);
- Block block = (Block)module.getChilds().get(0);
- PythonListExpression list = (PythonListExpression) block.getChilds().get(0);
- PythonListForExpression listFor = (PythonListForExpression) list.getChilds().get(0);
- assertTrue(listFor.sourceStart()==1 && listFor.sourceEnd() == 14);
- assertTrue(listFor.getChilds().get(0) instanceof VariableReference && listFor.getChilds().get(1) instanceof PythonForListExpression);
+ ModuleDeclaration module = (ModuleDeclaration) parser.parse(
+ new ModuleSource(testForList), null);
+ Block block = (Block) module.getChilds().get(0);
+ PythonListExpression list = (PythonListExpression) block.getChilds()
+ .get(0);
+ PythonListForExpression listFor = (PythonListForExpression) list
+ .getChilds().get(0);
+ assertTrue(listFor.sourceStart() == 1 && listFor.sourceEnd() == 14);
+ assertTrue(listFor.getChilds().get(0) instanceof VariableReference
+ && listFor.getChilds().get(1) instanceof PythonForListExpression);
VariableReference var = (VariableReference) listFor.getChilds().get(0);
assertTrue(var.sourceStart() == 1 && var.sourceEnd() == 2);
- PythonForListExpression forList = (PythonForListExpression) listFor.getChilds().get(1);
+ PythonForListExpression forList = (PythonForListExpression) listFor
+ .getChilds().get(1);
assertTrue(forList.sourceStart() == 3 && forList.sourceEnd() == 14);
}
}