List of usage examples for org.eclipse.jdt.internal.core JavaModelManager createClassFileFrom
public static IClassFile createClassFileFrom(IFile file, IJavaProject project)
.class file, its project being the given project. From source file:com.drgarbage.bytecodevisualizer.editors.BytecodeDocumentProvider.java
License:Apache License
protected IAnnotationModel createAnnotationModel(Object element) throws CoreException { if (element instanceof IEditorInput) { IEditorInput input = (IEditorInput) element; if (input instanceof IFileEditorInput) { /* a local class file */ IFileEditorInput fileEditorInput = (IFileEditorInput) input; IFile file = fileEditorInput.getFile(); String fqTypeName = BytecodeUtils.toFullyQualifiedTypeName(file); if (fqTypeName != null) { /* FIX for BUG#214: * NullPointerException when opening a Class which is * not in build path from Navigator */ IProject project = file.getProject(); /* create java project */ IJavaProject javaProject = JavaCore.create(project); try { IType t = javaProject.findType(fqTypeName); if (t != null) { IResource res = t.getCompilationUnit().getResource(); BytecodeMarkerAnnotationModel model = new BytecodeMarkerAnnotationModel(res, classFileEditor); IClassFile classFile = t.getClassFile(); if (classFile == null) { classFile = JavaModelManager.createClassFileFrom(file, javaProject); }/*from w w w. j a v a 2s .co m*/ model.setClassFile(classFile); model.setClassFileDocument(classFileDocument); return model; } } catch (JavaModelException e) { throw new CoreException( new Status(IStatus.ERROR, CoreConstants.BYTECODE_VISUALIZER_PLUGIN_ID, IStatus.OK, BytecodeVisualizerMessages.Error_not_load_file, e)); } } } } if (element instanceof IClassFileEditorInput) { return createClassFileAnnotationModel((IClassFileEditorInput) element); } return null; }