Search in sources :

Example 11 with IClassFile

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

the class ClassFileBasedOpenerContributor method collectSourceFileOpeners.

@Override
public boolean collectSourceFileOpeners(IEditorPart editor, IAcceptor<FileOpener> acceptor) {
    if (!(editor instanceof XtextEditor) && editor.getEditorInput() != null) {
        try {
            IClassFile classFile = Adapters.adapt(editor, IClassFile.class);
            if (classFile == null) {
                return false;
            }
            ITrace trace = traceForTypeRootProvider.getTraceToSource(classFile);
            if (trace == null) {
                return false;
            }
            for (ILocationInResource location : trace.getAllAssociatedLocations()) {
                String name = location.getAbsoluteResourceURI().getURI().lastSegment();
                IEditorDescriptor editorDescriptor = IDE.getEditorDescriptor(name);
                acceptor.accept(createEditorOpener(editor.getEditorInput(), editorDescriptor.getId()));
                return true;
            }
        } catch (PartInitException e) {
            LOG.error(e.getMessage(), e);
        }
    }
    return false;
}
Also used : IClassFile(org.eclipse.jdt.core.IClassFile) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) ITrace(org.eclipse.xtext.generator.trace.ITrace) PartInitException(org.eclipse.ui.PartInitException) ILocationInResource(org.eclipse.xtext.generator.trace.ILocationInResource)

Example 12 with IClassFile

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

the class JavaBreakPointProvider method getJavaTrace.

private IEclipseTrace getJavaTrace(final IJavaStratumLineBreakpoint breakpoint) throws CoreException {
    IEclipseTrace result;
    IClassFile classFile = getClassFile(breakpoint);
    if (classFile == null) {
        URI uri = URI.createURI((String) breakpoint.getMarker().getAttribute(StratumBreakpointAdapterFactory.ORG_ECLIPSE_XTEXT_XBASE_SOURCE_URI));
        Pair<IStorage, IProject> storage = Iterables.getFirst(storage2UriMapper.getStorages(uri), null);
        if (storage == null)
            return null;
        result = traceForStorageProvider.getTraceToTarget(storage.getFirst());
    } else {
        result = traceForTypeRootProvider.getTraceToSource(classFile);
    }
    return result;
}
Also used : IClassFile(org.eclipse.jdt.core.IClassFile) IEclipseTrace(org.eclipse.xtext.ui.generator.trace.IEclipseTrace) IStorage(org.eclipse.core.resources.IStorage) URI(org.eclipse.emf.common.util.URI) IProject(org.eclipse.core.resources.IProject)

Example 13 with IClassFile

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

the class XbaseDocumentProvider method setDocumentContent.

@Override
protected boolean setDocumentContent(IDocument document, IEditorInput input, String encoding) throws CoreException {
    if (input instanceof IClassFileEditorInput && document instanceof XtextDocument) {
        IClassFile classFile = ((IClassFileEditorInput) input).getClassFile();
        ILocationInEclipseResource source = getClassFileSourceStorage(classFile);
        if (source == null) {
            return false;
        }
        InputStream contents = null;
        try {
            contents = source.getContents();
            if (contents != null)
                setDocumentContent(document, contents, encoding);
        } catch (WrappedCoreException e) {
            throw e.getCause();
        } catch (IOException e) {
            throw new CoreException(new Status(IStatus.ERROR, plugin.getBundle().getSymbolicName(), e.getMessage(), e));
        } finally {
            try {
                if (contents != null)
                    contents.close();
            } catch (IOException e1) {
            }
        }
        setDocumentResource((XtextDocument) document, input, encoding);
        return true;
    }
    return super.setDocumentContent(document, input, encoding);
}
Also used : ILocationInEclipseResource(org.eclipse.xtext.ui.generator.trace.ILocationInEclipseResource) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IClassFile(org.eclipse.jdt.core.IClassFile) CoreException(org.eclipse.core.runtime.CoreException) WrappedCoreException(org.eclipse.xtext.ui.generator.trace.WrappedCoreException) InputStream(java.io.InputStream) XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) WrappedCoreException(org.eclipse.xtext.ui.generator.trace.WrappedCoreException) IOException(java.io.IOException) IClassFileEditorInput(org.eclipse.jdt.internal.ui.javaeditor.IClassFileEditorInput)

