List of usage examples for org.eclipse.jdt.core.util IClassFileReader CONSTANT_POOL
int CONSTANT_POOL
To view the source code for org.eclipse.jdt.core.util IClassFileReader CONSTANT_POOL.
Click Source Link
From source file:edu.uci.ics.sourcerer.tools.java.extractor.eclipse.NamingAdvisor.java
License:Open Source License
private void addClassFile(IClassFile classFile) { IClassFileReader reader = ToolFactory.createDefaultClassFileReader(classFile, IClassFileReader.CONSTANT_POOL | IClassFileReader.METHOD_INFOS); IConstantPool constants = reader.getConstantPool(); for (int i = 0, max = constants.getConstantPoolCount(); i < max; i++) { switch (constants.getEntryKind(i)) { case IConstantPoolConstant.CONSTANT_Class: { IConstantPoolEntry constant = constants.decodeEntry(i); addClass(new String(constant.getClassInfoName()).replace('/', '.')); break; }// ww w .ja v a 2 s.co m case IConstantPoolConstant.CONSTANT_Fieldref: { IConstantPoolEntry constant = constants.decodeEntry(i); addClassSig(constant.getFieldDescriptor()); break; } case IConstantPoolConstant.CONSTANT_Methodref: { IConstantPoolEntry constant = constants.decodeEntry(i); addMethod(new String(constant.getClassName()), new String(constant.getMethodName()), constant.getMethodDescriptor()); break; } case IConstantPoolConstant.CONSTANT_InterfaceMethodref: { IConstantPoolEntry constant = constants.decodeEntry(i); addMethod(new String(constant.getClassName()), new String(constant.getMethodName()), constant.getMethodDescriptor()); break; } default: } } // Add the method parameter / return types for (IMethodInfo method : reader.getMethodInfos()) { for (char[] p : Signature.getParameterTypes(method.getDescriptor())) { addClassSig(p); } addClassSig(Signature.getReturnType(method.getDescriptor())); } }
From source file:org.eclipse.ant.internal.ui.datatransfer.SourceAnalyzer.java
License:Open Source License
/** * Find all classes that are required by given class file. * /*ww w .j av a2 s. c om*/ * @param file * a ".class" file * @return set of strings, each contains a full qualified class name (forward slash as package separator) */ public static Set<String> getRequiredClasses(IFile file) { Set<String> classes = new TreeSet<>(); IClassFile classFile = JavaCore.createClassFileFrom(file); IClassFileReader reader = ToolFactory.createDefaultClassFileReader(classFile, IClassFileReader.CONSTANT_POOL); if (reader == null) { // class not compiled return classes; } IConstantPool pool = reader.getConstantPool(); for (int i = 0; i < pool.getConstantPoolCount(); i++) { if (pool.getEntryKind(i) == IConstantPoolConstant.CONSTANT_Class) { IConstantPoolEntry entry = pool.decodeEntry(i); String classname = new String(entry.getClassInfoName()); // don't return inner classes int index = classname.indexOf('$'); if (index != -1) { classname = classname.substring(0, index); } classes.add(classname); } } return classes; }
From source file:org.seasar.diigu.eclipse.operation.NameEnhanceJob.java
License:Apache License
public static IResource toSource(IClassFile clazz) throws CoreException { IJavaProject project = clazz.getJavaProject(); IClassFileReader reader = ToolFactory.createDefaultClassFileReader(clazz, IClassFileReader.CONSTANT_POOL); if (reader != null) { IConstantPool pool = reader.getConstantPool(); for (int i = 0; i < pool.getConstantPoolCount(); i++) { if (pool.getEntryKind(i) == IConstantPoolConstant.CONSTANT_Class) { IConstantPoolEntry entry = pool.decodeEntry(i); char[] data = entry.getClassInfoName(); String name = String.valueOf(data); name = name.replace('/', '.'); IType type = project.findType(name); if (type != null && type.isBinary() == false) { return type.getResource(); }/* ww w. j ava 2s.c om*/ } } } return null; }