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;
}
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;
}
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);
}
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;
}
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);
}
}
Aggregations