本文整理汇总了Java中org.eclipse.jdt.core.IPackageFragmentRoot.K_SOURCE属性的典型用法代码示例。如果您正苦于以下问题:Java IPackageFragmentRoot.K_SOURCE属性的具体用法?Java IPackageFragmentRoot.K_SOURCE怎么用?Java IPackageFragmentRoot.K_SOURCE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.eclipse.jdt.core.IPackageFragmentRoot
的用法示例。
在下文中一共展示了IPackageFragmentRoot.K_SOURCE属性的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getIFileFromQualifiedName
/**
* @param project
* @param qualifiedName
* @return
* @throws CoreException
*/
public static IFile getIFileFromQualifiedName(String projectname, String qualifiedName) throws CoreException {
IProject project = getProject(projectname);
IJavaProject jproject = JavaCore.create(project);
IPackageFragment[] pkgs = jproject.getPackageFragments();
String spath = qualifiedName.replace(".", "/");
for (int i = 0; i < pkgs.length; i++) {
if (pkgs[i].getKind() != IPackageFragmentRoot.K_SOURCE)
continue;
IPath path = pkgs[i].getPath().append(spath);
IFile iFile = (IFile) ResourceManager.getResource(path.toString() + ".java");
if (iFile != null && iFile.exists())
return iFile;
}
return null;
}
示例2: build
/**
* @see IBuilder#build
*/
@Override
public void build(Measure measure, ItemMeasured item) {
IPackageFragment[] packages;
ItemMeasured packageMeasured;
String packageName = "";
try {
packages = project.getPackageFragments();
for (IPackageFragment myPackage : packages) {
if ((myPackage.getKind() == IPackageFragmentRoot.K_SOURCE) && myPackage.hasChildren()) {
packageName = myPackage.isDefaultPackage() ? "(default)" : myPackage.getElementName();
packageMeasured = new ItemMeasured(packageName, item);
addClassBuilder(measure, myPackage, packageMeasured);
item.addChild(packageMeasured);
item.setMax(packageMeasured.getMax());
item.setClassWithMax(packageMeasured.getClassWithMax());
item.addValue(packageMeasured.getValue());
item.addMean(packageMeasured.getMean());
}
}
} catch (JavaModelException exception) {
logger.error(exception);
}
}
示例3: getTopLevelPackages
public static Collection<IPackageFragment> getTopLevelPackages(IJavaProject javaProject) {
Set<IPackageFragment> packages = new LinkedHashSet<>();
try {
if (javaProject == null || !javaProject.getProject().isAccessible()) {
return packages;
}
for (IPackageFragment f : javaProject.getPackageFragments()){
if (f.getKind() != IPackageFragmentRoot.K_SOURCE || f.isDefaultPackage() ) {
continue;
}
if (f.containsJavaResources() || f.getChildren().length > 1) {
packages.add(f);
}
}
} catch (CoreException e) {
e.printStackTrace();
}
return packages;
}
示例4: test
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
IProject project = null;
boolean authorized = false;
if (receiver instanceof IJavaProject) {
project = ((IJavaProject)receiver).getProject();
authorized = true;
} else {
if (receiver instanceof IPackageFragmentRoot) {
IPackageFragmentRoot pfr = ((IPackageFragmentRoot)receiver);
project = pfr.getJavaProject().getProject();
try {
authorized = (pfr.getKind() == IPackageFragmentRoot.K_SOURCE);
} catch (JavaModelException ignore) {
}
} else {
if (receiver instanceof IPackageFragment) {
IPackageFragment pf = (IPackageFragment)receiver;
project = pf.getJavaProject().getProject();
authorized = true;
}
}
}
if (authorized && project!= null) {
if (GW4ENature.hasGW4ENature(project))
return true;
}
return false;
}
示例5: loadComboJarListFromBuildPath
@SuppressWarnings("restriction")
private void loadComboJarListFromBuildPath(Combo comboJarList, String newJarName) {
comboJarList.removeAll();
IProject iProject = BuildExpressionEditorDataSturcture.INSTANCE.getCurrentProject();
IJavaProject iJavaProject=null;
try {
iJavaProject = JavaCore.create(iProject);
PackageFragmentRoot srcfragmentRoot= BuildExpressionEditorDataSturcture.INSTANCE.getSrcPackageFragment(iJavaProject);
comboJarList.add(hydrograph.ui.common.util.Constants.ProjectSupport_SRC);
comboJarList.setData(String.valueOf(comboJarList.getItemCount() - 1), srcfragmentRoot);
for (IPackageFragmentRoot iPackageFragmentRoot : iJavaProject.getAllPackageFragmentRoots()) {
if (isJarPresentInLibFolder(iPackageFragmentRoot.getPath())
&& iPackageFragmentRoot.getKind() != IPackageFragmentRoot.K_SOURCE) {
comboJarList.add(iPackageFragmentRoot.getElementName());
comboJarList.setData(String.valueOf(comboJarList.getItemCount() - 1), iPackageFragmentRoot);
}
}
selectAndLoadJarData(newJarName);
} catch (JavaModelException javaModelException) {
LOGGER.error("Error occurred while loading engines-transform jar", javaModelException);
}
finally{
if(iJavaProject!=null){
try {
iJavaProject.close();
} catch (JavaModelException e) {
LOGGER.warn("JavaModelException occurred while closing java-project"+e);
}
}
}
}
示例6: getSourceFolders
/**
* Returns all folders configured as source folders for the given project.
*
* @param javaProject
* the java project to examine
* @return a List of all source folders as IJavaElements
* @throws JavaModelException
* @see {@link #getJavaProjects(IJavaModel)}
*/
private List<IJavaElement> getSourceFolders(IJavaElement javaProject) throws JavaModelException {
List<IJavaElement> folders = new ArrayList<>();
IJavaElement[] children = ((IParent) javaProject).getChildren();
for (IJavaElement child : children) {
if (child instanceof IPackageFragmentRoot) {
IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot) child;
if (packageFragmentRoot.getKind() == IPackageFragmentRoot.K_SOURCE) {
folders.add(packageFragmentRoot);
}
}
}
return folders;
}
示例7: sourceFoldersOnly
private void sourceFoldersOnly(Collection<IPackageFragmentRoot> filtered)
throws JavaModelException {
for (final Iterator<IPackageFragmentRoot> i = filtered.iterator(); i
.hasNext();) {
if (i.next().getKind() != IPackageFragmentRoot.K_SOURCE) {
i.remove();
}
}
}
示例8: createSourceFileLocator
private ISourceFileLocator createSourceFileLocator(IPackageFragmentRoot root)
throws JavaModelException {
if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
return new SourceFolderSourceFileLocator(root);
} else {
return new LibrarySourceFileLocator(root);
}
}
示例9: processPackageFragment
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();
}
示例10: getProjectCompilationUnits
public Set<ICompilationUnit> getProjectCompilationUnits(IJavaProject project) throws JavaModelException {
Set<ICompilationUnit> compilationUnits = new HashSet<ICompilationUnit>();
for (IPackageFragment packageFragment : project.getPackageFragments()) {
if (packageFragment.getKind() == IPackageFragmentRoot.K_SOURCE)
Collections.addAll(compilationUnits, packageFragment.getCompilationUnits());
}
return compilationUnits;
}
示例11: organizeImportsInDirectory
/**
* Organize imports underlying a directory
*
* @param folderUri
* Selected folder URI
* @param proj
* the folder associated project
* @return
* @throws CoreException
*/
public WorkspaceEdit organizeImportsInDirectory(String folderUri, IProject proj) throws CoreException {
WorkspaceEdit rootEdit = new WorkspaceEdit();
IPackageFragment fragment = null;
if (JDTUtils.toURI(folderUri) != null) {
fragment = JDTUtils.resolvePackage(folderUri);
}
// Select an individual package
if (fragment != null) {
organizeImportsInPackageFragment(fragment, rootEdit);
} else if (proj != null) {
// Search the packages under the selected folder:
IJavaProject javaProject = JavaCore.create(proj);
IPath rootPath = ResourceUtils.filePathFromURI(folderUri);
IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots();
HashSet<IJavaElement> result = new HashSet<>();
for (IPackageFragmentRoot root : roots) {
if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
String packageRoot = root.getResource().getLocation().toString();
if (packageRoot.toLowerCase().indexOf(rootPath.toString().toLowerCase()) >= 0) {
collectCompilationUnits(javaProject, result, null);
}
}
}
for (IJavaElement elem : result) {
if (elem.getElementType() == IJavaElement.COMPILATION_UNIT) {
organizeImportsInCompilationUnit((ICompilationUnit) elem, rootEdit);
}
}
}
return rootEdit;
}
示例12: collectCompilationUnits
private void collectCompilationUnits(IPackageFragmentRoot root, Collection<IJavaElement> result, String prefix) throws JavaModelException {
if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
IJavaElement[] children = root.getChildren();
for (int i = 0; i < children.length; i++) {
IPackageFragment pack = (IPackageFragment) children[i];
if (StringUtils.isBlank(prefix) || pack.getElementName().indexOf(prefix) >= 0) {
collectCompilationUnits(pack, result);
}
}
}
}
示例13: isJavaFilePresent
/**
* Checks that the Java file for the given class name exists in the project.
*
* @param project
* the project, must not be {@code null}
* @param className
* the class name, must not be {@code null}
* @return whether the corresponding java file exists in the project
*/
public boolean isJavaFilePresent(final IProject project, final String className) {
int packageSplitIndex = className.lastIndexOf('.');
if (packageSplitIndex == -1) {
throw new IllegalArgumentException(String.format("%s is a simple class name or not a class name at all.", className));
}
int fileNameEndIndex = className.indexOf('$');
if (fileNameEndIndex == -1) {
fileNameEndIndex = className.length();
}
String packageName = className.substring(0, packageSplitIndex);
String fileName = className.substring(packageSplitIndex + 1, fileNameEndIndex) + ".java";
try {
if (project.hasNature(JavaCore.NATURE_ID)) {
for (IPackageFragmentRoot root : JavaCore.create(project).getAllPackageFragmentRoots()) {
if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
for (IJavaElement element : root.getChildren()) {
if (element instanceof IPackageFragment && packageName.equals(element.getElementName())
&& ((IPackageFragment) element).getCompilationUnit(fileName).exists()) {
return true;
}
}
}
}
}
} catch (CoreException e) {
LOGGER.error(String.format("Failed to read project %s.", project.getName()), e);
}
return false;
}
示例14: SourceViewer
public SourceViewer(Composite parent, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler,
boolean showAnnotationsOverview, int styles, IAnnotationAccess annotationAccess, ISharedTextColors sharedColors,
IDocument document)
{
super(parent, verticalRuler, overviewRuler, showAnnotationsOverview, SWT.BOLD);
int id = currentId++;
filename = VIEWER_CLASS_NAME + id++ + ".java";
this.sharedColors=sharedColors;
this.annotationAccess=annotationAccess;
this.fOverviewRuler=overviewRuler;
oldAnnotations= new HashMap<ProjectionAnnotation, Position>();
IJavaProject javaProject = JavaCore.create(BuildExpressionEditorDataSturcture.INSTANCE.getCurrentProject());
try
{
IPackageFragmentRoot[] ipackageFragmentRootList=javaProject.getPackageFragmentRoots();
IPackageFragmentRoot ipackageFragmentRoot=null;
for(IPackageFragmentRoot tempIpackageFragmentRoot:ipackageFragmentRootList)
{
if(tempIpackageFragmentRoot.getKind()==IPackageFragmentRoot.K_SOURCE
&& StringUtils.equals(PathConstant.TEMP_BUILD_PATH_SETTINGS_FOLDER,tempIpackageFragmentRoot.getPath().removeFirstSegments(1).toString()))
{
ipackageFragmentRoot=tempIpackageFragmentRoot;
break;
}
}
IPackageFragment compilationUnitPackage= ipackageFragmentRoot.createPackageFragment(HYDROGRAPH_COMPILATIONUNIT_PACKAGE, true, new NullProgressMonitor());
compilatioUnit= compilationUnitPackage.createCompilationUnit(filename,document.get(),true, new NullProgressMonitor());
}
catch (Exception exception) {
LOGGER.warn("Exception occurred while initializing source viewer", exception);
} finally {
if (javaProject != null) {
try {
javaProject.close();
} catch (JavaModelException javaModelException) {
LOGGER.warn("Exception occurred while closing java-project", javaModelException);
}
}
}
initializeViewer(document);
updateContents();
}