Java Code Examples for org.eclipse.core.resources.IResource#isDerived()

The following examples show how to use org.eclipse.core.resources.IResource#isDerived() . 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: FilteringCompositeChange.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected Change createUndoChange(Change[] childUndos) {
	List<Change> filteredUndos = newArrayList();
	for (Change childUndo : childUndos) {
		try {
			Object modifiedElement = childUndo.getModifiedElement();
			if (modifiedElement instanceof ICompilationUnit) {
				ICompilationUnit cu = (ICompilationUnit) modifiedElement;
				if (cu.exists()) {
					IResource resource = cu.getUnderlyingResource();
					if (!resource.isDerived()) {
						filteredUndos.add(childUndo);
					}
				}
			} else {
				filteredUndos.add(childUndo);
			}
		} catch (JavaModelException e) {
			LOG.error("Error filtering refactoring undo changes", e);
		}
	}
	return super.createUndoChange(toArray(filteredUndos, Change.class));
}
 
Example 2
Source File: FileNamePatternSearchScope.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private static void addToList(ArrayList<IResource> res, IResource curr, boolean includeDerived) {
	if (!includeDerived && curr.isDerived(IResource.CHECK_ANCESTORS)) {
		return;
	}
	IPath currPath= curr.getFullPath();
	for (int k= res.size() - 1; k >= 0 ; k--) {
		IResource other= res.get(k);
		IPath otherPath= other.getFullPath();
		if (otherPath.isPrefixOf(currPath)) {
			return;
		}
		if (currPath.isPrefixOf(otherPath)) {
			res.remove(k);
		}
	}
	res.add(curr);
}
 
Example 3
Source File: ResourceTreeSelectionDialog.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
private boolean isAcceptableResourceType(Object element) {
  if (!(element instanceof IResource)) {
    return false;
  }

  IResource resource = (IResource) element;
  if (resource.isDerived()) {
    return false;
  }

  if (resource.getName().startsWith(".")) {
    return false;
  }

  return (resource.getType() & acceptedResourceTypes) > 0;
}
 
Example 4
Source File: WebAppUtilities.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This is nearly a clone of the method of the same name in BuildPathsBlock,
 * except here we force delete files, so out-of-sync files don't result in
 * exceptions.
 *
 * TODO: we can revert back to using BuildPathsBlock's method if we update
 * EnhancerJob to refresh any files it touches.
 */
private static void removeOldClassfiles(IResource resource)
    throws CoreException {
  if (resource.isDerived()) {
    resource.delete(true, null);
  } else {
    IContainer resourceAsContainer = AdapterUtilities.getAdapter(resource,
        IContainer.class);
    if (resourceAsContainer != null) {
      IResource[] members = resourceAsContainer.members();
      for (int i = 0; i < members.length; i++) {
        removeOldClassfiles(members[i]);
      }
    }
  }
}
 
Example 5
Source File: HostPagePathSelectionDialog.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
private static List<IFolder> getSubfolders(IFolder folder) {
  List<IFolder> folders = new ArrayList<IFolder>();

  try {
    for (IResource member : folder.members()) {
      if (member.getType() == IResource.FOLDER) {
        // Filter out derived and hidden folders (anything prefixed with .)
        if (member.isDerived() || member.getName().startsWith(".")) {
          continue;
        }
        folders.add((IFolder) member);
      }
    }
  } catch (CoreException e) {
    GWTPluginLog.logError(e);
  }

  return folders;
}
 
