Example usage for org.eclipse.jdt.core.dom ASTNode getRoot

List of usage examples for org.eclipse.jdt.core.dom ASTNode getRoot

Introduction

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

Prototype

public final ASTNode getRoot() 

Source Link

Document

Returns the root node at or above this node; returns this node if it is a root.

Usage

From source file:cc.kave.eclipse.namefactory.NodeFactory.java

License:Apache License

private static String getDeclaringType(ASTNode node) {
    return BindingFactory.getBindingName(
            ((TypeDeclaration) ((CompilationUnit) node.getRoot()).types().get(0)).resolveBinding());
}

From source file:com.architexa.diagrams.jdt.builder.ReloASTExtractor.java

License:Open Source License

@SuppressWarnings("deprecation")
public void dumpContext() {
    System.err.println("Extractor context:");
    Iterator<ASTNode> it = context.iterator();
    while (it.hasNext()) {
        ASTNode node = it.next();
        System.err.print(" " + node.getClass());
        System.err.print("[" + node.getStartPosition() + "+" + node.getLength());
        if (node.getRoot() instanceof CompilationUnit)
            System.err.print("/line:" + ((CompilationUnit) node.getRoot()).lineNumber(node.getLength()));
        System.err.println("]: " + getNodeKey(node));
    }/*  w ww. j  a va2 s.  com*/
}

From source file:com.bsiag.eclipse.jdt.java.formatter.DefaultCodeFormatter.java

License:Open Source License

private ASTNode parseSourceCode(ASTParser parser, int parserMode, boolean ignoreErrors) {
    parser.setKind(parserMode);/*from  w ww  .  j  ava  2s .c o m*/
    parser.setSource(this.sourceArray);
    ASTNode astNode = parser.createAST(null);
    if (ignoreErrors)
        return astNode;

    boolean hasErrors = false;
    CompilationUnit root = (CompilationUnit) astNode.getRoot();
    for (IProblem problem : root.getProblems()) {
        if (problem.isError()) {
            hasErrors = true;
            break;
        }
    }
    return hasErrors ? null : astNode;
}

From source file:com.google.appengine.eclipse.core.validators.java.JavaCompilationParticipant.java

License:Open Source License

public static List<? extends CategorizedProblem> validateCompilationUnit(ASTNode ast) {
    CompilationUnit root = (CompilationUnit) ast.getRoot();
    ICompilationUnit cu = (ICompilationUnit) root.getJavaElement();

    // If the compilation unit is not on the build classpath, return an empty
    // list of problems.
    if (!cu.getJavaProject().isOnClasspath(cu)) {
        return Collections.emptyList();
    }/*from w w w. j a v  a2  s. co m*/

    List<IPath> validationExclusionPatterns = GaeProjectProperties
            .getValidationExclusionPatterns(cu.getJavaProject().getProject());
    char[][] exclusionPatterns = null;
    if (!validationExclusionPatterns.isEmpty()) {
        exclusionPatterns = new char[validationExclusionPatterns.size()][];
        for (int i = 0; i < validationExclusionPatterns.size(); ++i) {
            exclusionPatterns[i] = validationExclusionPatterns.get(i).toString().toCharArray();
        }
    }

    // Get the source root relative path, since our exclusion filter does
    // not include the project name, but the compilation unit's path does.
    IPath sourceRelativePath = cu.getPath().removeFirstSegments(1);
    if (Util.isExcluded(sourceRelativePath, null, exclusionPatterns, false)) {
        return Collections.emptyList();
    }

    List<CategorizedProblem> problems = GoogleCloudSqlChecker.check(root, cu.getJavaProject());
    problems.addAll(GaeChecker.check(root, cu.getJavaProject()));

    return problems;
}

From source file:com.google.currysrc.api.process.ast.PackageMatcher.java

License:Apache License

/**
 * Returns the package name of the compilation unit associated with the supplied node.
 *//*from ww  w  . j a v a  2  s  . c  om*/
public static String getPackageName(ASTNode node) {
    CompilationUnit compilationUnit = (CompilationUnit) node.getRoot();
    PackageDeclaration packageDeclaration = compilationUnit.getPackage();
    if (packageDeclaration == null) {
        return "";
    }
    return packageDeclaration.getName().getFullyQualifiedName();
}

From source file:com.google.devtools.j2cpp.gen.CppStatementGenerator.java

License:Open Source License

private CppStatementGenerator(ASTNode node, Set<IVariableBinding> fieldHiders, boolean asFunction,
        int startLine) {
    CompilationUnit unit = node != null ? (CompilationUnit) node.getRoot() : null;
    buffer = new SourceBuilder(unit, Options.emitLineDirectives(), startLine);
    this.fieldHiders = fieldHiders;
    this.asFunction = asFunction;
    useReferenceCounting = !Options.useARC();
}

From source file:com.google.devtools.j2cpp.J2ObjC.java

License:Open Source License

private static int getNodeLine(ASTNode node) {
    CompilationUnit unit = (CompilationUnit) node.getRoot();
    return unit.getLineNumber(node.getStartPosition());
}

From source file:com.google.devtools.j2objc.ast.TreeNode.java

License:Apache License

protected TreeNode(ASTNode jdtNode) {
    this();//from w  w  w  .ja v a 2  s. co m
    startPosition = jdtNode.getStartPosition();
    length = jdtNode.getLength();
    ASTNode root = jdtNode.getRoot();
    if (root instanceof org.eclipse.jdt.core.dom.CompilationUnit) {
        lineNumber = ((org.eclipse.jdt.core.dom.CompilationUnit) root).getLineNumber(startPosition);
    }
}

From source file:com.google.devtools.j2objc.jdt.TreeConverter.java

License:Apache License

private static SourcePosition getPosition(ASTNode jdtNode) {
    int startPosition = jdtNode.getStartPosition();
    int length = jdtNode.getLength();
    ASTNode root = jdtNode.getRoot();
    if (root instanceof org.eclipse.jdt.core.dom.CompilationUnit) {
        int line = ((org.eclipse.jdt.core.dom.CompilationUnit) root).getLineNumber(startPosition);
        return new SourcePosition(startPosition, length, line);
    } else {//  w w  w  .j  av  a2 s  .  c o  m
        return new SourcePosition(startPosition, length);
    }
}

From source file:com.google.gdt.eclipse.core.JavaASTUtils.java

License:Open Source License

/**
 * Gets the compilation unit containing a particular Java AST node.
 *///from  ww w .  j a  v  a2  s .  c o  m
public static ICompilationUnit getCompilationUnit(ASTNode node) {
    CompilationUnit root = (CompilationUnit) node.getRoot();
    ICompilationUnit cu = (ICompilationUnit) root.getJavaElement();
    return cu;
}