Search in sources :

Example 1 with IJavaReferenceType

use of org.eclipse.jdt.debug.core.IJavaReferenceType in project xtext-eclipse by eclipse.

the class XbaseLineBreakpoint method computeJavaProject.

// old working implementation copied from 3.8
private IJavaProject computeJavaProject(IJavaStackFrame stackFrame) {
    ILaunch launch = stackFrame.getLaunch();
    if (launch == null) {
        return null;
    }
    ISourceLocator locator = launch.getSourceLocator();
    if (locator == null)
        return null;
    Object sourceElement = null;
    try {
        if (locator instanceof ISourceLookupDirector && !stackFrame.isStatic()) {
            IJavaType thisType = stackFrame.getThis().getJavaType();
            if (thisType instanceof IJavaReferenceType) {
                String[] sourcePaths = ((IJavaReferenceType) thisType).getSourcePaths(null);
                if (sourcePaths != null && sourcePaths.length > 0) {
                    sourceElement = ((ISourceLookupDirector) locator).getSourceElement(sourcePaths[0]);
                }
            }
        }
    } catch (DebugException e) {
        DebugPlugin.log(e);
    }
    if (sourceElement == null) {
        sourceElement = locator.getSourceElement(stackFrame);
    }
    if (!(sourceElement instanceof IJavaElement) && sourceElement instanceof IAdaptable) {
        Object element = ((IAdaptable) sourceElement).getAdapter(IJavaElement.class);
        if (element != null) {
            sourceElement = element;
        }
    }
    if (sourceElement instanceof IJavaElement) {
        return ((IJavaElement) sourceElement).getJavaProject();
    } else if (sourceElement instanceof IResource) {
        IJavaProject project = JavaCore.create(((IResource) sourceElement).getProject());
        if (project.exists()) {
            return project;
        }
    }
    return null;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IAdaptable(org.eclipse.core.runtime.IAdaptable) ISourceLookupDirector(org.eclipse.debug.core.sourcelookup.ISourceLookupDirector) IJavaReferenceType(org.eclipse.jdt.debug.core.IJavaReferenceType) DebugException(org.eclipse.debug.core.DebugException) IJavaProject(org.eclipse.jdt.core.IJavaProject) IJavaType(org.eclipse.jdt.debug.core.IJavaType) ILaunch(org.eclipse.debug.core.ILaunch) ISourceLocator(org.eclipse.debug.core.model.ISourceLocator) IResource(org.eclipse.core.resources.IResource)

Aggregations

IResource (org.eclipse.core.resources.IResource)1 IAdaptable (org.eclipse.core.runtime.IAdaptable)1 DebugException (org.eclipse.debug.core.DebugException)1 ILaunch (org.eclipse.debug.core.ILaunch)1 ISourceLocator (org.eclipse.debug.core.model.ISourceLocator)1 ISourceLookupDirector (org.eclipse.debug.core.sourcelookup.ISourceLookupDirector)1 IJavaElement (org.eclipse.jdt.core.IJavaElement)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 IJavaReferenceType (org.eclipse.jdt.debug.core.IJavaReferenceType)1 IJavaType (org.eclipse.jdt.debug.core.IJavaType)1