List of usage examples for org.eclipse.jdt.core.util IClassFileReader CLASSFILE_ATTRIBUTES
int CLASSFILE_ATTRIBUTES
To view the source code for org.eclipse.jdt.core.util IClassFileReader CLASSFILE_ATTRIBUTES.
Click Source Link
From source file:com.redhat.ceylon.eclipse.code.wizard.ClassPathDetector.java
License:Open Source License
private IPath detectOutputFolder() throws CoreException { HashSet<IPath> classFolders = new HashSet<IPath>(); for (Iterator<IResource> iter = fClassFiles.iterator(); iter.hasNext();) { IFile file = (IFile) iter.next(); IClassFileReader reader = null;// w w w . j a va2 s . c o m InputStream content = null; try { content = file.getContents(); reader = ToolFactory.createDefaultClassFileReader(content, IClassFileReader.CLASSFILE_ATTRIBUTES); } finally { try { if (content != null) content.close(); } catch (IOException e) { throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.ERROR, Messages.format("error closing file", BasicElementLabels.getPathLabel(file.getFullPath(), false)), e)); } } if (reader == null) { continue; // problematic class file } char[] className = reader.getClassName(); ISourceAttribute sourceAttribute = reader.getSourceFileAttribute(); if (className != null && sourceAttribute != null && sourceAttribute.getSourceFileName() != null) { IPath packPath = file.getParent().getFullPath(); int idx = CharOperation.lastIndexOf('/', className) + 1; IPath relPath = new Path(new String(className, 0, idx)); IPath cuPath = relPath.append(new String(sourceAttribute.getSourceFileName())); IPath resPath = null; if (idx == 0) { resPath = packPath; } else { IPath folderPath = getFolderPath(packPath, relPath); if (folderPath != null) { resPath = folderPath; } } if (resPath != null) { IPath path = findInSourceFolders(cuPath); if (path != null) { return resPath; } else { classFolders.add(resPath); } } } } IPath projPath = fProject.getFullPath(); if (fSourceFolders.size() == 1 && classFolders.isEmpty() && fSourceFolders.get(projPath) != null) { return projPath; } else { IPath path = projPath .append(PreferenceConstants.getPreferenceStore().getString(PreferenceConstants.SRCBIN_BINNAME)); while (classFolders.contains(path)) { path = new Path(path.toString() + '1'); } return path; } }
From source file:in.software.analytics.parichayana.core.internal.builder.ParichayanaBuilder.java
License:Open Source License
/** * @param delta/*from w ww . ja va 2s. c om*/ * @param monitor * @throws CoreException */ private void buildDelta(IResourceDelta delta, IProgressMonitor monitor) throws CoreException { final List<ICompilationUnit> units = new ArrayList<ICompilationUnit>(); delta.accept(new IResourceDeltaVisitor() { @Override public boolean visit(IResourceDelta delta) throws CoreException { IResource res = delta.getResource(); switch (res.getType()) { case IResource.ROOT: return true; case IResource.PROJECT: return true; case IResource.FOLDER: return true; case IResource.FILE: IJavaElement element = JavaCore.create(res); ICompilationUnit cu = null; if (element instanceof IClassFile) { cu = getCompilationUnit((IClassFile) element); } if (element instanceof ICompilationUnit) { cu = (ICompilationUnit) element; } if (cu != null) { cleanupMarkers(cu.getUnderlyingResource()); if (units.contains(cu)) { return false; } units.add(cu); } return false; default: return false; } } public ICompilationUnit getCompilationUnit(IClassFile classFile) { IClassFileReader classFileReader = ToolFactory.createDefaultClassFileReader(classFile, IClassFileReader.CLASSFILE_ATTRIBUTES); if (classFileReader != null) { char[] className = classFileReader.getClassName(); if (className != null) { String fqn = new String(classFileReader.getClassName()).replace("/", "."); //$NON-NLS-1$ //$NON-NLS-2$ IJavaProject javaProject = classFile.getJavaProject(); IType sourceType = null; try { sourceType = javaProject.findType(fqn); if (sourceType != null) { return sourceType.getCompilationUnit(); } } catch (JavaModelException e) { // ignore } } } return null; } }); build(units, monitor); }
From source file:org.eclipse.acceleo.common.internal.utils.workspace.AcceleoDeltaVisitor.java
License:Open Source License
/** * {@inheritDoc}/*from w w w . ja v a 2 s.co m*/ * * @see org.eclipse.core.resources.IResourceDeltaVisitor#visit(org.eclipse.core.resources.IResourceDelta) */ public boolean visit(IResourceDelta delta) throws CoreException { if (delta == null || 0 == (delta.getKind() & IResourceDelta.CHANGED)) { return false; } boolean visit = false; IResource resource = delta.getResource(); if (resource != null) { switch (resource.getType()) { case IResource.FILE: if (0 == (delta.getFlags() & IResourceDelta.CONTENT)) { break; } if ("class".equals(resource.getFullPath().getFileExtension())) { //$NON-NLS-1$ final IClassFileReader reader = ToolFactory.createDefaultClassFileReader( resource.getLocation().toOSString(), IClassFileReader.CLASSFILE_ATTRIBUTES); changedClasses.add(new String(reader.getClassName()).replace("/", ".")); //$NON-NLS-1$ //$NON-NLS-2$ } break; case IResource.PROJECT: changedProjects.add((IProject) resource); visit = true; break; default: visit = true; } } return visit; }
From source file:org.eclipse.ajdt.internal.ui.wizards.exports.AJJarFileExportOperation.java
License:Open Source License
private Map<String, ArrayList<IFile>> buildJavaToClassMap(IContainer container) throws CoreException { if (container == null || !container.isAccessible()) return new HashMap<String, ArrayList<IFile>>(0); /*/*from ww w . j a v a2 s . c o m*/ * XXX: Bug 6584: Need a way to get class files for a java file (or CU) */ IClassFileReader cfReader = null; IResource[] members = container.members(); Map<String, ArrayList<IFile>> map = new HashMap<String, ArrayList<IFile>>(members.length); for (int i = 0; i < members.length; i++) { if (isClassFile(members[i])) { IFile classFile = (IFile) members[i]; IPath location = classFile.getLocation(); if (location != null) { File file = location.toFile(); cfReader = ToolFactory.createDefaultClassFileReader(location.toOSString(), IClassFileReader.CLASSFILE_ATTRIBUTES); if (cfReader != null) { ISourceAttribute sourceAttribute = cfReader.getSourceFileAttribute(); if (sourceAttribute == null) { /* * Can't fully build the map because one or more * class file does not contain the name of its * source file. */ addWarning(Messages.format( JarPackagerMessages.JarFileExportOperation_classFileWithoutSourceFileAttribute, file), null); return null; } String javaName = new String(sourceAttribute.getSourceFileName()); ArrayList<IFile> classFiles = map.get(javaName); if (classFiles == null) { classFiles = new ArrayList<IFile>(3); map.put(javaName, classFiles); } classFiles.add(classFile); } } } } return map; }
From source file:org.eclipse.jst.j2ee.internal.archive.JavaEEArchiveUtilities.java
License:Open Source License
public boolean isEJBArchive(IArchive archive) { // first check for the deployment descriptor if (archiveToJavaEEQuickPeek.containsKey(archive)) { JavaEEQuickPeek qp = JavaEEArchiveUtilities.INSTANCE.getJavaEEQuickPeek(archive); if (qp.getType() == JavaEEQuickPeek.EJB_TYPE) { return true; }/*w w w . j a v a 2 s .co m*/ } List<IArchiveResource> archiveResources = archive.getArchiveResources(); for (IArchiveResource archiveResource : archiveResources) { if (archiveResource.getType() == IArchiveResource.FILE_TYPE) { if (archiveResource.getPath().lastSegment().endsWith(DOT_CLASS)) { InputStream ioStream = null; try { ioStream = archiveResource.getInputStream(); IClassFileReader classFileReader = ToolFactory.createDefaultClassFileReader(ioStream, IClassFileReader.CLASSFILE_ATTRIBUTES); //classFileReader will be null if this is an invalid java .class file if (classFileReader != null) { IClassFileAttribute[] attributes = classFileReader.getAttributes(); for (IClassFileAttribute attribute : attributes) { char[] attributeName = attribute.getAttributeName(); if (Arrays.equals(attributeName, RUNTIME_VISIBLE)) { IRuntimeVisibleAnnotationsAttribute annotationsAttribute = (IRuntimeVisibleAnnotationsAttribute) attribute; IAnnotation[] annotations = annotationsAttribute.getAnnotations(); for (IAnnotation annotation : annotations) { char[] typedName = annotation.getTypeName(); if (Arrays.equals(typedName, STATELESS) || Arrays.equals(typedName, STATEFUL) || Arrays.equals(typedName, MESSAGEDRIVEN) || Arrays.equals(typedName, SINGLETON)) { return true; } } } } } } catch (FileNotFoundException e) { ArchiveUtil.warn(e); } catch (IOException e) { ArchiveUtil.warn(e); } finally { if (null != ioStream) { try { ioStream.close(); } catch (IOException e) { ArchiveUtil.warn(e); } } ioStream = null; } } } } return false; }
From source file:org.jboss.tools.arquillian.core.internal.builder.ArquillianBuilder.java
License:Open Source License
private void buildDelta(IResourceDelta delta, IProgressMonitor monitor) throws CoreException { final List<ICompilationUnit> units = new ArrayList<ICompilationUnit>(); delta.accept(new IResourceDeltaVisitor() { @Override/*from www . ja v a 2s .c om*/ public boolean visit(IResourceDelta delta) throws CoreException { IResource res = delta.getResource(); switch (res.getType()) { case IResource.ROOT: return true; case IResource.PROJECT: return true; case IResource.FOLDER: return true; case IResource.FILE: IJavaElement element = JavaCore.create(res); ICompilationUnit cu = null; if (element instanceof IClassFile) { cu = getCompilationUnit((IClassFile) element); } if (element instanceof ICompilationUnit) { cu = (ICompilationUnit) element; } if (cu != null) { IResource resource = null; try { resource = cu.getUnderlyingResource(); } catch (Exception e) { // ignore } if (resource != null) { cleanupMarkers(resource); } if (units.contains(cu)) { DependencyCache.getDependencies().remove(cu); return false; } if (ArquillianSearchEngine.isArquillianJUnitTest(element, false, false)) { units.add(cu); } else { Set<ICompilationUnit> cus = DependencyCache.getDependencies().keySet(); IType primaryType = cu == null ? null : cu.findPrimaryType(); String fqn = primaryType == null ? null : primaryType.getFullyQualifiedName(); Iterator<ICompilationUnit> iterator = cus.iterator(); Set<ICompilationUnit> toRemove = new HashSet<ICompilationUnit>(); toRemove.add(cu); while (iterator.hasNext()) { ICompilationUnit unit = iterator.next(); Set<DependencyType> types = DependencyCache.getDependentTypes(unit); for (DependencyType type : types) { if (type.getName() != null && type.getName().equals(fqn)) { if (ArquillianSearchEngine.isArquillianJUnitTest(unit, false, false)) { units.add(unit); } toRemove.add(unit); } } } iterator = toRemove.iterator(); while (iterator.hasNext()) { DependencyCache.getDependencies().remove(iterator.next()); } } } return false; default: return false; } } public ICompilationUnit getCompilationUnit(IClassFile classFile) { IClassFileReader classFileReader = ToolFactory.createDefaultClassFileReader(classFile, IClassFileReader.CLASSFILE_ATTRIBUTES); if (classFileReader != null) { char[] className = classFileReader.getClassName(); if (className != null) { String fqn = new String(classFileReader.getClassName()).replace("/", "."); //$NON-NLS-1$ //$NON-NLS-2$ IJavaProject javaProject = classFile.getJavaProject(); IType sourceType = null; try { sourceType = javaProject.findType(fqn); if (sourceType != null) { return sourceType.getCompilationUnit(); } } catch (JavaModelException e) { // ignore } } } return null; } }); if (units.size() > 0) { ArquillianCoreActivator.getDefault().removeProjectLoader(currentProject); build(units, monitor); } }