List of usage examples for org.eclipse.jdt.internal.core.util Util concatWith
public static final String concatWith(String[] array, String name, char separator)
From source file:com.codenvy.ide.ext.java.server.internal.core.ClassFile.java
License:Open Source License
public byte[] getBytes() throws JavaModelException { JavaElement pkg = (JavaElement) getParent(); if (pkg instanceof JarPackageFragment) { JarPackageFragmentRoot root = (JarPackageFragmentRoot) pkg.getParent(); ZipFile zip = null;//w ww .j a v a2s.co m try { zip = root.getJar(); String entryName = Util.concatWith(((PackageFragment) pkg).names, getElementName(), '/'); ZipEntry ze = zip.getEntry(entryName); if (ze != null) { return org.eclipse.jdt.internal.compiler.util.Util.getZipEntryByteContent(ze, zip); } throw new JavaModelException( new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, this)); } catch (IOException ioe) { throw new JavaModelException(ioe, IJavaModelStatusConstants.IO_EXCEPTION); } catch (CoreException e) { if (e instanceof JavaModelException) { throw (JavaModelException) e; } else { throw new JavaModelException(e); } } finally { manager.closeZipFile(zip); } } else { IFile file = (IFile) resource(); return Util.getResourceContentsAsByteArray(file); } }
From source file:com.codenvy.ide.ext.java.server.internal.core.ClassFile.java
License:Open Source License
private IBinaryType getJarBinaryTypeInfo(PackageFragment pkg, boolean fullyInitialize) throws CoreException, IOException, ClassFormatException { JarPackageFragmentRoot root = (JarPackageFragmentRoot) pkg.getParent(); ZipFile zip = null;/* w w w . ja v a 2 s . c o m*/ try { zip = root.getJar(); String entryName = Util.concatWith(pkg.names, getElementName(), '/'); ZipEntry ze = zip.getEntry(entryName); if (ze != null) { byte contents[] = org.eclipse.jdt.internal.compiler.util.Util.getZipEntryByteContent(ze, zip); String fileName = root.getHandleIdentifier() + IDependent.JAR_FILE_ENTRY_SEPARATOR + entryName; return new ClassFileReader(contents, fileName.toCharArray(), fullyInitialize); } } finally { manager.closeZipFile(zip); } return null; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MatchLocator.java
License:Open Source License
public static ClassFileReader classFileReader(IType type) { IClassFile classFile = type.getClassFile(); JavaModelManager manager = JavaModelManager.getJavaModelManager(); if (classFile.isOpen()) return (ClassFileReader) manager.getInfo(type); PackageFragment pkg = (PackageFragment) type.getPackageFragment(); IPackageFragmentRoot root = (IPackageFragmentRoot) pkg.getParent(); try {/*ww w. ja v a 2 s .c om*/ if (!root.isArchive()) return Util.newClassFileReader(((JavaElement) type).resource()); ZipFile zipFile = null; try { IPath zipPath = root.getPath(); if (JavaModelManager.ZIP_ACCESS_VERBOSE) 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); } finally { manager.closeZipFile(zipFile); } } catch (ClassFormatException e) { // invalid class file: return null } catch (CoreException e) { // cannot read class file: return null } catch (IOException e) { // cannot read class file: return null } return null; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MatchLocator.java
License:Open Source License
protected IBinaryType getBinaryInfo(ClassFile classFile, IResource resource) throws CoreException { BinaryType binaryType = (BinaryType) classFile.getType(); if (classFile.isOpen()) return (IBinaryType) binaryType.getElementInfo(); // reuse the info from the java model cache // create a temporary info IBinaryType info;/* w w w.ja v a2 s .co m*/ try { PackageFragment pkg = (PackageFragment) classFile.getParent(); PackageFragmentRoot root = (PackageFragmentRoot) pkg.getParent(); if (root.isArchive()) { // class file in a jar String classFileName = classFile.getElementName(); String classFilePath = Util.concatWith(pkg.names, classFileName, '/'); ZipFile zipFile = null; try { zipFile = ((JarPackageFragmentRoot) root).getJar(); info = ClassFileReader.read(zipFile, classFilePath); } finally { JavaModelManager.getJavaModelManager().closeZipFile(zipFile); } } else { // class file in a directory info = Util.newClassFileReader(resource); } if (info == null) throw binaryType.newNotPresentException(); return info; } catch (ClassFormatException e) { //e.printStackTrace(); return null; } catch (IOException e) { throw new JavaModelException(e, IJavaModelStatusConstants.IO_EXCEPTION); } }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.PossibleMatch.java
License:Open Source License
private char[] getQualifiedName() { if (this.openable instanceof CompilationUnit) { // get file name String fileName = this.openable.getElementName(); // working copy on a .class file may not have a resource, so use the element name // get main type name char[] mainTypeName = Util.getNameWithoutJavaLikeExtension(fileName).toCharArray(); CompilationUnit cu = (CompilationUnit) this.openable; return cu.getType(new String(mainTypeName)).getFullyQualifiedName().toCharArray(); } else if (this.openable instanceof ClassFile) { String fileName = getSourceFileName(); if (fileName == NO_SOURCE_FILE_NAME) return ((ClassFile) this.openable).getType().getFullyQualifiedName('.').toCharArray(); // Class file may have a source file name with ".java" extension (see bug 73784) int index = Util.indexOfJavaLikeExtension(fileName); String simpleName = index == -1 ? fileName : fileName.substring(0, index); PackageFragment pkg = (PackageFragment) this.openable.getParent(); return Util.concatWith(pkg.names, simpleName, '.').toCharArray(); }//from ww w.ja v a 2 s. co m return null; }
From source file:org.eclipse.jdt.internal.core.hierarchy.HierarchyBuilder.java
License:Open Source License
/** * Create a type info from the given class file in a jar and adds it to the given list of infos. *//* w w w . jav a2 s.com*/ protected IBinaryType createInfoFromClassFileInJar(Openable classFile) { PackageFragment pkg = (PackageFragment) classFile.getParent(); String classFilePath = Util.concatWith(pkg.names, classFile.getElementName(), '/'); IBinaryType info = null; java.util.zip.ZipFile zipFile = null; try { zipFile = ((JarPackageFragmentRoot) pkg.getParent()).getJar(); info = org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader.read(zipFile, classFilePath); } catch (org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException e) { if (TypeHierarchy.DEBUG) { e.printStackTrace(); } return null; } catch (java.io.IOException e) { if (TypeHierarchy.DEBUG) { e.printStackTrace(); } return null; } catch (CoreException e) { if (TypeHierarchy.DEBUG) { e.printStackTrace(); } return null; } finally { JavaModelManager.getJavaModelManager().closeZipFile(zipFile); } this.infoToHandle.put(info, classFile); return info; }
From source file:org.eclipse.jdt.internal.core.search.matching.MatchLocator.java
License:Open Source License
public static ClassFileReader classFileReader(IType type) { IClassFile classFile = type.getClassFile(); JavaModelManager manager = JavaModelManager.getJavaModelManager(); if (classFile.isOpen()) return (ClassFileReader) manager.getInfo(type); PackageFragment pkg = (PackageFragment) type.getPackageFragment(); IPackageFragmentRoot root = (IPackageFragmentRoot) pkg.getParent(); try {//w w w . jav a 2s. c o m if (!root.isArchive()) return Util.newClassFileReader(((JavaElement) type).resource()); ZipFile zipFile = null; try { IPath zipPath = root.getPath(); if (JavaModelManager.ZIP_ACCESS_VERBOSE) System.out.println("(" + Thread.currentThread() //$NON-NLS-1$ + ") [MatchLocator.classFileReader()] Creating ZipFile on " + zipPath); //$NON-NLS-1$ zipFile = manager.getZipFile(zipPath); String classFileName = classFile.getElementName(); String path = Util.concatWith(pkg.names, classFileName, '/'); return ClassFileReader.read(zipFile, path); } finally { manager.closeZipFile(zipFile); } } catch (ClassFormatException e) { // invalid class file: return null } catch (CoreException e) { // cannot read class file: return null } catch (IOException e) { // cannot read class file: return null } return null; }
From source file:org.eclipse.jdt.internal.core.search.matching.MatchLocator.java
License:Open Source License
protected IBinaryType getBinaryInfo(ClassFile classFile, IResource resource) throws CoreException { BinaryType binaryType = (BinaryType) classFile.getType(); if (classFile.isOpen()) return (IBinaryType) binaryType.getElementInfo(); // reuse the info from the java model cache // create a temporary info IBinaryType info;//from w w w. j av a 2 s . com try { PackageFragment pkg = (PackageFragment) classFile.getParent(); PackageFragmentRoot root = (PackageFragmentRoot) pkg.getParent(); if (root.isArchive()) { // class file in a jar String classFileName = classFile.getElementName(); String classFilePath = Util.concatWith(pkg.names, classFileName, '/'); ZipFile zipFile = null; try { zipFile = ((JarPackageFragmentRoot) root).getJar(); info = ClassFileReader.read(zipFile, classFilePath); } finally { JavaModelManager.getJavaModelManager().closeZipFile(zipFile); } } else { // class file in a directory info = Util.newClassFileReader(resource); } if (info == null) throw binaryType.newNotPresentException(); return info; } catch (ClassFormatException e) { //e.printStackTrace(); return null; } catch (java.io.IOException e) { throw new JavaModelException(e, IJavaModelStatusConstants.IO_EXCEPTION); } }
From source file:org.springframework.ide.eclipse.beans.core.internal.model.BeansJavaConfig.java
License:Open Source License
public BeansJavaConfig(IBeansProject project, IType configClass, String configClassName, Type type) { super(project, BeansConfigFactory.JAVA_CONFIG_TYPE + configClassName, type); this.configClass = configClass; this.configClassName = configClassName; modificationTimestamp = IResource.NULL_STAMP; if (this.configClass != null) { IResource resource = this.configClass.getResource(); if (resource != null && resource instanceof IFile) { file = (IFile) resource;/* w w w. ja v a 2 s . co m*/ } else { IClassFile classFile = configClass.getClassFile(); PackageFragment pkg = (PackageFragment) configClass.getPackageFragment(); IPackageFragmentRoot root = (IPackageFragmentRoot) pkg.getParent(); if (root.isArchive()) { IPath zipPath = root.getPath(); String classFileName = classFile.getElementName(); String path = Util.concatWith(pkg.names, classFileName, '/'); file = new ExternalFile(zipPath.toFile(), path, project.getProject()); } } } if (file == null || !file.exists()) { modificationTimestamp = IResource.NULL_STAMP; String msg = "Beans Java config class '" + configClassName + "' not accessible"; problems = new CopyOnWriteArraySet<ValidationProblem>(); problems.add(new ValidationProblem(IMarker.SEVERITY_ERROR, msg, file, -1)); } else { modificationTimestamp = file.getModificationStamp(); try { file.setSessionProperty(IBeansConfig.CONFIG_FILE_TAG, IBeansConfig.CONFIG_FILE_TAG_VALUE); } catch (CoreException e) { BeansCorePlugin.log(new Status(IStatus.WARNING, BeansCorePlugin.PLUGIN_ID, String.format("Error occured while tagging config file '%s'", file.getFullPath()), e)); } } }