Example usage for org.eclipse.jdt.core.dom CompilationUnit subtreeMatch

List of usage examples for org.eclipse.jdt.core.dom CompilationUnit subtreeMatch

Introduction

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

Prototype

public final boolean subtreeMatch(ASTMatcher matcher, Object other) 

Source Link

Document

Returns whether the subtree rooted at the given node matches the given other object as decided by the given matcher.

Usage

From source file:de.fkoeberle.autocommit.message.java.helper.JavaFormatationChecker.java

License:Open Source License

/**
 * Checks for a given file if there are only whitespace changes.
 * /*from   www  . ja  va 2 s.  co m*/
 * @param changedFile
 *            the file to check.
 * @return true if it can be guaranteed that there were only formation
 *         changes and false otherwise.
 * @throws IOException
 */
public boolean foundJavaFormatationChangesOnly(JavaFileDelta javaFileDelta) throws IOException {
    Map<JavaFileDelta, Boolean> map = getCachableValue();
    Boolean result = map.get(javaFileDelta);
    if (result == null) {
        CompilationUnit oldContent = javaFileDelta.getOldDeclaration();
        CompilationUnit newContent = javaFileDelta.getNewDeclaration();

        if (containsProblems(oldContent)) {
            return false;
        }
        if (containsProblems(newContent)) {
            return false;
        }
        boolean match = oldContent.subtreeMatch(new ASTMatcher(true), newContent);
        result = Boolean.valueOf(match);
        map.put(javaFileDelta, result);
    }

    return result.booleanValue();
}

From source file:org.whole.lang.java.JavaImportExportTests.java

License:Open Source License

@SuppressWarnings("unchecked")
private boolean performTest(String source) throws Exception {
    CompilationUnit cu = JDTUtils.parseAsCompilationUnit(source);
    IEntity model = JDTTransformerVisitor.transform(source, cu);

    String newSource = PrettyPrinterOperation.toPrettyPrintString(model);
    CompilationUnit cuReparsed = JDTUtils.parseAsCompilationUnit(newSource);

    for (Comment element : (List<Comment>) cu.getCommentList())
        element.delete();//w ww. ja v a2 s.c o m

    boolean subtreeMatch = cu.subtreeMatch(new SemanticASTMatcher(), cuReparsed);
    return subtreeMatch;
}