Search in sources :

Example 1 with ICodeAssist

use of org.eclipse.jdt.core.ICodeAssist in project che by eclipse.

the class JavaNavigation method findDeclaration.

public OpenDeclarationDescriptor findDeclaration(IJavaProject project, String fqn, int offset) throws JavaModelException {
    IJavaElement originalElement = null;
    IType type = project.findType(fqn);
    ICodeAssist codeAssist;
    if (type.isBinary()) {
        codeAssist = type.getClassFile();
    } else {
        codeAssist = type.getCompilationUnit();
    }
    IJavaElement[] elements = null;
    if (codeAssist != null) {
        elements = codeAssist.codeSelect(offset, 0);
    }
    if (elements != null && elements.length > 0) {
        originalElement = elements[0];
    }
    IJavaElement element = originalElement;
    while (element != null) {
        if (element instanceof ICompilationUnit) {
            ICompilationUnit unit = ((ICompilationUnit) element).getPrimary();
            return compilationUnitNavigation(unit, originalElement);
        }
        if (element instanceof IClassFile) {
            return classFileNavigation((IClassFile) element, originalElement);
        }
        element = element.getParent();
    }
    return null;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) ICodeAssist(org.eclipse.jdt.core.ICodeAssist) IClassFile(org.eclipse.jdt.core.IClassFile) IType(org.eclipse.jdt.core.IType)

Example 2 with ICodeAssist

use of org.eclipse.jdt.core.ICodeAssist in project che by eclipse.

the class JavaTypeHierarchy method getJavaElement.

private IJavaElement getJavaElement(IJavaProject project, String fqn, int offset) throws JavaModelException {
    IJavaElement originalElement = null;
    IType type = project.findType(fqn);
    ICodeAssist codeAssist;
    if (type.isBinary()) {
        codeAssist = type.getClassFile();
    } else {
        codeAssist = type.getCompilationUnit();
    }
    IJavaElement[] elements = null;
    if (codeAssist != null) {
        elements = codeAssist.codeSelect(offset, 0);
    }
    if (elements != null && elements.length > 0) {
        originalElement = elements[0];
    }
    return originalElement;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) ICodeAssist(org.eclipse.jdt.core.ICodeAssist) IType(org.eclipse.jdt.core.IType)

Example 3 with ICodeAssist

use of org.eclipse.jdt.core.ICodeAssist in project che by eclipse.

the class JavadocFinder method findJavadoc.

public String findJavadoc(IJavaProject project, String fqn, int offset) throws JavaModelException {
    IMember member = null;
    IType type = project.findType(fqn);
    ICodeAssist codeAssist;
    if (type.isBinary()) {
        codeAssist = type.getClassFile();
    } else {
        codeAssist = type.getCompilationUnit();
    }
    IJavaElement[] elements = null;
    if (codeAssist != null) {
        elements = codeAssist.codeSelect(/*region.getOffset(), region.getLength()*/
        offset, 0);
    }
    IJavaElement element = null;
    if (elements != null && elements.length > 0) {
        element = elements[0];
    }
    if (element != null && element instanceof IMember) {
        member = ((IMember) element);
    }
    if (member == null) {
        return null;
    }
    return getJavadoc(member);
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) ICodeAssist(org.eclipse.jdt.core.ICodeAssist) IMember(org.eclipse.jdt.core.IMember) IType(org.eclipse.jdt.core.IType)

Aggregations

ICodeAssist (org.eclipse.jdt.core.ICodeAssist)3 IJavaElement (org.eclipse.jdt.core.IJavaElement)3 IType (org.eclipse.jdt.core.IType)3 IClassFile (org.eclipse.jdt.core.IClassFile)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 IMember (org.eclipse.jdt.core.IMember)1