List of usage examples for org.eclipse.jdt.internal.core.util ClassFileReader ClassFileReader
public ClassFileReader(byte[] classFileBytes, int decodingFlags) throws ClassFormatException
From source file:nz.ac.massey.cs.jquest.views.QueryView.java
License:Open Source License
private String getFullname(IJavaElement e) { String fullname = null;/*from w ww. ja v a 2s.c om*/ 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.eclipse.che.jdt.core.ToolFactory.java
License:Open Source License
/** * Create a default classfile reader, able to expose the internal representation of a given classfile * according to the decoding flag used to initialize the reader. * Answer null if the input stream contents cannot be retrieved * <p/>//from w w w .j ava 2s . c om * The decoding flags are described in IClassFileReader. * * @param stream * the given input stream to read * @param decodingFlag * the flag used to decode the class file reader. * @return a default classfile reader * @see org.eclipse.jdt.core.util.IClassFileReader * @since 3.2 */ public static IClassFileReader createDefaultClassFileReader(InputStream stream, int decodingFlag) { try { return new ClassFileReader(Util.getInputStreamAsByteArray(stream, -1), decodingFlag); } catch (ClassFormatException e) { return null; } catch (IOException e) { return null; } }
From source file:org.eclipse.che.jdt.core.ToolFactory.java
License:Open Source License
/** * Create a default classfile reader, able to expose the internal representation of a given classfile * according to the decoding flag used to initialize the reader. * Answer null if the file named fileName doesn't represent a valid .class file. * The fileName has to be an absolute OS path to the given .class file. * <p/>//from w w w.j a v a2s .co m * The decoding flags are described in IClassFileReader. * * @param fileName * the name of the file to be read * @param decodingFlag * the flag used to decode the class file reader. * @return a default classfile reader * @see org.eclipse.jdt.core.util.IClassFileReader */ public static IClassFileReader createDefaultClassFileReader(String fileName, int decodingFlag) { try { return new ClassFileReader(Util.getFileByteContent(new File(fileName)), decodingFlag); } catch (ClassFormatException e) { return null; } catch (IOException e) { return null; } }
From source file:org.eclipse.che.jdt.core.ToolFactory.java
License:Open Source License
/** * Create a default classfile reader, able to expose the internal representation of a given classfile * according to the decoding flag used to initialize the reader. * Answer null if the file named zipFileName doesn't represent a valid zip file or if the zipEntryName * is not a valid entry name for the specified zip file or if the bytes don't represent a valid * .class file according to the JVM specifications. * <p/>/*from ww w . j a va 2s . c o m*/ * The decoding flags are described in IClassFileReader. * * @param zipFileName * the name of the zip file * @param zipEntryName * the name of the entry in the zip file to be read * @param decodingFlag * the flag used to decode the class file reader. * @return a default classfile reader * @see org.eclipse.jdt.core.util.IClassFileReader */ public static IClassFileReader createDefaultClassFileReader(String zipFileName, String zipEntryName, int decodingFlag) { ZipFile zipFile = null; try { if (JavaModelManager.ZIP_ACCESS_VERBOSE) { System.out.println("(" + Thread.currentThread() + ") [ToolFactory.createDefaultClassFileReader()] Creating ZipFile on " + zipFileName); //$NON-NLS-1$ //$NON-NLS-2$ } zipFile = new ZipFile(zipFileName); ZipEntry zipEntry = zipFile.getEntry(zipEntryName); if (zipEntry == null) { return null; } if (!zipEntryName.toLowerCase().endsWith(SuffixConstants.SUFFIX_STRING_class)) { return null; } byte classFileBytes[] = Util.getZipEntryByteContent(zipEntry, zipFile); return new ClassFileReader(classFileBytes, decodingFlag); } catch (ClassFormatException e) { return null; } catch (IOException e) { return null; } finally { if (zipFile != null) { try { zipFile.close(); } catch (IOException e) { // ignore } } } }
From source file:org.eclipse.objectteams.otdt.tests.compiler.smap.Requestor.java
License:Open Source License
protected void outputClassFiles(CompilationResult unitResult) { if ((unitResult != null) && (!unitResult.hasErrors() || forceOutputGeneration)) { ClassFile[] classFiles = unitResult.getClassFiles(); for (int i = 0, fileCount = classFiles.length; i < fileCount; i++) { // retrieve the key and the corresponding classfile ClassFile classFile = classFiles[i]; if (outputPath != null) { String relativeName = new String(classFile.fileName()).replace('/', File.separatorChar) + ".class"; try { org.eclipse.jdt.internal.compiler.util.Util.writeToDisk(true, outputPath, relativeName, classFile);/*from w ww .j a v a2s . co m*/ } catch (IOException e) { e.printStackTrace(); } } if (this.lineNumbers != null) { ClassFileReader cfr; try { cfr = new ClassFileReader(classFile.getBytes(), IClassFileReader.METHOD_INFOS | IClassFileReader.METHOD_BODIES); } catch (ClassFormatException e) { throw new AssertionFailedError("Can't read class file: " + e.getMessage()); } for (IMethodInfo method : cfr.getMethodInfos()) { String fullMethodDesignator = String .valueOf(CharOperation.concatWith(classFile.getCompoundName(), CharOperation.concat(method.getName(), method.getDescriptor()), '.')); int[] expectedNumbers = this.lineNumbers.get(fullMethodDesignator); if (expectedNumbers != null) { this.lineNumbers.remove(fullMethodDesignator); ILineNumberAttribute lineNumberAttribute = method.getCodeAttribute() .getLineNumberAttribute(); int[][] table = lineNumberAttribute.getLineNumberTable(); Assert.assertEquals("wrong number of line numbers", expectedNumbers.length, table.length); for (int n = 0; n < expectedNumbers.length; n++) Assert.assertEquals("wrong line numeber", expectedNumbers[n], table[n][1]); } } } } } }