/** * Returns the primary type of a class file. * * @param classFile the class file * @return returns the primary type of the class file, or <code>null</code> * if is does not have one */ private IType getMainType(IClassFile classFile) { IType type= classFile.getType(); return type != null && type.exists() ? type : null; } }
private static String getFileURI(IClassFile classFile) { String packageName = classFile.getParent().getElementName(); String jarName = classFile.getParent().getParent().getElementName(); try { return new URI(JDT_SCHEME, "contents", PATH_SEPARATOR + jarName + PATH_SEPARATOR + packageName + PATH_SEPARATOR + classFile.getElementName(), classFile.getHandleIdentifier(), null) .toASCIIString(); } catch (URISyntaxException e) { return null; } }
@Override public boolean exists() { return fClassFile.exists(); }
public IType getDeclaringType() { IClassFile classFile = getClassFile(); if (classFile.isOpen()) { try { char[] enclosingTypeName = ((IBinaryType) getElementInfo()).getEnclosingTypeName(); if (classFile.getElementName().length() > enclosingTypeName.length+1 && Character.isDigit(classFile.getElementName().charAt(enclosingTypeName.length+1))) { return null; return getPackageFragment().getClassFile(new String(enclosingTypeName) + SUFFIX_STRING_class).getType(); } catch (JavaModelException npe) { return null; String classFileName = classFile.getElementName(); int lastDollar = -1; for (int i = 0, length = classFileName.length(); i < length; i++) {
IPackageFragmentRoot root = (IPackageFragmentRoot) classfile.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (root != null){ try { JavaModelManager.getJavaModelManager().closeZipFile(jar); PackageFragment packageFragment = (PackageFragment) classfile.getParent(); String classFileName = classfile.getElementName(); String entryName = org.eclipse.jdt.internal.core.util.Util.concatWith(packageFragment.names, classFileName, '/'); return createDefaultClassFileReader(archiveName, entryName, decodingFlag);
public IType getDeclaringType() { IClassFile classFile = getClassFile(); if (classFile.isOpen()) { try { char[] enclosingTypeName = ((IBinaryType) getElementInfo()).getEnclosingTypeName(); if (classFile.getElementName().length() > enclosingTypeName.length+1 && Character.isDigit(classFile.getElementName().charAt(enclosingTypeName.length+1))) { return null; String classFileName = classFile.getElementName(); int lastDollar = -1; for (int i = 0, length = classFileName.length(); i < length; i++) {
@Override public String getName() { return fClassFile.getElementName(); }
/** * Runs the stub generation on the specified class file. * * @param file * the class file * @param parent * the parent store * @param monitor * the progress monitor to use * @throws CoreException * if an error occurs */ protected void run(final IClassFile file, final IFileStore parent, final IProgressMonitor monitor) throws CoreException { try { monitor.beginTask(getOperationLabel(), 2); final IType type= file.getType(); if (type.isAnonymous() || type.isLocal() || type.isMember()) return; final String source= file.getSource(); createCompilationUnit(parent, type.getElementName() + ".java", source != null ? source : "", monitor); //$NON-NLS-1$ //$NON-NLS-2$ } finally { monitor.done(); } } }
public static BinaryTypeDescriptor createDescriptor(IClassFile classFile) { ClassFile concreteClass = (ClassFile)classFile; PackageFragment parent = (PackageFragment) classFile.getParent(); return createDescriptor(parent, concreteClass); }
private ImageDescriptor getOverlay(Object element) throws JavaModelException { if (element instanceof ICompilationUnit) { ICompilationUnit unit= (ICompilationUnit) element; if (unit.isOpen()) { IType mainType= unit.findPrimaryType(); if (mainType != null) { return getOverlayFromFlags(mainType.getFlags()); } return null; } String typeName= JavaCore.removeJavaLikeExtension(unit.getElementName()); return getOverlayWithSearchEngine(unit, typeName); } else if (element instanceof IClassFile) { IClassFile classFile= (IClassFile) element; if (classFile.isOpen()) { return getOverlayFromFlags(classFile.getType().getFlags()); } String typeName= classFile.getType().getElementName(); return getOverlayWithSearchEngine(classFile, typeName); } return null; }
@Override public String[] getCategories() throws JavaModelException { SourceMapper mapper= getSourceMapper(); if (mapper != null) { // ensure the class file's buffer is open so that categories are computed getClassFile().getBuffer(); if (mapper.categories != null) { String[] categories = (String[]) mapper.categories.get(this); if (categories != null) return categories; } } return CharOperation.NO_STRINGS; } public String getKey() {
/** * @param newCfSource the source * @param originalCf the class file to get the name and project from * @param resolveBindings whether bindings are to be resolved * @param recovery whether statements and binding recovery should be enabled * @param pm an {@link IProgressMonitor}, or <code>null</code> * @return the parsed CompilationUnit */ public CompilationUnit parse(String newCfSource, IClassFile originalCf, boolean resolveBindings, boolean recovery, IProgressMonitor pm) { fParser.setResolveBindings(resolveBindings); fParser.setStatementsRecovery(recovery); fParser.setBindingsRecovery(recovery); fParser.setSource(newCfSource.toCharArray()); String cfName= originalCf.getElementName(); fParser.setUnitName(cfName.substring(0, cfName.length() - 6) + JavaModelUtil.DEFAULT_CU_SUFFIX); fParser.setProject(originalCf.getJavaProject()); fParser.setCompilerOptions(getCompilerOptions(originalCf)); CompilationUnit newCUNode= (CompilationUnit) fParser.createAST(pm); return newCUNode; }
public static ResourceMapping create(IClassFile classFile) { // test if in a archive IPackageFragmentRoot root= (IPackageFragmentRoot)classFile.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (!root.isArchive()) { return new ClassFileResourceMapping(classFile); } return null; }
/** * @param classFileWithSource * @throws JavaModelException * */ public ClassFileSourceStorage(IClassFile classFileWithSource) throws JavaModelException { this.classFile = classFileWithSource; this.source = classFile.getSource(); }
@Override public IProject[] getProjects() { return new IProject[] { fClassFile.getJavaProject().getProject() }; } @Override
cu= classFile.getWorkingCopy((WorkingCopyOwner) null, null); if (cu == null || classFile.getSource() == null) return null;
public IType getDeclaringType() { IClassFile classFile = getClassFile(); if (classFile.isOpen()) { try { char[] enclosingTypeName = ((IBinaryType) getElementInfo()).getEnclosingTypeName(); if (classFile.getElementName().length() > enclosingTypeName.length+1 && Character.isDigit(classFile.getElementName().charAt(enclosingTypeName.length+1))) { return null; return getPackageFragment().getClassFile(new String(enclosingTypeName) + SUFFIX_STRING_class).getType(); } catch (JavaModelException npe) { return null; String classFileName = classFile.getElementName(); int lastDollar = -1; for (int i = 0, length = classFileName.length(); i < length; i++) {
IPackageFragmentRoot root = (IPackageFragmentRoot) classfile.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (root != null){ try { JavaModelManager.getJavaModelManager().closeZipFile(jar); PackageFragment packageFragment = (PackageFragment) classfile.getParent(); String classFileName = classfile.getElementName(); String entryName = org.eclipse.jdt.internal.core.util.Util.concatWith(packageFragment.names, classFileName, '/'); return createDefaultClassFileReader(archiveName, entryName, decodingFlag);
public static IBinaryType classFileReader(IType type) { IClassFile classFile = type.getClassFile(); JavaModelManager manager = JavaModelManager.getJavaModelManager(); if (classFile.isOpen()) return (IBinaryType)manager.getInfo(type); String classFileName = classFile.getElementName(); String path = Util.concatWith(pkg.names, classFileName, '/'); return ClassFileReader.readFromJrt(new File(rootPath), null, path); System.out.println("(" + Thread.currentThread() + ") [MatchLocator.classFileReader()] Creating ZipFile on " + zipPath); //$NON-NLS-1$ //$NON-NLS-2$ zipFile = manager.getZipFile(zipPath); String classFileName = classFile.getElementName(); String path = Util.concatWith(pkg.names, classFileName, '/'); return ClassFileReader.read(zipFile, path);
@Override public String getName() { return fClassFile.getElementName(); }