當前位置: 首頁>>代碼示例>>Java>>正文


Java IPackageFragmentRoot.getKind方法代碼示例

本文整理匯總了Java中org.eclipse.jdt.core.IPackageFragmentRoot.getKind方法的典型用法代碼示例。如果您正苦於以下問題:Java IPackageFragmentRoot.getKind方法的具體用法?Java IPackageFragmentRoot.getKind怎麽用?Java IPackageFragmentRoot.getKind使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jdt.core.IPackageFragmentRoot的用法示例。


在下文中一共展示了IPackageFragmentRoot.getKind方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: attachSource

import org.eclipse.jdt.core.IPackageFragmentRoot; //導入方法依賴的package包/類
public static void attachSource(final IPackageFragmentRoot fragment, final IPath newSourcePath,
    IProgressMonitor monitor) {
  try {
    if (fragment == null || fragment.getKind() != IPackageFragmentRoot.K_BINARY) {
      return;
    }
    if (!Objects.equals(fragment.getSourceAttachmentPath(), newSourcePath)) {
      // would be so cool if it refreshed the UI automatically
      fragment.attachSource(newSourcePath, null, monitor);
      // close the root so that source attachment cache is flushed. Else UI
      // won't update
      fragment.close();
      // we have to manually fire a delta to notify the UI about the source
      // attachment.
      JavaModelManager manager = JavaModelManager.getJavaModelManager();
      JavaElementDelta attachedSourceDelta = new JavaElementDelta(fragment.getJavaModel());
      attachedSourceDelta.sourceAttached(fragment);
      manager.getDeltaProcessor().fire(attachedSourceDelta, ElementChangedEvent.POST_CHANGE);
    }
  } catch (CoreException e) {
    // ignore
  }
}
 
開發者ID:fbricon,項目名稱:pde.source.lookup,代碼行數:24,代碼來源:ClasspathUtils.java

示例2: getSimpleTextForJavaElement

import org.eclipse.jdt.core.IPackageFragmentRoot; //導入方法依賴的package包/類
private String getSimpleTextForJavaElement(Object element) {
  if (element instanceof IPackageFragmentRoot) {
    final IPackageFragmentRoot root = (IPackageFragmentRoot) element;
    // tweak label if the package fragment root is the project itself:
    if (root.getElementName().length() == 0) {
      element = root.getJavaProject();
    }
    // shorten JAR references
    try {
      if (root.getKind() == IPackageFragmentRoot.K_BINARY) {
        return root.getPath().lastSegment();
      }
    } catch (JavaModelException e) {
      EclEmmaUIPlugin.log(e);
    }
  }
  return workbenchLabelProvider.getText(element);
}
 
開發者ID:eclipse,項目名稱:eclemma,代碼行數:19,代碼來源:CellTextConverter.java

示例3: internalGetContentReader

import org.eclipse.jdt.core.IPackageFragmentRoot; //導入方法依賴的package包/類
/**
 * Gets a reader for an package fragment's Javadoc comment content from the source attachment.
 * The content does contain only the text from the comment without the Javadoc leading star characters.
 * Returns <code>null</code> if the package fragment does not contain a Javadoc comment or if no source is available.
 * @param fragment The package fragment to get the Javadoc of.
 * @return Returns a reader for the Javadoc comment content or <code>null</code> if the member
 * does not contain a Javadoc comment or if no source is available
 * @throws JavaModelException is thrown when the package fragment's javadoc can not be accessed
 * @since 3.4
 */
private static Reader internalGetContentReader(IPackageFragment fragment) throws JavaModelException {
	IPackageFragmentRoot root= (IPackageFragmentRoot) fragment.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);

	//1==> Handle the case when the documentation is present in package-info.java or package-info.class file
	boolean isBinary= root.getKind() == IPackageFragmentRoot.K_BINARY;
	ITypeRoot packageInfo;
	if (isBinary) {
		packageInfo= fragment.getClassFile(PACKAGE_INFO_CLASS);
	} else {
		packageInfo= fragment.getCompilationUnit(PACKAGE_INFO_JAVA);
	}
	if (packageInfo != null && packageInfo.exists()) {
		String source = packageInfo.getSource();
		//the source can be null for some of the class files
		if (source != null) {
			Javadoc javadocNode = getPackageJavadocNode(fragment, source);
			if (javadocNode != null) {
				int start = javadocNode.getStartPosition();
				int length = javadocNode.getLength();
				return new JavaDocCommentReader(source, start, start + length - 1);
			}
		}
	}
	return null;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:36,代碼來源:JavadocContentAccess.java

示例4: test

import org.eclipse.jdt.core.IPackageFragmentRoot; //導入方法依賴的package包/類
@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; 
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:31,代碼來源:SynchronizeBuildPoliciesEnabled.java

示例5: getSrcPackageFragment

