Example usage for org.eclipse.jdt.core.dom Message getMessage

List of usage examples for org.eclipse.jdt.core.dom Message getMessage

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom Message getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the localized message.

Usage

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  ww.  ja  va 2 s . c o  m*/
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:edu.cmu.cs.crystal.tac.eclipse.EclipseTACSimpleTestDriver.java

License:Open Source License

public static CompilationUnit parseCode(String qualifiedCompUnitName, String code) throws CoreException {
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    CompilationUnit node;/*from www . ja  v  a2  s.  c  o m*/

    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("CrystalTest");
    project.open(null /* IProgressMonitor */);

    IJavaProject javaProject = JavaCore.create(project);

    parser.setKind(ASTParser.K_COMPILATION_UNIT);
    parser.setProject(javaProject);
    parser.setSource(code.toCharArray());
    parser.setUnitName("/CrystalTest/" + qualifiedCompUnitName);
    parser.setResolveBindings(true);
    node = (CompilationUnit) parser.createAST(null);

    Message[] msgs = node.getMessages();
    if (msgs.length > 0) {
        StringBuffer errs = new StringBuffer();
        errs.append("Compiler problems for ");
        errs.append(qualifiedCompUnitName);
        for (Message m : msgs) {
            errs.append('\n');
            errs.append(m.getMessage());
        }
        throw new IllegalArgumentException(errs.toString());
    }

    return node;
}

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());
        }//w  w  w . ja v  a2s .c om
    }
}