/** * @return the underlying character stream description */ public String getDescription() { if( context != null ) { return context.getName(); } else { return this.description; } }
public void write( PrintWriter writer, Janitor janitor ) { if( owner instanceof SourceUnit ) { String name = ((SourceUnit)owner).getName(); writer.println( "" + name + ": " + message ); } else { writer.println( message ); } }
public SyntaxErrorMessage(SyntaxException cause, SourceUnit source) { this.cause = cause; this.source = source; cause.setSourceLocator(source.getName()); }
private int ensureStackNotEmpty(List<ClassNode> stack) { int size = stack.size(); try { if (size == 0) throw new ArrayIndexOutOfBoundsException("size==0"); } catch (ArrayIndexOutOfBoundsException ai) { System.err.println("index problem in " + controller.getSourceUnit().getName()); throw ai; } return size; }
/** * Dequeues any source units add through addSource and resets the compiler phase * to initialization. * <p> * Note: this does not mean a file is recompiled. If a SourceUnit has already passed * a phase it is skipped until a higher phase is reached. * * @return true if there was a queued source * @throws CompilationFailedException */ protected boolean dequeued() throws CompilationFailedException { boolean dequeue = !queuedSources.isEmpty(); while (!queuedSources.isEmpty()) { SourceUnit su = queuedSources.removeFirst(); String name = su.getName(); names.add(name); sources.put(name, su); } if (dequeue) { gotoPhase(Phases.INITIALIZATION); } return dequeue; }
private void throwExceptionForNoStackElement(int size, ClassNode targetType, boolean coerce) { if (size>0) return; StringBuilder sb = new StringBuilder(); sb.append("Internal compiler error while compiling ").append(controller.getSourceUnit().getName()).append("\n"); MethodNode methodNode = controller.getMethodNode(); if (methodNode!=null) { sb.append("Method: "); sb.append(methodNode); sb.append("\n"); } ConstructorNode constructorNode = controller.getConstructorNode(); if (constructorNode!=null) { sb.append("Constructor: "); sb.append(methodNode); sb.append("\n"); } sb.append("Line ").append(controller.getLineNumber()).append(","); sb.append(" expecting ").append(coerce ? "coercion" : "casting").append(" to ").append(targetType.toString(false)); sb.append(" but operand stack is empty"); throw new ArrayIndexOutOfBoundsException(sb.toString()); }
private String getPath(Class clazz, Map<String, String> precompiledEntries) { CompilationUnit cu = getLocalData().get().cu; String name = clazz.getName(); ClassNode classNode = cu.getClassNode(name); if (classNode == null) { // this is a precompiled class! String path = precompiledEntries.get(name); if (path == null) throw new GroovyBugError("Precompiled class " + name + " should be available in precompiled entries map, but was not."); return path; } else { return classNode.getModule().getContext().getName(); } }
public void write( PrintWriter writer, Janitor janitor ) { if (owner instanceof SourceUnit) { SourceUnit source = (SourceUnit) owner; String name = source.getName(); int line = context.getStartLine(); int column = context.getStartColumn(); String sample = source.getSample( line, column, janitor ); if( sample != null ) { writer.println( source.getSample(line, column, janitor) ); } writer.println( name + ": " + line + ": " + this.message ); writer.println(""); } else { writer.println( "<No Relevant Source>: " + this.message ); writer.println(""); } }
saveAsXML(sourceUnit.getName(), ast); PrintStream out = new PrintStream(new FileOutputStream(sourceUnit.getName() + ".pretty.groovy")); Visitor visitor = new SourcePrinter(out, tokenNames); AntlrASTProcessor treewalker = new SourceCodeTraversal(visitor); treewalker.process(ast); } catch (FileNotFoundException e) { System.out.println("Cannot create " + sourceUnit.getName() + ".pretty.groovy"); PrintStream out = new PrintStream(new FileOutputStream(sourceUnit.getName() + ".mm")); Visitor visitor = new MindMapPrinter(out, tokenNames); AntlrASTProcessor treewalker = new PreOrderTraversal(visitor); treewalker.process(ast); } catch (FileNotFoundException e) { System.out.println("Cannot create " + sourceUnit.getName() + ".mm"); PrintStream out = new PrintStream(new FileOutputStream(sourceUnit.getName() + ".mm")); Visitor visitor = new MindMapPrinter(out, tokenNames, sourceBuffer); AntlrASTProcessor treewalker = new PreOrderTraversal(visitor); treewalker.process(ast); } catch (FileNotFoundException e) { System.out.println("Cannot create " + sourceUnit.getName() + ".mm"); PrintStream out = new PrintStream(new FileOutputStream(sourceUnit.getName() + ".html")); List<VisitorAdapter> v = new ArrayList<VisitorAdapter>(); v.add(new NodeAsHTMLPrinter(out, tokenNames)); treewalker.process(ast); } catch (FileNotFoundException e) {
private void changeBugText(GroovyBugError e, SourceUnit context) { e.setBugText("exception in phase '" + getPhaseDescription() + "' in source unit '" + ((context != null) ? context.getName() : "?") + "' " + e.getBugText()); }
/** * Writes out a nicely formatted summary of the syntax error. */ public void write(PrintWriter output, Janitor janitor) { String name = source.getName(); int line = getCause().getStartLine(); int column = getCause().getStartColumn(); String sample = source.getSample(line, column, janitor); output.print(name + ": " + line + ": " + getCause().getMessage()); if (sample != null) { output.println(); output.print(sample); output.println(); } }
.append(name) .append(" in ") .append(su.getName()); if (classesInSourceUnit.isEmpty()) { message.append(", but the file seems not to contain any classes");
public SourceTextNotAvailableException(AssertStatement stat, SourceUnit unit, String msg) { super(String.format("%s for %s at (%d,%d)-(%d,%d) in %s", msg, stat.getBooleanExpression().getText(), stat.getLineNumber(), stat.getColumnNumber(), stat.getLastLineNumber(), stat.getLastColumnNumber(), unit.getName())); } }
@Override public void call(final SourceUnit source, final GeneratorContext context, final ClassNode classNode) throws CompilationFailedException { String fileName = source.getName(); ReaderSource reader = source.getSource(); if (reader instanceof FileReaderSource) { FileReaderSource file = (FileReaderSource) reader; fileName = file.getFile().getName(); } if (acceptSource(source) && acceptClass(classNode) && accept(fileName)) { delegate.call(source, context, classNode); } }
private void addSpecMetadata(Spec spec) { AnnotationNode ann = new AnnotationNode(nodeCache.SpecMetadata); String pathname = spec.getAst().getModule().getContext().getName(); String filename = new File(pathname).getName(); ann.setMember(SpecMetadata.FILENAME, new ConstantExpression(filename)); ann.setMember(SpecMetadata.LINE, new ConstantExpression(spec.getAst().getLineNumber())); spec.getAst().addAnnotation(ann); }
if (nodeSource == storedSource) { txt += "The source " + nodeSource.getName() + " contains at least two definitions of the class " + node.getName() + ".\n"; if (node.isScriptBody() || stored.isScriptBody()) { txt += "One of the classes is an explicit generated class using the class statement, the other is a class generated from" + txt += "The sources " + nodeSource.getName() + " and " + storedSource.getName() + " each contain a class with the name " + node.getName() + ".\n";
public ModuleNode buildAST(SourceUnit sourceUnit, ClassLoader classLoader, Reduction cst) throws ParserException { setClassLoader(classLoader); makeModule(); try { convertGroovy(ast); if (output.getStatementBlock().isEmpty() && output.getMethods().isEmpty() && output.getClasses().isEmpty()) { output.addStatement(ReturnStatement.RETURN_NULL_OR_VOID); } // set the script source position ClassNode scriptClassNode = output.getScriptClassDummy(); if (scriptClassNode != null) { List<Statement> statements = output.getStatementBlock().getStatements(); if (!statements.isEmpty()) { Statement firstStatement = statements.get(0); Statement lastStatement = statements.get(statements.size() - 1); scriptClassNode.setSourcePosition(firstStatement); scriptClassNode.setLastColumnNumber(lastStatement.getLastColumnNumber()); scriptClassNode.setLastLineNumber(lastStatement.getLastLineNumber()); } } } catch (ASTRuntimeException e) { throw new ASTParserException(e.getMessage() + ". File: " + sourceUnit.getName(), e); } return output; }
parser.setSourceBuffer(sourceBuffer); tokenNames = parser.getTokenNames(); parser.setFilename(sourceUnit.getName());