import org.eclipse.jdt.core.IPackageFragmentRoot; //導入方法依賴的package包/類
@SuppressWarnings("restriction")
public PackageFragmentRoot getSrcPackageFragment(IJavaProject iJavaProject) throws JavaModelException {
	for(IPackageFragmentRoot iPackageFragmentRoot:iJavaProject.getAllPackageFragmentRoots()){
		if(iPackageFragmentRoot instanceof PackageFragmentRoot && iPackageFragmentRoot.getKind()==iPackageFragmentRoot.K_SOURCE){
			if(StringUtils.startsWith(iPackageFragmentRoot.toString(),hydrograph.ui.common.util.Constants.ProjectSupport_SRC)){
				return (PackageFragmentRoot) iPackageFragmentRoot;
			}
		}
	}
	return null;
}
 
開發者ID:capitalone,項目名稱:Hydrograph,代碼行數:12,代碼來源:BuildExpressionEditorDataSturcture.java

示例6: loadComboJarListFromBuildPath

import org.eclipse.jdt.core.IPackageFragmentRoot; //導入方法依賴的package包/類
@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);
			}
		}
	}

}
 
開發者ID:capitalone,項目名稱:Hydrograph,代碼行數:34,代碼來源:CategoriesDialogSourceComposite.java

示例7: getSourceFolders

import org.eclipse.jdt.core.IPackageFragmentRoot; //導入方法依賴的package包/類
/**
 * 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;
}
 
開發者ID:VisuFlow,項目名稱:visuflow-plugin,代碼行數:23,代碼來源:BreakpointLocator.java

示例8: isBinaryFragment

import org.eclipse.jdt.core.IPackageFragmentRoot; //導入方法依賴的package包/類
public static boolean isBinaryFragment(IPackageFragmentRoot pfr) {
  try {
    return pfr != null && pfr.getKind() == IPackageFragmentRoot.K_BINARY;
  } catch (JavaModelException e) {
    return false;
  }
}
 
開發者ID:fbricon,項目名稱:pde.source.lookup,代碼行數:8,代碼來源:ClasspathUtils.java

示例9: isBinaryProject

import org.eclipse.jdt.core.IPackageFragmentRoot; //導入方法依賴的package包/類
private boolean isBinaryProject(IPackageFragmentRoot fragment) {
  try {
    return fragment.getKind() == IPackageFragmentRoot.K_BINARY;
  } catch (JavaModelException e) {
    return false;
  }
}
 
開發者ID:fbricon,項目名稱:pde.source.lookup,代碼行數:8,代碼來源:DownloadSourcesActionDelegate.java

示例10: getPathLabel

import org.eclipse.jdt.core.IPackageFragmentRoot; //導入方法依賴的package包/類
/**
 * Calculates a label for the class path of the given package fragment root.
 * For external entries this is the full path, otherwise it is the project
 * relative path.
 *
 * @param root
 *          package fragment root
 * @return label for the class path entry
 */
private static String getPathLabel(IPackageFragmentRoot root) {
  final IPath path = root.getPath();
  try {
    if (root.getKind() == IPackageFragmentRoot.K_BINARY) {
      return path.lastSegment();
    }
  } catch (JavaModelException e) {
    EclEmmaUIPlugin.log(e);
  }
  return path.removeFirstSegments(1).toString();
}
 
開發者ID:eclipse,項目名稱:eclemma,代碼行數:21,代碼來源:ScopeViewer.java

示例11: createSourceFileLocator

import org.eclipse.jdt.core.IPackageFragmentRoot; //導入方法依賴的package包/類
private ISourceFileLocator createSourceFileLocator(IPackageFragmentRoot root)
    throws JavaModelException {
  if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
    return new SourceFolderSourceFileLocator(root);
  } else {
    return new LibrarySourceFileLocator(root);
  }
}
 
開發者ID:eclipse,項目名稱:eclemma,代碼行數:9,代碼來源:SessionExporter.java

示例12: getClassfilesLocation

import org.eclipse.jdt.core.IPackageFragmentRoot; //導入方法依賴的package包/類
private IResource getClassfilesLocation(IPackageFragmentRoot root)
    throws CoreException {

  // For binary roots the underlying resource directly points to class files:
  if (root.getKind() == IPackageFragmentRoot.K_BINARY) {
    return root.getResource();
  }

  // For source roots we need to find the corresponding output folder:
  IPath path = root.getRawClasspathEntry().getOutputLocation();
  if (path == null) {
    path = root.getJavaProject().getOutputLocation();
  }
  return root.getResource().getWorkspace().getRoot().findMember(path);
}
 
開發者ID:eclipse,項目名稱:eclemma,代碼行數:16,代碼來源:PackageFragementRootAnalyzer.java

示例13: organizeImportsInDirectory

import org.eclipse.jdt.core.IPackageFragmentRoot; //導入方法依賴的package包/類
/**
 * 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;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:42,代碼來源:OrganizeImportsCommand.java

示例14: collectCompilationUnits

import org.eclipse.jdt.core.IPackageFragmentRoot; //導入方法依賴的package包/類
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);
			}
		}
	}
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:12,代碼來源:OrganizeImportsCommand.java

示例15: isJavaFilePresent

import org.eclipse.jdt.core.IPackageFragmentRoot; //導入方法依賴的package包/類
/**
 * 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;
}
 
開發者ID:dsldevkit,項目名稱:dsl-devkit,代碼行數:39,代碼來源:CheckProjectHelper.java


注:本文中的org.eclipse.jdt.core.IPackageFragmentRoot.getKind方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。