List of usage examples for org.eclipse.jdt.core.dom Message getStartPosition
public int getStartPosition()
From source file:com.google.googlejavaformat.java.Formatter.java
License:Apache License
/** * Construct a {@code Formatter} given Java compilation unit. Parses the code; builds a * {@link JavaInput} and the corresponding {@link JavaOutput}. * @param javaInput the input, a Java compilation unit * @param javaOutput the {@link JavaOutput} * @param maxWidth the maximum formatted width * @param errors mutable list to receive errors * @param indentationMultiplier the multiplier for the unit of indent; the default is 1 */// w w w .j a v a 2 s .com static void format(JavaInput javaInput, JavaOutput javaOutput, int maxWidth, List<FormatterDiagnostic> errors, int indentationMultiplier) { ASTParser parser = ASTParser.newParser(AST.JLS8); parser.setSource(javaInput.getText().toCharArray()); @SuppressWarnings("unchecked") // safe by specification Map<String, String> options = JavaCore.getOptions(); JavaCore.setComplianceOptions(JavaCore.VERSION_1_8, options); parser.setCompilerOptions(options); CompilationUnit unit = (CompilationUnit) parser.createAST(null); javaInput.setCompilationUnit(unit); if (unit.getMessages().length > 0) { for (Message message : unit.getMessages()) { errors.add(javaInput.createDiagnostic(message.getStartPosition(), message.getMessage())); } return; } OpsBuilder builder = new OpsBuilder(javaInput, javaOutput, errors); // Output compilation unit. new JavaInputAstVisitor(builder, indentationMultiplier).visit(unit); builder.sync(javaInput.getText().length()); builder.drain(); Doc doc = new DocBuilder().withOps(builder.build()).build(); doc.computeBreaks(javaOutput.getCommentsHelper(), maxWidth, new Doc.State(+0, 0, 0)); doc.write(javaOutput); javaOutput.flush(); }
From source file:org.modeshape.sequencer.javafile.JdtRecorder.java
License:Apache License
protected void recordCompilerMessages(final CompilationUnit unit, final Node parentNode) throws Exception { final Message[] messages = unit.getMessages(); if ((messages != null) && (messages.length != 0)) { final Node containerNode = parentNode.addNode(ClassFileSequencerLexicon.MESSAGES, ClassFileSequencerLexicon.MESSAGES); for (final Message message : messages) { final Node messageNode = containerNode.addNode(ClassFileSequencerLexicon.MESSAGE, ClassFileSequencerLexicon.MESSAGE); messageNode.setProperty(ClassFileSequencerLexicon.MESSAGE, message.getMessage()); messageNode.setProperty(ClassFileSequencerLexicon.START_POSITION, message.getStartPosition()); messageNode.setProperty(ClassFileSequencerLexicon.LENGTH, message.getLength()); }/*from w w w.j a v a 2 s.c o m*/ } }