Example 6
Source File: AnalysisBuilderRunnable.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Checks if some resource is hierarchically derived (if any parent is derived, it's also derived).
 */
private static boolean isHierarchicallyDerived(IResource curr) {
    if (useEclipse32DerivedVersion) {
        do {
            if (curr.isDerived()) {
                return true;
            }
            curr = curr.getParent();
        } while (curr != null);
        return false;
    } else {
        try {
            return curr.isDerived(IResource.CHECK_ANCESTORS);
        } catch (Throwable e) {
            useEclipse32DerivedVersion = true;
            return isHierarchicallyDerived(curr);
        }
    }
}
 
Example 7
Source File: ProjectDeltaVisitor.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean visit(IResourceDelta delta) {
  IResource resource = delta.getResource();

  if (resource.isDerived()) return false;

  /*
   * TODO Refactor this, we don't need to make a distinction here.
   * Resource is resource. It's just Saros that insists on having separate
   * activities for files and folders.
   */
  if (isFile(resource)) {
    handleFileDelta(delta);
    return true;
  } else if (isFolder(resource)) {
    return handleFolderDelta(delta);
  }

  return true;
}
 
Example 8
Source File: FindBugsWorker.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * @return map of all source folders to output folders, for current java
 *         project, where both are represented by absolute IPath objects
 *
 * @throws CoreException
 */
private Map<IPath, IPath> createOutputLocations() throws CoreException {

    Map<IPath, IPath> srcToOutputMap = new HashMap<>();

    // get the default location => relative to wsp
    IPath defaultOutputLocation = ResourceUtils.relativeToAbsolute(javaProject.getOutputLocation());
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    // path to the project without project name itself
    IClasspathEntry entries[] = javaProject.getResolvedClasspath(true);
    for (int i = 0; i < entries.length; i++) {
        IClasspathEntry classpathEntry = entries[i];
        if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            IPath outputLocation = ResourceUtils.getOutputLocation(classpathEntry, defaultOutputLocation);
            if (outputLocation == null) {
                continue;
            }
            IResource cpeResource = root.findMember(classpathEntry.getPath());
            // patch from 2891041: do not analyze derived "source" folders
            // because they probably contain auto-generated classes
            if (cpeResource != null && cpeResource.isDerived()) {
                continue;
            }
            // TODO not clear if it is absolute in workspace or in global FS
            IPath srcLocation = ResourceUtils.relativeToAbsolute(classpathEntry.getPath());
            if (srcLocation != null) {
                srcToOutputMap.put(srcLocation, outputLocation);
            }
        }
    }

    return srcToOutputMap;
}
 
Example 9
Source File: ClientBundleResourceChangeListener.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private static boolean isPossibleClientBundleResourceDelta(
    IResourceDelta delta) {
  IResource resource = delta.getResource();

  if (resource.isDerived()) {
    return false;
  }

  if (resource.getType() != IResource.FILE) {
    return false;
  }

  // We only care about additions/deletions. If the contents of a
  // resource file change, it doesn't affect our validation.
  if (delta.getKind() != IResourceDelta.ADDED
      && delta.getKind() != IResourceDelta.REMOVED) {
    return false;
  }

  // Ignore Java source changes, since we're only interested in resource files
  if ("java".equals(resource.getFileExtension())) {
    return false;
  }

  if (!GWTNature.isGWTProject(resource.getProject())) {
    return false;
  }

  IJavaProject javaProject = JavaCore.create(resource.getProject());
  if (!javaProject.isOnClasspath(resource)) {
    return false;
  }

  // All checks passed; it looks like a change we care about
  return true;
}
 
Example 10
Source File: ActionUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static boolean isEditable(Shell shell, IJavaElement element) {
	if (! isProcessable(shell, element))
		return false;

	IJavaElement cu= element.getAncestor(IJavaElement.COMPILATION_UNIT);
	if (cu != null) {
		IResource resource= cu.getResource();
		if (resource != null && resource.isDerived(IResource.CHECK_ANCESTORS)) {

			// see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#validateEditorInputState()
			final String warnKey= AbstractDecoratedTextEditorPreferenceConstants.EDITOR_WARN_IF_INPUT_DERIVED;
			IPreferenceStore store= EditorsUI.getPreferenceStore();
			if (!store.getBoolean(warnKey))
				return true;

			MessageDialogWithToggle toggleDialog= MessageDialogWithToggle.openYesNoQuestion(
					shell,
					ActionMessages.ActionUtil_warning_derived_title,
					Messages.format(ActionMessages.ActionUtil_warning_derived_message, BasicElementLabels.getPathLabel(resource.getFullPath(), false)),
					ActionMessages.ActionUtil_warning_derived_dontShowAgain,
					false,
					null,
					null);

			EditorsUI.getPreferenceStore().setValue(warnKey, !toggleDialog.getToggleState());

			return toggleDialog.getReturnCode() == IDialogConstants.YES_ID;
		}
	}
	return true;
}
 
Example 11
Source File: BuildPathsBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static boolean hasClassfiles(IResource resource) throws CoreException {
	if (resource.isDerived()) {
		return true;
	}
	if (resource instanceof IContainer) {
		IResource[] members= ((IContainer) resource).members();
		for (int i= 0; i < members.length; i++) {
			if (hasClassfiles(members[i])) {
				return true;
			}
		}
	}
	return false;
}
 
