private boolean isEmpty(IPackageFragment fragment) { try { return (fragment.getCompilationUnits().length == 0) && (fragment.getClassFiles().length == 0); } catch (JavaModelException e) { // ignore } return false; }
private boolean isEmpty(IPackageFragment fragment) { try { return (fragment.getCompilationUnits().length == 0) && (fragment.getClassFiles().length == 0); } catch (JavaModelException e) { // ignore } return false; }
private void processPackageFragment(ITypeVisitor visitor, IPackageFragment fragment, IProgressMonitor monitor) throws JavaModelException { switch (fragment.getKind()) { case IPackageFragmentRoot.K_SOURCE: final ICompilationUnit[] units = fragment.getCompilationUnits(); monitor.beginTask("", units.length); //$NON-NLS-1$ for (final ICompilationUnit unit : units) { if (monitor.isCanceled()) { break; } processCompilationUnit(visitor, unit, monitor); monitor.worked(1); } break; case IPackageFragmentRoot.K_BINARY: final IClassFile[] classfiles = fragment.getClassFiles(); monitor.beginTask("", classfiles.length); //$NON-NLS-1$ for (final IClassFile classfile : classfiles) { if (monitor.isCanceled()) { break; } processClassFile(visitor, classfile, monitor); monitor.worked(1); } break; } monitor.done(); }
private void findStaticHooks(final IPackageFragment pkg, final TreeMultimap<IType, IMethod> index) throws JavaModelException { for (final ITypeRoot f : pkg.getClassFiles()) { findStaticHooks(index, f); } for (final ITypeRoot f : pkg.getCompilationUnits()) { findStaticHooks(index, f); } }
/** * Adds all of the openables defined within this package fragment to the * list. */ private void injectAllOpenablesForPackageFragment( IPackageFragment packFrag, ArrayList openables) { try { IPackageFragmentRoot root = (IPackageFragmentRoot) packFrag.getParent(); int kind = root.getKind(); if (kind != 0) { boolean isSourcePackageFragment = (kind == IPackageFragmentRoot.K_SOURCE); if (isSourcePackageFragment) { ICompilationUnit[] cus = packFrag.getCompilationUnits(); for (int i = 0, length = cus.length; i < length; i++) { openables.add(cus[i]); } } else { IClassFile[] classFiles = packFrag.getClassFiles(); for (int i = 0, length = classFiles.length; i < length; i++) { openables.add(classFiles[i]); } } } } catch (JavaModelException e) { // ignore } }
/** * Adds all of the openables defined within this package fragment to the * list. */ private void injectAllOpenablesForPackageFragment( IPackageFragment packFrag, ArrayList openables) { try { IPackageFragmentRoot root = (IPackageFragmentRoot) packFrag.getParent(); int kind = root.getKind(); if (kind != 0) { boolean isSourcePackageFragment = (kind == IPackageFragmentRoot.K_SOURCE); if (isSourcePackageFragment) { ICompilationUnit[] cus = packFrag.getCompilationUnits(); for (int i = 0, length = cus.length; i < length; i++) { openables.add(cus[i]); } } else { IClassFile[] classFiles = packFrag.getClassFiles(); for (int i = 0, length = classFiles.length; i < length; i++) { openables.add(classFiles[i]); } } } } catch (JavaModelException e) { // ignore } }
/** * Adds all of the openables defined within this package fragment to the * list. */ private void injectAllOpenablesForPackageFragment( IPackageFragment packFrag, ArrayList openables) { try { IPackageFragmentRoot root = (IPackageFragmentRoot) packFrag.getParent(); int kind = root.getKind(); if (kind != 0) { boolean isSourcePackageFragment = (kind == IPackageFragmentRoot.K_SOURCE); if (isSourcePackageFragment) { ICompilationUnit[] cus = packFrag.getCompilationUnits(); for (int i = 0, length = cus.length; i < length; i++) { openables.add(cus[i]); } } else { IClassFile[] classFiles = packFrag.getClassFiles(); for (int i = 0, length = classFiles.length; i < length; i++) { openables.add(classFiles[i]); } } } } catch (JavaModelException e) { // ignore } }
/** * Adds all of the openables defined within this package fragment to the * list. */ private void injectAllOpenablesForPackageFragment( IPackageFragment packFrag, ArrayList openables) { try { IPackageFragmentRoot root = (IPackageFragmentRoot) packFrag.getParent(); int kind = root.getKind(); if (kind != 0) { boolean isSourcePackageFragment = (kind == IPackageFragmentRoot.K_SOURCE); if (isSourcePackageFragment) { ICompilationUnit[] cus = packFrag.getCompilationUnits(); for (int i = 0, length = cus.length; i < length; i++) { openables.add(cus[i]); } } else { IClassFile[] classFiles = packFrag.getClassFiles(); for (int i = 0, length = classFiles.length; i < length; i++) { openables.add(classFiles[i]); } } } } catch (JavaModelException e) { // ignore } }
private Object[] getPackageContents(IPackageFragment fragment) throws JavaModelException { if (fragment.getKind() == IPackageFragmentRoot.K_SOURCE) { // AspectJ Change begin - ignore AJCompilationUnits to avoid duplicates Object[] files = fragment.getCompilationUnits(); ArrayList filesToKeep = new ArrayList(); for (int i = 0; i < files.length; i++) { if(!(files[i] instanceof AJCompilationUnit)) { filesToKeep.add(files[i]); } } return concatenate(filesToKeep.toArray(), fragment.getNonJavaResources()); // AspectJ Change end } return concatenate(fragment.getClassFiles(), fragment.getNonJavaResources()); }
final IPackageFragment fragment= iterator.next(); final IProgressMonitor subMonitor= new SubProgressMonitor(monitor, 100); final IClassFile[] files= fragment.getClassFiles(); final int size= files.length; subMonitor.beginTask(getOperationLabel(), size * 50);
if (child instanceof IPackageFragment) { IPackageFragment frag = (IPackageFragment) child; IClassFile[] files = frag.getClassFiles(); for (IClassFile file : files) classFiles.add(file);
private Object[] getPackageContent(IPackageFragment pack) { ArrayList<Object> result= new ArrayList<>(); try { ICompilationUnit[] units= pack.getCompilationUnits(); for (int i= 0; i < units.length; i++) { if (JavaModelUtil.isPackageInfo(units[i])) result.add(units[i]); IType[] types= units[i].getTypes(); for (int j= 0; j < types.length; j++) { if (isValidType(types[j])) result.add(types[j]); } } IClassFile[] classFiles= pack.getClassFiles(); for (int i= 0; i < classFiles.length; i++) { if (isValidType(classFiles[i].getType())) result.add(classFiles[i].getType()); } Object[] nonJavaResources= pack.getNonJavaResources(); for (int i= 0; i < nonJavaResources.length; i++) { result.add(nonJavaResources[i]); } } catch (JavaModelException e) { JavaPlugin.log(e); } return result.toArray(); }
private Object[] getPackageContents(IPackageFragment fragment) throws JavaModelException { ISourceReference[] sourceRefs; if (fragment.getKind() == IPackageFragmentRoot.K_SOURCE) { sourceRefs= fragment.getCompilationUnits(); } else { IClassFile[] classFiles= fragment.getClassFiles(); List topLevelClassFile= new ArrayList(); for (int i= 0; i < classFiles.length; i++) { IType type= classFiles[i].getType(); if (type != null && type.getDeclaringType() == null && !type.isAnonymous() && !type.isLocal()) topLevelClassFile.add(classFiles[i]); } sourceRefs= (ISourceReference[])topLevelClassFile.toArray(new ISourceReference[topLevelClassFile.size()]); } Object[] result= new Object[0]; for (int i= 0; i < sourceRefs.length; i++) result= concatenate(result, removeImportAndPackageDeclarations(getChildren(sourceRefs[i]))); return concatenate(result, fragment.getNonJavaResources()); }
private Object[] getPackageContents(IPackageFragment fragment) throws JavaModelException { ISourceReference[] sourceRefs; if (fragment.getKind() == IPackageFragmentRoot.K_SOURCE) { sourceRefs= fragment.getCompilationUnits(); } else { IClassFile[] classFiles= fragment.getClassFiles(); List<IClassFile> topLevelClassFile= new ArrayList<>(); for (int i= 0; i < classFiles.length; i++) { IType type= classFiles[i].getType(); if (type != null && type.getDeclaringType() == null && !type.isAnonymous() && !type.isLocal()) topLevelClassFile.add(classFiles[i]); } sourceRefs= topLevelClassFile.toArray(new ISourceReference[topLevelClassFile.size()]); } Object[] result= new Object[0]; for (int i= 0; i < sourceRefs.length; i++) result= concatenate(result, removeImportAndPackageDeclarations(getChildren(sourceRefs[i]))); return concatenate(result, fragment.getNonJavaResources()); }
/** * Evaluates all children of a given {@link IPackageFragment}. Clients can override this method. * @param fragment The fragment to evaluate the children for. * @return The children of the given package fragment. * @exception JavaModelException if the package fragment does not exist or if an * exception occurs while accessing its corresponding resource * * @since 3.3 */ protected Object[] getPackageContent(IPackageFragment fragment) throws JavaModelException { if (fragment.getKind() == IPackageFragmentRoot.K_SOURCE) { return concatenate(fragment.getCompilationUnits(), fragment.getNonJavaResources()); } return concatenate(fragment.getClassFiles(), fragment.getNonJavaResources()); }
/** * Evaluates all children of a given {@link IPackageFragment}. Clients can override this method. * @param fragment The fragment to evaluate the children for. * @return The children of the given package fragment. * @exception JavaModelException if the package fragment does not exist or if an * exception occurs while accessing its corresponding resource * * @since 3.3 */ protected Object[] getPackageContent(IPackageFragment fragment) throws JavaModelException { if (fragment.getKind() == IPackageFragmentRoot.K_SOURCE) { return concatenate(fragment.getCompilationUnits(), fragment.getNonJavaResources()); } return concatenate(fragment.getClassFiles(), fragment.getNonJavaResources()); }
protected Map<String, HashSet<String>> findPackageReferences(Collection<String> packages, IProgressMonitor monitor) { IJavaProject jp = JavaCore.create(fProject); HashMap<String, HashSet<String>> pkgsAndUses = new HashMap<>(); IPackageFragment[] frags = PDEJavaHelper.getPackageFragments(jp, Collections.EMPTY_SET, false); SubMonitor subMonitor = SubMonitor.convert(monitor, frags.length * 2); for (IPackageFragment fragment : frags) { SubMonitor iterationMonitor = subMonitor.split(2); if (iterationMonitor.isCanceled()) { return pkgsAndUses; } iterationMonitor.subTask( NLS.bind(PDEUIMessages.CalculateUsesOperation_calculatingDirective, fragment.getElementName())); if (packages.contains(fragment.getElementName())) { HashSet<String> pkgs = new HashSet<>(); pkgsAndUses.put(fragment.getElementName(), pkgs); try { findReferences(fragment.getCompilationUnits(), pkgs, iterationMonitor.split(1), false); findReferences(fragment.getClassFiles(), pkgs, iterationMonitor.split(1), true); } catch (JavaModelException e) { } } } return pkgsAndUses; }
private void indexClassFiles(IndexWriter indexWriter, IPackageFragmentRoot jar, IProgressMonitor monitor) throws Exception { String jarName = getJarName(jar); String projectPath = getProjectPath(jar); for(IJavaElement pkgRootChild: jar.getChildren()) { IPackageFragment pkg = (IPackageFragment) pkgRootChild; monitor.setTaskName("Indexing JAR Source Attachements: " + jar.getElementName() + " - " + pkg.getElementName()); for(IClassFile classFile: pkg.getClassFiles()) { if( classFile.getElementName().contains("$") ) continue; // not type root try { ClassFileSourceStorage classFileSourceStorage = new ClassFileSourceStorage(classFile); if (classFileSourceStorage.hasSource()) indexStorageWithRetry(indexWriter, classFileSourceStorage, projectPath, IResource.NULL_STAMP, jarName); } catch (Exception e) { //Issue #69. Avoid Ex where Eclipse has trouble loading a source file. } if( monitor.isCanceled() ) return; } } }
private static void addElementFor(IPackageFragment packageFragment, boolean isArchive, IApiComponent apiComponent, ApiScope scope) throws JavaModelException, CoreException { // add package fragment elements only if this is an API package IApiDescription apiDescription = apiComponent.getApiDescription(); IApiAnnotations annotations = apiDescription.resolveAnnotations(Factory.packageDescriptor(packageFragment.getElementName())); if (annotations == null || !VisibilityModifiers.isAPI(annotations.getVisibility())) { return; } if (isArchive) { IClassFile[] classFiles = packageFragment.getClassFiles(); for (IClassFile classFile : classFiles) { addElementFor(classFile, apiComponent, scope); } } else { ICompilationUnit[] units = packageFragment.getCompilationUnits(); for (ICompilationUnit unit : units) { addElementFor(unit, apiComponent, scope); } } }
private static void addElementFor( IPackageFragment packageFragment, boolean isArchive, IApiComponent apiComponent, ApiScope scope) throws JavaModelException, CoreException { // add package fragment elements only if this is an API package IApiDescription apiDescription = apiComponent.getApiDescription(); IApiAnnotations annotations = apiDescription.resolveAnnotations(Factory.packageDescriptor(packageFragment.getElementName())); if (annotations == null || !VisibilityModifiers.isAPI(annotations.getVisibility())) { return; } if (isArchive) { IClassFile[] classFiles = packageFragment.getClassFiles(); for (int i = 0, max= classFiles.length; i < max; i++) { addElementFor(classFiles[i], apiComponent, scope); } } else { ICompilationUnit[] units = packageFragment.getCompilationUnits(); for (int i = 0, max= units.length; i < max; i++) { addElementFor(units[i], apiComponent, scope); } } }