Java Code Examples for org.eclipse.core.resources.IProject#isNatureEnabled()

The following examples show how to use org.eclipse.core.resources.IProject#isNatureEnabled() . 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: MultiPageEditor.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the primary source folder.
 *
 * @return the primary source folder
 */
public IResource getPrimarySourceFolder() {
  IProject project = getProject();
  try {
    if (!project.isNatureEnabled("org.eclipse.jdt.core.javanature")) { //$NON-NLS-1$
      return null;
    }
    IJavaProject javaProj = JavaCore.create(project);
    IPackageFragmentRoot[] frs = javaProj.getPackageFragmentRoots();
    for (int i = 0; i < frs.length; i++) {
      frs[i].open(null);
      IResource resource = frs[i].getResource(); // first folder resource will always be first
      // source folder
      if (resource instanceof IFolder || resource instanceof IProject) {
        return resource;
      }
    }
  } catch (Exception ex) {
    ex.printStackTrace();
  }

  return null;
}
 
Example 2
Source File: ProblemMarkerBuilder.java    From CogniCrypt with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * startMarking Method that starts the Marking process by getting the IPackageFragments
 *
 * @param project Needed for getting the PackageFragments
 * @throws JavaModelException
 * @throws CoreException
 */
private void startMarking(final IProject project) throws JavaModelException, CoreException {
	if (project.isNatureEnabled("org.eclipse.jdt.core.javanature")) {
		final IPackageFragment[] packages = JavaCore.create(project).getPackageFragments();
		for (final IPackageFragment mypackage : packages) {
			getUnitForParser(mypackage);
		}
	}
}
 
Example 3
Source File: JdtUtils.java    From java-debug with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Check if the project is a java project or not.
 */
public static boolean isJavaProject(IProject project) {
    if (project == null || !project.exists()) {
        return false;
    }
    try {
        if (!project.isNatureEnabled(JavaCore.NATURE_ID)) {
            return false;
        }
    } catch (CoreException e) {
        return false;
    }
    return true;
}