Example 14 with IClassFile

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

the class AbstractJavaSearchResult method getFile.

/* (non-Javadoc)
     * @see org.eclipse.search.ui.ISearchResultCategory#getFile(java.lang.Object)
     */
public IFile getFile(Object element) {
    if (element instanceof IJavaElement) {
        IJavaElement javaElement = (IJavaElement) element;
        ICompilationUnit cu = (ICompilationUnit) javaElement.getAncestor(IJavaElement.COMPILATION_UNIT);
        if (cu != null) {
            return (IFile) cu.getResource();
        } else {
            IClassFile cf = (IClassFile) javaElement.getAncestor(IJavaElement.CLASS_FILE);
            if (cf != null)
                return (IFile) cf.getResource();
        }
        return null;
    }
    if (element instanceof IFile)
        return (IFile) element;
    return null;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IFile(org.eclipse.core.resources.IFile) IClassFile(org.eclipse.jdt.core.IClassFile)

Example 15 with IClassFile

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

the class JavaDebuggerUtils method getLocation.

/**
     * Returns Location for current debugger resource.
     *
     * @param location
     *         location type from JVM
     * @throws DebuggerException
     *         in case {@link org.eclipse.jdt.core.JavaModelException} or if Java {@link org.eclipse.jdt.core.IType}
     *         was not find
     */
public Location getLocation(com.sun.jdi.Location location) throws DebuggerException {
    String fqn = location.declaringType().name();
    List<IType> types;
    try {
        Pair<char[][], char[][]> fqnPair = prepareFqnToSearch(fqn);
        types = findTypeByFqn(fqnPair.first, fqnPair.second, createWorkspaceScope());
    } catch (JavaModelException e) {
        throw new DebuggerException("Can't find class models by fqn: " + fqn, e);
    }
    if (types.isEmpty()) {
        throw new DebuggerException("Type with fully qualified name: " + fqn + " was not found");
    }
    //TODO we need handle few result! It's temporary solution.
    IType type = types.get(0);
    String typeProjectPath = type.getJavaProject().getPath().toOSString();
    if (type.isBinary()) {
        IClassFile classFile = type.getClassFile();
        int libId = classFile.getAncestor(IPackageFragmentRoot.PACKAGE_FRAGMENT_ROOT).hashCode();
        return new LocationImpl(fqn, location.lineNumber(), null, true, libId, typeProjectPath);
    } else {
        ICompilationUnit compilationUnit = type.getCompilationUnit();
        typeProjectPath = type.getJavaProject().getPath().toOSString();
        String resourcePath = compilationUnit.getPath().toOSString();
        return new LocationImpl(fqn, location.lineNumber(), resourcePath, false, -1, typeProjectPath);
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) JavaModelException(org.eclipse.jdt.core.JavaModelException) IClassFile(org.eclipse.jdt.core.IClassFile) DebuggerException(org.eclipse.che.api.debugger.server.exceptions.DebuggerException) LocationImpl(org.eclipse.che.api.debug.shared.model.impl.LocationImpl) IType(org.eclipse.jdt.core.IType)

Aggregations

IClassFile (org.eclipse.jdt.core.IClassFile)34 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)20 IJavaElement (org.eclipse.jdt.core.IJavaElement)13 IType (org.eclipse.jdt.core.IType)9 JavaModelException (org.eclipse.jdt.core.JavaModelException)8 CoreException (org.eclipse.core.runtime.CoreException)7 ArrayList (java.util.ArrayList)6 ISourceRange (org.eclipse.jdt.core.ISourceRange)5 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)4 ITypeRoot (org.eclipse.jdt.core.ITypeRoot)4 BadLocationException (org.eclipse.jface.text.BadLocationException)4 IResource (org.eclipse.core.resources.IResource)3 IStorage (org.eclipse.core.resources.IStorage)3 IMethod (org.eclipse.jdt.core.IMethod)3 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)3 ISourceReference (org.eclipse.jdt.core.ISourceReference)3 Document (org.eclipse.jface.text.Document)3 IOException (java.io.IOException)2 DebuggerException (org.eclipse.che.api.debugger.server.exceptions.DebuggerException)2 JarEntry (org.eclipse.che.ide.ext.java.shared.JarEntry)2