protected void setUp() throws Exception { super.setUp(); source = SourceUnit.create("dummy.groovy", ""); verifier = new ClassCompletionVerifier(source); }
public ModuleNode parse(String text, String description) throws Exception { SourceUnit unit = SourceUnit.create(description, text); unit.parse(); unit.convert(); return unit.getAST(); } }
public ModuleNode getAST(String source, int untilPhase) { SourceUnit unit = SourceUnit.create("Test", source); CompilationUnit compUnit = new CompilationUnit(); compUnit.addSource(unit); compUnit.compile(untilPhase); return unit.getAST(); }
public ExpressionInfo build() { try { SourceUnit unit = SourceUnit.create("Spec expression", adjustedText); unit.parse(); unit.completePhase();
public void testSetsTheSourceLocatorOfItsSyntaxExceptionAsTheNameOfTheCorrespondingSourceUnitWhenInstantiated() { SyntaxException syntaxException = new SyntaxException(someString(), -1, -1); assertEquals("source locator", null, syntaxException.getSourceLocator()); String sourceUnitName = someString(); SourceUnit sourceUnit = SourceUnit.create(sourceUnitName, someString()); new SyntaxErrorMessage(syntaxException, sourceUnit); assertEquals("source locator", sourceUnitName, syntaxException.getSourceLocator()); }
/** * <p> Attempts to parse the specified code with the specified tolerance. * Updates the * <code>parser</code> and * <code>error</code> members appropriately. Returns true if the text * parsed, false otherwise. The attempts to identify and suppress errors * resulting from the unfinished source text. </p> <p> <b>Note:</b> taken * from {@link groovy.ui.InteractiveShell}. </p> */ private static boolean parse(final String code, final int tolerance) { assert code != null; boolean parsed = false; // Create the parser and attempt to parse the text as a top-level statement. try { SourceUnit parser = SourceUnit.create("vrl-script", code, tolerance); parser.parse(); parsed = true; } // We report errors other than unexpected EOF to the user. catch (CompilationFailedException e) { // } catch (Exception e) { // } return parsed; }
/** * Attempts to parse the specified code with the specified tolerance. * Updates the <code>parser</code> and <code>error</code> members * appropriately. Returns true if the text parsed, false otherwise. * The attempts to identify and suppress errors resulting from the * unfinished source text. */ private boolean parse(final String code, final int tolerance) { assert code != null; boolean parsed = false; parser = null; error = null; // Create the parser and attempt to parse the text as a top-level statement. try { parser = SourceUnit.create("groovysh-script", code, tolerance); parser.parse(); parsed = true; } // We report errors other than unexpected EOF to the user. catch (CompilationFailedException e) { if (parser.getErrorCollector().getErrorCount() > 1 || !parser.failedWithUnexpectedEOF()) { error = e; } } catch (Exception e) { error = e; } return parsed; }
parser = SourceUnit.create("vrl-script", code, tolerance); parser.parse(); parsed = true;
/** * Attempts to parse the specified code with the specified tolerance. * Updates the <code>parser</code> and <code>error</code> members * appropriately. Returns true if the text parsed, false otherwise. * The attempts to identify and suppress errors resulting from the * unfinished source text. */ private boolean parse(final String code, final int tolerance) { assert code != null; boolean parsed = false; parser = null; error = null; // Create the parser and attempt to parse the text as a top-level statement. try { parser = SourceUnit.create("groovysh-script", code, tolerance); parser.parse(); parsed = true; } // We report errors other than unexpected EOF to the user. catch (CompilationFailedException e) { if (parser.getErrorCollector().getErrorCount() > 1 || !parser.failedWithUnexpectedEOF()) { error = e; } } catch (Exception e) { error = e; } return parsed; }
/** * Attempts to parse the specified code with the specified tolerance. * Updates the <code>parser</code> and <code>error</code> members * appropriately. Returns true if the text parsed, false otherwise. * The attempts to identify and suppress errors resulting from the * unfinished source text. */ private boolean parse(final String code, final int tolerance) { assert code != null; boolean parsed = false; parser = null; error = null; // Create the parser and attempt to parse the text as a top-level statement. try { parser = SourceUnit.create("groovysh-script", code, tolerance); parser.parse(); parsed = true; } // We report errors other than unexpected EOF to the user. catch (CompilationFailedException e) { if (parser.getErrorCollector().getErrorCount() > 1 || !parser.failedWithUnexpectedEOF()) { error = e; } } catch (Exception e) { error = e; } return parsed; }
/** * Attempts to parse the specified code with the specified tolerance. * Updates the <code>parser</code> and <code>error</code> members * appropriately. Returns true if the text parsed, false otherwise. * The attempts to identify and suppress errors resulting from the * unfinished source text. */ private boolean parse(final String code, final int tolerance) { assert code != null; boolean parsed = false; parser = null; error = null; // Create the parser and attempt to parse the text as a top-level statement. try { parser = SourceUnit.create("groovysh-script", code, tolerance); parser.parse(); parsed = true; } // We report errors other than unexpected EOF to the user. catch (CompilationFailedException e) { if (parser.getErrorCollector().getErrorCount() > 1 || !parser.failedWithUnexpectedEOF()) { error = e; } } catch (Exception e) { error = e; } return parsed; }