List of usage examples for org.eclipse.jdt.core IClassFile getBytes
byte[] getBytes() throws JavaModelException;
From source file:com.drgarbage.bytecodevisualizer.compare.ClassFileMergeViewer.java
License:Apache License
public static InputStream createStream(IJavaElement javaElement) throws CoreException { IClassFile classFile = (IClassFile) javaElement.getAncestor(IJavaElement.CLASS_FILE); InputStream stream = null;/* w w w . j a v a2s . co m*/ if (classFile != null) { stream = new ByteArrayInputStream(classFile.getBytes()); } else { if (javaElement.getParent().getElementType() == IJavaElement.COMPILATION_UNIT) { IType t = (IType) javaElement; IJavaProject javaProject = t.getJavaProject(); String fullyQualifiedName = t.getFullyQualifiedName(); String className = JavaSourceUtils.getSimpleName(fullyQualifiedName); String packageName = JavaSourceUtils.getPackage(fullyQualifiedName); String classPath[] = JavaLangUtils.computeRuntimeClassPath(javaProject); try { stream = JavaLangUtils.findResource(classPath, packageName, className); } catch (IOException e) { throw new CoreException( new Status(IStatus.ERROR, BytecodeVisualizerPlugin.PLUGIN_ID, e.getMessage(), e)); } } else { return null; } } return stream; }
From source file:com.drgarbage.visualgraphic.model.ControlFlowGraphDiagramFactory.java
License:Apache License
/** * Return the input stream for the given class. The result may be null, if * the class has not been compiled./*from w ww . jav a 2 s. c om*/ * * @param type * @return input stream * @throws CoreException * @throws IOException */ private static InputStream getInputStream(IType type) throws CoreException, IOException { if (type.isBinary()) { IClassFile classFile = type.getClassFile(); byte[] bytes = classFile.getBytes(); return new ByteArrayInputStream(bytes); } else { String[] classpath = JavaRuntime.computeDefaultRuntimeClassPath(type.getJavaProject()); String packageName = type.getPackageFragment().getElementName(); // if(type.isAnonymous()){ // Messages.info("Generate graph", // "Cannot generate graph for anonymous source class '"+ // type.getTypeQualifiedName() // +"', because the name is unknown. The comiler generates the name automatically by inserting a $ with a constant for example $1, $2 ..."); // return null; // } String name = type.getTypeQualifiedName(); return JavaLangUtils.findResource(classpath, packageName, name); } }
From source file:edu.uci.ics.sourcerer.tools.java.extractor.eclipse.EclipseExtractor.java
License:Open Source License
private void extractClassFile(IClassFile classFile) { if (asmExtractor == null) { eclipseExtractor.extractClassFile(classFile); } else {/* w w w. j av a2s. co m*/ try { asmExtractor.extract(classFile.getBytes()); } catch (JavaModelException e) { logger.log(Level.SEVERE, "Unable to get bytecode for " + classFile.getElementName(), e); } catch (Exception e) { logger.log(Level.SEVERE, "Error extracting bytecode for " + classFile.getElementName(), e); } } }
From source file:nz.ac.massey.cs.jquest.views.QueryView.java
License:Open Source License
private String getFullname(IJavaElement e) { String fullname = null;//from ww w . j a v a 2 s. c o m try { if (e instanceof ICompilationUnit) { fullname = ".fullname=='" + ((ICompilationUnit) e).getTypes()[0].getFullyQualifiedName() + "'"; return fullname; } else if (e instanceof IClassFile) { IClassFile icf = (IClassFile) e; IClassFileReader r = new ClassFileReader(icf.getBytes(), IClassFileReader.ALL); char[] name = r.getClassName(); String classname = String.valueOf(name); classname = classname.replace("/", "."); fullname = ".fullname=='" + classname + "'"; return fullname; } else if (e instanceof IPackageFragment) { fullname = ".namespace=='" + e.getElementName() + "'"; return fullname; } else if (e instanceof IPackageFragmentRoot) { fullname = ".container=='" + e.getElementName() + "'"; return fullname; } else { return null; } } catch (Exception e1) { e1.printStackTrace(); } return null; }
From source file:org.jboss.tools.seam.internal.core.scanner.lib.LibraryScanner.java
License:Open Source License
private ClassFileReader getReader(IType type, IClassFile typeRoot) throws JavaModelException, ClassFormatException, IOException { String className = type.getFullyQualifiedName(); ClassFileReader newReader = null;/*w w w . j a v a 2 s . c o m*/ byte[] bs = null; bs = typeRoot.getBytes(); return ClassFileReader.read(new ByteArrayInputStream(bs), className, false); }