Example 12
Source File: BuildPathsBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static void removeOldClassfiles(IResource resource) throws CoreException {
	if (resource.isDerived()) {
		resource.delete(false, null);
	} else if (resource instanceof IContainer) {
		IResource[] members= ((IContainer) resource).members();
		for (int i= 0; i < members.length; i++) {
			removeOldClassfiles(members[i]);
		}
	}
}
 
Example 13
Source File: HiddenFileFilter.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
	if (element instanceof IResource) {
		final IResource resource = (IResource) element;
		if (resource.isHidden() || resource.isDerived() || resource.isPhantom()) {
			return false;
		}
		final IPath path2 = resource.getRawLocation();
		if (path2 != null) {
			final File rawFile = path2.toFile();
			return rawFile != null && !rawFile.isHidden();
		}
	}
	return true;
}
 
Example 14
Source File: TLAParsingBuilder.java    From tlaplus with MIT License 4 votes vote down vote up
private void build(String moduleFileName, IResource rootFile, IProgressMonitor monitor)
{
    // if the changed file is a root file - run the spec build
    if (rootFile != null && (rootFile.getName().equals(moduleFileName)))
    {
        monitor.beginTask("Invoking the SANY to re-parse the spec", IProgressMonitor.UNKNOWN);
        // this will rebuild the spec starting from root, and change the
        // spec status
        // still, we want to continue and keep the dependency information
        // about other files
        ParserHelper.rebuildSpec(new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN));

        monitor.done();
    } else
    {
        // retrieve a resource
        IProject project = getProject();
        // get the file
        IResource moduleFile = project.getFile(moduleFileName);

        /*
         * At this point of time, all modules should have been linked if
         * (!moduleFile.exists()) { moduleFile =
         * ResourceHelper.getLinkedFile(project, moduleFileName, false); }
         */

        if (moduleFile == null || !moduleFile.exists())
        {
            throw new IllegalStateException("Resource not found during build: " + moduleFileName);
        }

        // never build derived resources
        if (!moduleFile.isDerived())
        {
            monitor.beginTask("Invoking SANY to re-parse a module " + moduleFileName, IProgressMonitor.UNKNOWN);
            // run the module build
            ParserHelper.rebuildModule(moduleFile, new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN));

            monitor.done();
        } else
        {
            Activator.getDefault().logDebug("Skipping resource: " + moduleFileName);
        }
    }

}
 
Example 15
Source File: ToStringResourceDeltaVisitor.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean visit(IResourceDelta delta) throws CoreException {
  boolean result = true;
  switch (delta.getKind()) {
    case IResourceDelta.NO_CHANGE:
      sb.append("0");
      result = false;
      break;
    case IResourceDelta.CHANGED:
      sb.append("C(");
      int f = delta.getFlags();
      if (f == 0) {
        sb.append("0) ");
      } else {
        Set<Entry<Integer, String>> entrySet = map.entrySet();
        for (Entry<Integer, String> entry : entrySet) {
          if (0 != (f & entry.getKey())) sb.append(entry.getValue());
        }
        sb.append(") ");
      }

      break;
    case IResourceDelta.ADDED:
      sb.append("A ");
      break;
    case IResourceDelta.REMOVED:
      sb.append("R ");
      break;
    default:
      sb.append("? ");
  }
  IResource resource = delta.getResource();
  if (resource != null) {
    if (resource.isDerived()) sb.append("* ");

    if (resource.isPhantom()) sb.append("P ");

    if (resource.isHidden()) sb.append("H ");

    sb.append(resource.getFullPath().toPortableString());
  } else {
    sb.append("No resource");
  }
  sb.append("\n");

  return result;
}
 
Example 16
Source File: AbstractSarlScriptInteractiveSelector.java    From sarl with Apache License 2.0 2 votes vote down vote up
/** Replies if the given resource could be considered for discovering an agent to be launched.
 *
 * @param resource the resource.
 * @return {@code true} if the resource could be explored.
 */
@SuppressWarnings("static-method")
protected boolean isValidResource(IResource resource) {
	return resource.isAccessible() && !resource.isHidden() && !resource.isPhantom() && !resource.isDerived();
}