Java Code Examples for org.eclipse.jdt.core.IPackageFragment#getClassFiles()

The following examples show how to use org.eclipse.jdt.core.IPackageFragment#getClassFiles() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavaBrowsingContentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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<IClassFile>();
		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());
}
 
Example 2
Source File: RegionBasedHierarchyBuilder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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
	}
}
 
Example 3
Source File: JavaEditorBreadcrumb.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private Object[] getPackageContent(IPackageFragment pack) {
	ArrayList<Object> result= new ArrayList<Object>();
	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();
}
 
Example 4
Source File: PackagesViewLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isEmpty(IPackageFragment fragment) {
	try {
		return (fragment.getCompilationUnits().length == 0) && (fragment.getClassFiles().length == 0);
	} catch (JavaModelException e) {
		// ignore
	}
	return false;
}