Example usage for org.eclipse.jdt.core IJavaElement getCorrespondingResource

List of usage examples for org.eclipse.jdt.core IJavaElement getCorrespondingResource

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IJavaElement getCorrespondingResource.

Prototype

IResource getCorrespondingResource() throws JavaModelException;

Source Link

Document

Returns the resource that corresponds directly to this element, or null if there is no resource that corresponds to this element.

Usage

From source file:org.spoofax.interpreter.library.ecj.ECJ_path_of_compilationunit.java

License:LGPL

@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars) throws InterpreterException {

    if (!ECJTools.isCompilationUnit(tvars[0]))
        return false;

    CompilationUnit n = ECJTools.asCompilationUnit(tvars[0]);

    IJavaElement je = n.getJavaElement();
    if (je == null)
        return false;

    try {/*w w  w  .  j a  v a2 s. c  o  m*/
        env.setCurrent(ECJFactory.wrap(je.getCorrespondingResource().getProjectRelativePath().toString()));
    } catch (JavaModelException e) {
        return false;
    }
    return true;
}

From source file:org.springframework.ide.eclipse.core.model.java.JavaModelSourceLocation.java

License:Open Source License

public Resource getResource() {
    try {//from w  ww  .jav a 2 s.  co m
        IJavaElement element = JdtUtils.getByHandle(handleIdentifier);
        if (element != null) {
            IResource resource = element.getUnderlyingResource();
            if (resource != null) {
                return new FileResource(resource.getFullPath().toString());
            }
            resource = element.getCorrespondingResource();
            if (resource != null) {
                return new FileResource(resource.getFullPath().toString());
            }
            resource = element.getResource();
            if (resource != null) {
                return new FileResource(resource.getFullPath().toString());
            }
            IPath path = element.getPath();
            if (path != null && path.toFile().exists()) {
                if (path.isAbsolute()) {
                    return new FileSystemResource(path.toFile());
                } else {
                    return new FileResource(path.toString());
                }
            }
        }
    } catch (JavaModelException e) {
    }
    return null;
}