private void handleMove(IResourceDelta delta) {
   if ((delta.getFlags() & IResourceDelta.MOVED_TO) != 0) {
     ensureResourceCovered(delta.getResource(), movedRoots);
   } else if ((delta.getFlags() & IResourceDelta.MOVED_FROM) != 0) {
     IResource source = createSourceResource(delta);
     ensureResourceCovered(source, movedRoots);
   }
 }
 private void handleAdded(IResourceDelta delta) {
   if ((delta.getFlags() & IResourceDelta.MOVED_FROM) != 0) {
     handleMove(delta);
   } else if ((delta.getFlags() & IResourceDelta.COPIED_FROM) != 0) {
     handleCopy(delta);
   } else {
     ensureResourceCovered(delta.getResource(), addedRoots);
   }
 }
 private void handleRemoved(IResourceDelta delta) {
   if ((delta.getFlags() & IResourceDelta.OPEN) != 0) {
     closedProjects.add(delta.getResource());
   } else if ((delta.getFlags() & IResourceDelta.MOVED_TO) != 0) {
     handleMove(delta);
   } else {
     ensureResourceCovered(delta.getResource(), removedRoots);
   }
 }
Esempio n. 4
0
 public void processResourceDelta(
     final IResourceDelta[] rDeltas, final ICElement element, Set<IResource> handled) {
   if (rDeltas != null) {
     for (IResourceDelta rd : rDeltas) {
       final int rdkind = rd.getKind();
       if (rdkind != IResourceDelta.ADDED) {
         IResource res = rd.getResource();
         if (!handled.add(res)) {
           continue;
         }
         if (res instanceof IFile) {
           switch (rdkind) {
             case IResourceDelta.CHANGED:
               if ((rd.getFlags() & IResourceDelta.CONTENT) != 0) {
                 fChanged.add(new PotentialTranslationUnit(element, (IFile) res));
               }
               break;
             case IResourceDelta.REMOVED:
               fRemoved.add(new PotentialTranslationUnit(element, (IFile) res));
               break;
           }
         }
       }
       processResourceDelta(
           rd.getAffectedChildren(IResourceDelta.CHANGED | IResourceDelta.REMOVED),
           element,
           handled);
     }
   }
 }
  private void processResourceDelta(WorkingSetDelta result, IResourceDelta delta) {
    IResource resource = delta.getResource();
    int type = resource.getType();
    int index = result.indexOf(resource);
    int kind = delta.getKind();
    int flags = delta.getFlags();
    if (kind == IResourceDelta.CHANGED && type == IResource.PROJECT && index != -1) {
      if ((flags & IResourceDelta.OPEN) != 0) {
        result.set(index, resource);
      }
    }
    if (index != -1 && kind == IResourceDelta.REMOVED) {
      if ((flags & IResourceDelta.MOVED_TO) != 0) {
        result.set(
            index, ResourcesPlugin.getWorkspace().getRoot().findMember(delta.getMovedToPath()));
      } else {
        result.remove(index);
      }
    }

    // Don't dive into closed or opened projects
    if (projectGotClosedOrOpened(resource, kind, flags)) {
      return;
    }

    IResourceDelta[] children = delta.getAffectedChildren();
    for (int i = 0; i < children.length; i++) {
      processResourceDelta(result, children[i]);
    }
  }
 @Override
 public synchronized void resourceChanged(IResourceChangeEvent event) {
   IResource res = event.getResource();
   if (!(res instanceof IProject)) return;
   String name = res.getName();
   IResourceDelta delta = event.getDelta();
   if (delta == null) return;
   int kind = delta.getKind();
   if (configs.containsKey(name)) {
     if (kind == IResourceDelta.REMOVED) {
       configs.remove(name);
       tmpConfigs.remove(name);
     } else if (kind == IResourceDelta.CHANGED) {
       int flags = delta.getFlags();
       if ((flags & IResourceDelta.MOVED_TO) != 0) {
         IPath path = delta.getMovedToPath();
         Map<String, IAConfiguration> cfgs = configs.get(name);
         String newName = path.lastSegment();
         configs.remove(name);
         configs.put(newName, cfgs);
         Map<String, IAConfiguration> tmpcfgs = tmpConfigs.get(name);
         tmpConfigs.remove(name);
         tmpConfigs.put(newName, tmpcfgs);
       }
     }
   }
 }
          public boolean visit(IResourceDelta delta) {
            if (delta.getResource().getType() != IResource.FILE) {
              return true;
            }
            int deltaKind = delta.getKind();
            if (deltaKind == IResourceDelta.CHANGED && delta.getFlags() != IResourceDelta.MARKERS) {
              URI platformURI = URI.createPlatformResourceURI(delta.getFullPath().toString(), true);
              Resource changedResource = resourceSet.getResource(platformURI, false);
              if (changedResource != null) {
                changedResource.unload();
                com.github.funthomas424242.rezeptsammler.rezept.resource.rezept.IRezeptTextResource
                    currentResource = getResource();
                if (changedResource.equals(currentResource)) {
                  // reload the resource displayed in the editor
                  resourceSet.getResource(currentResource.getURI(), true);
                }
                if (currentResource != null && currentResource.getErrors().isEmpty()) {
                  EcoreUtil.resolveAll(currentResource);
                }
                // reset the selected element in outline and properties by text position
                if (highlighting != null) {
                  highlighting.updateEObjectSelection();
                }
              }
            }

            return true;
          }
 private void handleChange(IResourceDelta delta) {
   if ((delta.getFlags() & IResourceDelta.REPLACED) != 0) {
     // A replace was added in place of a removed resource
     handleAdded(delta);
   } else if (delta.getResource().getType() == IResource.FILE) {
     ensureResourceCovered(delta.getResource(), changedRoots);
   }
 }
Esempio n. 9
0
    public boolean visit(IResourceDelta delta) throws CoreException {
      switch (delta.getKind()) {
        case IResourceDelta.ADDED:
        case IResourceDelta.REMOVED:
          collect(delta.getResource());
          break;

        case IResourceDelta.CHANGED:
          if ((delta.getFlags() & (IResourceDelta.CONTENT | IResourceDelta.REPLACED)) != 0)
            collect(delta.getResource());
          break;
      }
      return true;
    }
Esempio n. 10
0
 public boolean visit(IResourceDelta delta) throws CoreException {
   IResource resource = delta.getResource();
   if (resource instanceof IFile) {
     if (delta.getKind() == IResourceDelta.ADDED
         || (delta.getKind() == IResourceDelta.CHANGED
             && ((delta.getFlags() & (IResourceDelta.CONTENT | IResourceDelta.ENCODING))
                 != 0))) {
       updatedFiles.add((IFile) resource);
     } else if (delta.getKind() == IResourceDelta.REMOVED) {
       removedFiles.add((IFile) resource);
     }
   }
   return true;
 }
  /**
   * Process a resource delta.
   *
   * @return true if the parent got refreshed
   */
  private boolean processResourceDelta(IResourceDelta delta, Object parent) {
    int status = delta.getKind();
    int flags = delta.getFlags();

    IResource resource = delta.getResource();
    // filter out changes affecting the output folder
    if (resource == null) return false;

    // this could be optimized by handling all the added children in the parent
    if ((status & IResourceDelta.REMOVED) != 0) {
      if (parent instanceof ISourceFolder) {
        Object grandparent = internalGetParent(parent);
        // if grandparent is src folder root that is equal to project, refresh project
        if (grandparent instanceof ISourceFolderRoot
            && ((ISourceFolderRoot) grandparent)
                .getResource()
                .equals(((ISourceFolderRoot) grandparent).getRubyProject().getProject())) {
          parent = grandparent;
          grandparent = internalGetParent(parent);
        }
        // refresh one level above to deal with empty package filtering properly
        postRefresh(grandparent, PARENT, parent);
        return true;
      } else postRemove(resource);
    }
    if ((status & IResourceDelta.ADDED) != 0) {
      if (parent instanceof ISourceFolder) {
        Object grandparent = internalGetParent(parent);
        // if grandparent is src folder root that is equal to project, refresh project
        if (grandparent instanceof ISourceFolderRoot
            && ((ISourceFolderRoot) grandparent)
                .getResource()
                .equals(((ISourceFolderRoot) grandparent).getRubyProject().getProject())) {
          parent = grandparent;
          grandparent = internalGetParent(parent);
        }
        // refresh one level above to deal with empty package filtering properly
        postRefresh(grandparent, PARENT, parent);
        return true;
      } else postAdd(parent, resource);
    }
    // open/close state change of a project
    if ((flags & IResourceDelta.OPEN) != 0) {
      postProjectStateChanged(internalGetParent(parent));
      return true;
    }
    processResourceDeltas(delta.getAffectedChildren(), resource);
    return false;
  }
  /**
   * @see
   *     org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent)
   */
  @Override
  public void resourceChanged(IResourceChangeEvent event) {
    final IResourceDelta rootDelta = event.getDelta();
    if (rootDelta == null) return;

    final IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
    for (IProject project : projects) {
      final IPath roughnessPath = project.getFullPath().append(ROUGHNESS_DATABASE_PATH);
      final IResourceDelta fileDelta = rootDelta.findMember(roughnessPath);
      if (fileDelta != null) {
        if ((fileDelta.getFlags() & IResourceDelta.CONTENT) != 0)
          startStyleUpdateJob((IFile) fileDelta.getResource());
      }
    }
  }
Esempio n. 13
0
 private boolean isErrorDelta(IResourceDelta delta) {
   if ((delta.getFlags() & IResourceDelta.MARKERS) != 0) {
     IMarkerDelta[] markerDeltas = delta.getMarkerDeltas();
     for (IMarkerDelta markerDelta : markerDeltas) {
       if (markerDelta.isSubtypeOf(IMarker.PROBLEM)) {
         int kind = markerDelta.getKind();
         if (kind == IResourceDelta.ADDED || kind == IResourceDelta.REMOVED) return true;
         int severity = markerDelta.getAttribute(IMarker.SEVERITY, -1);
         int newSeverity = markerDelta.getMarker().getAttribute(IMarker.SEVERITY, -1);
         if (newSeverity != severity) return true;
       }
     }
   }
   return false;
 }
    /**
     * Goes through all the resource-dependent preferences associated with currentProject & key and
     * updates the preference keys if needed based on projectDelta
     *
     * @param currentProject current project of the preferences to be looked at
     * @param key current key/subcategory of the preferences to be looked at
     * @param projectDelta the changes to process the preference keys against
     * @param projectsToSave the projects that need to be updated/saved
     * @return true if currentProject's preferences were modified
     */
    private boolean processPreferences(
        IProject currentProject, String key, IResourceDelta projectDelta, Set projectsToSave) {
      boolean resourceChanges = false;

      // get the project-key preference node
      Preferences projectPrefs = CSSContentProperties.getPreferences(currentProject, key, false);
      if (projectPrefs == null)
        // no preferences for this project-key, just bail
        return false;
      String[] affectedResources;
      try {
        affectedResources = projectPrefs.keys();
      } catch (BackingStoreException e) {
        // problems with the project scope... we gonna miss the
        // changes (but will log)
        Logger.log(
            Logger.WARNING_DEBUG, "Problem retreiving JSP Fragment preferences", e); // $NON-NLS-1$
        return false;
      }

      // go through each preference key (which is really a file name)
      for (int i = 0; i < affectedResources.length; i++) {
        // see if preference key/file name was file that was changed
        IResourceDelta memberDelta = projectDelta.findMember(new Path(affectedResources[i]));
        // no changes for the given resource
        if (memberDelta == null) continue;
        if (memberDelta.getKind() == IResourceDelta.REMOVED) {
          resourceChanges = true;
          // remove the setting for the original location
          String currentValue = projectPrefs.get(affectedResources[i], null);
          projectPrefs.remove(affectedResources[i]);
          if ((memberDelta.getFlags() & IResourceDelta.MOVED_TO) != 0) {
            // if moving, copy the setting for the new location
            IProject targetProject =
                ResourcesPlugin.getWorkspace()
                    .getRoot()
                    .getProject(memberDelta.getMovedToPath().segment(0));
            Preferences targetPrefs = CSSContentProperties.getPreferences(targetProject, key, true);
            targetPrefs.put(
                CSSContentProperties.getKeyFor(memberDelta.getMovedToPath()), currentValue);
            if (targetProject != currentProject) projectsToSave.add(targetProject);
          }
        }
      }
      return resourceChanges;
    }
  static boolean isContentChange(IResourceDelta delta) {
    int kind = delta.getKind();
    if (IResourceDelta.ADDED == kind) {
      return true;
    }

    if (IResourceDelta.CHANGED == kind) {
      if (delta.getResource() instanceof IContainer) {
        return true;
      }

      int flags = delta.getFlags();

      return (flags & IResourceDelta.CONTENT) != 0;
    }

    return false;
  }
Esempio n. 16
0
 public void resourceChanged(IResourceChangeEvent event) {
   if (event.getType() == IResourceChangeEvent.PRE_DELETE
       || event.getType() == IResourceChangeEvent.PRE_CLOSE) {
     IResource r = event.getResource();
     if (r instanceof IProject) {
       KbProject n = (KbProject) KbProjectFactory.getKbProject((IProject) r, false, true);
       if (n != null) {
         n.dispose();
       }
     }
   } else if (event.getType() == IResourceChangeEvent.POST_CHANGE) {
     IResourceDelta[] cs = event.getDelta().getAffectedChildren(IResourceDelta.CHANGED);
     for (IResourceDelta c : cs) {
       if ((c.getFlags() & IResourceDelta.OPEN) != 0 && c.getResource() instanceof IProject) {
         IProject p = (IProject) c.getResource();
         KbProjectFactory.getKbProject(p, true, true);
       }
     }
   }
 }
Esempio n. 17
0
                public boolean visit(IResourceDelta delta) {
                  if (delta.getFlags() != IResourceDelta.MARKERS
                      && delta.getResource().getType() == IResource.FILE) {
                    if ((delta.getKind() & (IResourceDelta.CHANGED | IResourceDelta.REMOVED))
                        != 0) {
                      Resource resource =
                          resourceSet.getResource(
                              URI.createURI(delta.getFullPath().toString()), false);
                      if (resource != null) {
                        if ((delta.getKind() & IResourceDelta.REMOVED) != 0) {
                          removedResources.add(resource);
                        } else {
                          changedResources.add(resource);
                        }
                      }
                    }
                  }

                  return true;
                }
              public boolean visit(IResourceDelta delta) {
                if (delta.getResource().getType() == IResource.FILE) {
                  if (delta.getKind() == IResourceDelta.REMOVED
                      || delta.getKind() == IResourceDelta.CHANGED
                          && delta.getFlags() != IResourceDelta.MARKERS) {
                    Resource resource =
                        resourceSet.getResource(
                            URI.createPlatformResourceURI(delta.getFullPath().toString(), true),
                            false);
                    if (resource != null) {
                      if (delta.getKind() == IResourceDelta.REMOVED) {
                        removedResources.add(resource);
                      } else if (!savedResources.remove(resource)) {
                        changedResources.add(resource);
                      }
                    }
                  }
                }

                return true;
              }
    private boolean moveSettingsIfDerivedChanged(
        IResourceDelta parent,
        IProject currentProject,
        Preferences projectPrefs,
        String[] affectedResources) {
      boolean resourceChanges = false;

      if ((parent.getFlags() & IResourceDelta.DERIVED_CHANGED) != 0) {
        // if derived changed, move encoding to correct preferences
        IPath parentPath = parent.getResource().getProjectRelativePath();
        for (int i = 0; i < affectedResources.length; i++) {
          IPath affectedPath = new Path(affectedResources[i]);
          // if parentPath is an ancestor of affectedPath
          if (parentPath.isPrefixOf(affectedPath)) {
            IResource member = currentProject.findMember(affectedPath);
            if (member != null) {
              Preferences targetPrefs =
                  getPreferences(currentProject, true, member.isDerived(IResource.CHECK_ANCESTORS));
              // if new preferences are different than current
              if (!projectPrefs.absolutePath().equals(targetPrefs.absolutePath())) {
                // remove encoding from old preferences and save in correct preferences
                String currentValue = projectPrefs.get(affectedResources[i], null);
                projectPrefs.remove(affectedResources[i]);
                targetPrefs.put(affectedResources[i], currentValue);
                resourceChanges = true;
              }
            }
          }
        }
      }

      IResourceDelta[] children = parent.getAffectedChildren();
      for (int i = 0; i < children.length; i++) {
        resourceChanges =
            moveSettingsIfDerivedChanged(
                    children[i], currentProject, projectPrefs, affectedResources)
                || resourceChanges;
      }
      return resourceChanges;
    }
 protected void findAffectedSourceFiles(
     IResourceDelta binaryDelta, int segmentCount, StringSet structurallyChangedTypes) {
   // When a package becomes a type or vice versa, expect 2 deltas,
   // one on the folder & one on the class file
   IResource resource = binaryDelta.getResource();
   switch (resource.getType()) {
     case IResource.FOLDER:
       switch (binaryDelta.getKind()) {
         case IResourceDelta.ADDED:
         case IResourceDelta.REMOVED:
           IPath packagePath = resource.getFullPath().removeFirstSegments(segmentCount);
           String packageName = packagePath.toString();
           if (binaryDelta.getKind() == IResourceDelta.ADDED) {
             // see if any known source file is from the same package... classpath already includes
             // new package
             if (!this.newState.isKnownPackage(packageName)) {
               if (JavaBuilder.DEBUG)
                 System.out.println("Found added package " + packageName); // $NON-NLS-1$
               addDependentsOf(packagePath, false);
               return;
             }
             if (JavaBuilder.DEBUG)
               System.out.println(
                   "Skipped dependents of added package " + packageName); // $NON-NLS-1$
           } else {
             // see if the package still exists on the classpath
             if (!this.nameEnvironment.isPackage(packageName)) {
               if (JavaBuilder.DEBUG)
                 System.out.println("Found removed package " + packageName); // $NON-NLS-1$
               addDependentsOf(packagePath, false);
               return;
             }
             if (JavaBuilder.DEBUG)
               System.out.println(
                   "Skipped dependents of removed package " + packageName); // $NON-NLS-1$
           }
           // $FALL-THROUGH$ traverse the sub-packages and .class files
         case IResourceDelta.CHANGED:
           IResourceDelta[] children = binaryDelta.getAffectedChildren();
           for (int i = 0, l = children.length; i < l; i++)
             findAffectedSourceFiles(children[i], segmentCount, structurallyChangedTypes);
       }
       return;
     case IResource.FILE:
       if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(resource.getName())) {
         IPath typePath =
             resource.getFullPath().removeFirstSegments(segmentCount).removeFileExtension();
         switch (binaryDelta.getKind()) {
           case IResourceDelta.ADDED:
           case IResourceDelta.REMOVED:
             if (JavaBuilder.DEBUG)
               System.out.println("Found added/removed class file " + typePath); // $NON-NLS-1$
             addDependentsOf(typePath, false);
             return;
           case IResourceDelta.CHANGED:
             if ((binaryDelta.getFlags() & IResourceDelta.CONTENT) == 0)
               return; // skip it since it really isn't changed
             if (structurallyChangedTypes != null
                 && !structurallyChangedTypes.includes(typePath.toString()))
               return; // skip since it wasn't a structural change
             if (JavaBuilder.DEBUG)
               System.out.println("Found changed class file " + typePath); // $NON-NLS-1$
             addDependentsOf(typePath, false);
         }
         return;
       }
   }
 }
    @Override
    public boolean visit(IResourceDelta delta) throws CoreException {
      if (delta == null) {
        return false;
      }

      IFile file = getFile();
      if (file == null) {
        return false;
      }

      delta = delta.findMember(file.getFullPath());

      if (delta == null) {
        return false;
      }

      Runnable runnable = null;

      switch (delta.getKind()) {
        case IResourceDelta.CHANGED:
          FileInfo info = (FileInfo) getElementInfo(fileEditorInput);
          if (info == null || !canRefreshFromFile(info)) {
            break;
          }

          boolean isSynchronized = computeModificationStamp(file) == info.modificationStamp;
          if ((IResourceDelta.ENCODING & delta.getFlags()) != 0 && isSynchronized) {
            runnable =
                new SafeChange(fileEditorInput) {
                  @Override
                  protected void execute(IEditorInput input) throws Exception {
                    handleElementContentChanged(input);
                  }
                };
          }

          if (runnable == null
              && (IResourceDelta.CONTENT & delta.getFlags()) != 0
              && !isSynchronized) {
            runnable =
                new SafeChange(fileEditorInput) {
                  @Override
                  protected void execute(IEditorInput input) throws Exception {
                    handleElementContentChanged(input);
                  }
                };
          }
          break;

        case IResourceDelta.REMOVED:
          if ((IResourceDelta.MOVED_TO & delta.getFlags()) != 0) {
            final IPath path = delta.getMovedToPath();
            runnable =
                new SafeChange(fileEditorInput) {
                  @Override
                  protected void execute(IEditorInput input) throws Exception {
                    handleElementMoved(input, path);
                  }
                };
          } else {
            info = (FileInfo) getElementInfo(fileEditorInput);
            if (info != null && canRefreshFromFile(info)) {
              runnable =
                  new SafeChange(fileEditorInput) {
                    @Override
                    protected void execute(IEditorInput input) throws Exception {
                      handleElementDeleted(input);
                    }
                  };
            }
          }
          break;
      }

      if (runnable != null) {
        update(runnable);
      }

      return false;
    }
Esempio n. 22
0
 protected boolean isOpened(IResourceDelta delta) {
   return delta.getResource() instanceof IProject
       && (delta.getFlags() & IResourceDelta.OPEN) != 0
       && ((IProject) delta.getResource()).isOpen();
 }
Esempio n. 23
0
  public void resourceChanged(IResourceChangeEvent event) {
    IResource myResource = ResourceUtil.getResource(getEditorInput());

    IResourceDelta delta = event.getDelta();
    if (delta == null) return;
    IPath fullPath = myResource.getFullPath();
    delta = delta.findMember(fullPath);
    if (delta == null) return;

    // Delegate to any interested pages
    for (Object page : pages) {
      if (page instanceof IResourceChangeListener) {
        ((IResourceChangeListener) page).resourceChanged(event);
      }
    }

    // Close editor if file removed or switch to new location if file moved
    if (delta.getKind() == IResourceDelta.REMOVED) {
      if ((delta.getFlags() & IResourceDelta.MOVED_TO) != 0) {
        IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(delta.getMovedToPath());
        final FileEditorInput newInput = new FileEditorInput(file);

        setInput(newInput);
        Display display = getEditorSite().getShell().getDisplay();
        if (display != null) {
          SWTConcurrencyUtil.execForDisplay(
              display,
              true,
              new Runnable() {
                public void run() {
                  setPartNameForInput(newInput);
                  sourcePage.setInput(newInput);
                }
              });
        }
      } else {
        close(false);
      }

    }
    // File content updated externally => reload all pages
    else if ((delta.getKind() & IResourceDelta.CHANGED) > 0
        && (delta.getFlags() & IResourceDelta.CONTENT) > 0) {
      if (!saving.get()) {
        final IDocumentProvider docProvider = sourcePage.getDocumentProvider();
        final IDocument document = docProvider.getDocument(getEditorInput());
        SWTConcurrencyUtil.execForControl(
            getEditorSite().getShell(),
            true,
            new Runnable() {
              public void run() {
                try {
                  model.loadFrom(new IDocumentWrapper(document));
                  updatePages();
                } catch (IOException e) {
                  logger.logError("Failed to reload document", e);
                }
              }
            });
      }
    }
  }
Esempio n. 24
0
 private static boolean isContentChanged(IResourceDelta delta) {
   return delta != null
       && delta.getKind() == IResourceDelta.CHANGED
       && (delta.getFlags() & IResourceDelta.CONTENT) != 0;
 }
 private void processEntryChanges(
     IResourceDelta projectDelta, Map<IProject, Boolean> projectsToSave) {
   // check each resource with user-set encoding to see if it has
   // been moved/deleted or if derived state has been changed
   IProject currentProject = (IProject) projectDelta.getResource();
   Preferences projectRegularPrefs = getPreferences(currentProject, false, false, true);
   Preferences projectDerivedPrefs = getPreferences(currentProject, false, true, true);
   Map<Boolean, String[]> affectedResourcesMap = new HashMap<>();
   try {
     // no regular preferences for this project
     if (projectRegularPrefs == null) affectedResourcesMap.put(Boolean.FALSE, new String[0]);
     else affectedResourcesMap.put(Boolean.FALSE, projectRegularPrefs.keys());
     // no derived preferences for this project
     if (projectDerivedPrefs == null) affectedResourcesMap.put(Boolean.TRUE, new String[0]);
     else affectedResourcesMap.put(Boolean.TRUE, projectDerivedPrefs.keys());
   } catch (BackingStoreException e) {
     // problems with the project scope... we will miss the changes (but will log)
     String message = Messages.resources_readingEncoding;
     Policy.log(
         new ResourceStatus(
             IResourceStatus.FAILED_GETTING_CHARSET, currentProject.getFullPath(), message, e));
     return;
   }
   for (Iterator<Boolean> it = affectedResourcesMap.keySet().iterator(); it.hasNext(); ) {
     Boolean isDerived = it.next();
     String[] affectedResources = affectedResourcesMap.get(isDerived);
     Preferences projectPrefs =
         isDerived.booleanValue() ? projectDerivedPrefs : projectRegularPrefs;
     for (int i = 0; i < affectedResources.length; i++) {
       IResourceDelta memberDelta = projectDelta.findMember(new Path(affectedResources[i]));
       // no changes for the given resource
       if (memberDelta == null) continue;
       if (memberDelta.getKind() == IResourceDelta.REMOVED) {
         boolean shouldDisableCharsetDeltaJobForCurrentProject = false;
         // remove the setting for the original location - save its value though
         String currentValue = projectPrefs.get(affectedResources[i], null);
         projectPrefs.remove(affectedResources[i]);
         if ((memberDelta.getFlags() & IResourceDelta.MOVED_TO) != 0) {
           IPath movedToPath = memberDelta.getMovedToPath();
           IResource resource = workspace.getRoot().findMember(movedToPath);
           if (resource != null) {
             Preferences encodingSettings =
                 getPreferences(
                     resource.getProject(), true, resource.isDerived(IResource.CHECK_ANCESTORS));
             if (currentValue == null || currentValue.trim().length() == 0)
               encodingSettings.remove(getKeyFor(movedToPath));
             else encodingSettings.put(getKeyFor(movedToPath), currentValue);
             IProject targetProject = workspace.getRoot().getProject(movedToPath.segment(0));
             if (targetProject.equals(currentProject))
               // if the file was moved inside the same project disable charset listener
               shouldDisableCharsetDeltaJobForCurrentProject = true;
             else projectsToSave.put(targetProject, Boolean.FALSE);
           }
         }
         projectsToSave.put(
             currentProject, Boolean.valueOf(shouldDisableCharsetDeltaJobForCurrentProject));
       }
     }
     if (moveSettingsIfDerivedChanged(
         projectDelta, currentProject, projectPrefs, affectedResources)) {
       // if settings were moved between preferences files disable charset listener so we don't
       // react to changes made by ourselves
       projectsToSave.put(currentProject, Boolean.TRUE);
     }
   }
 }
  protected boolean findSourceFiles(
      IResourceDelta sourceDelta, ClasspathMultiDirectory md, int segmentCount)
      throws CoreException {
    // When a package becomes a type or vice versa, expect 2 deltas,
    // one on the folder & one on the source file
    IResource resource = sourceDelta.getResource();
    // remember that if inclusion & exclusion patterns change then a full build is done
    boolean isExcluded =
        (md.exclusionPatterns != null || md.inclusionPatterns != null)
            && Util.isExcluded(resource, md.inclusionPatterns, md.exclusionPatterns);
    switch (resource.getType()) {
      case IResource.FOLDER:
        if (isExcluded && md.inclusionPatterns == null)
          return true; // no need to go further with this delta since its children cannot be
        // included

        switch (sourceDelta.getKind()) {
          case IResourceDelta.ADDED:
            if (!isExcluded) {
              IPath addedPackagePath = resource.getFullPath().removeFirstSegments(segmentCount);
              createFolder(
                  addedPackagePath, md.binaryFolder); // ensure package exists in the output folder
              // see if any known source file is from the same package... classpath already includes
              // new package
              if (this.sourceLocations.length > 1
                  && this.newState.isKnownPackage(addedPackagePath.toString())) {
                if (JavaBuilder.DEBUG)
                  System.out.println(
                      "Skipped dependents of added package " + addedPackagePath); // $NON-NLS-1$
              } else {
                if (JavaBuilder.DEBUG)
                  System.out.println("Found added package " + addedPackagePath); // $NON-NLS-1$
                addDependentsOf(addedPackagePath, true);
              }
            }
            // $FALL-THROUGH$ collect all the source files
          case IResourceDelta.CHANGED:
            IResourceDelta[] children = sourceDelta.getAffectedChildren();
            for (int i = 0, l = children.length; i < l; i++)
              if (!findSourceFiles(children[i], md, segmentCount)) return false;
            return true;
          case IResourceDelta.REMOVED:
            if (isExcluded) {
              // since this folder is excluded then there is nothing to delete (from this md), but
              // must walk any included subfolders
              children = sourceDelta.getAffectedChildren();
              for (int i = 0, l = children.length; i < l; i++)
                if (!findSourceFiles(children[i], md, segmentCount)) return false;
              return true;
            }
            IPath removedPackagePath = resource.getFullPath().removeFirstSegments(segmentCount);
            if (this.sourceLocations.length > 1) {
              for (int i = 0, l = this.sourceLocations.length; i < l; i++) {
                if (this.sourceLocations[i].sourceFolder.getFolder(removedPackagePath).exists()) {
                  // only a package fragment was removed, same as removing multiple source files
                  createFolder(
                      removedPackagePath,
                      md.binaryFolder); // ensure package exists in the output folder
                  IResourceDelta[] removedChildren = sourceDelta.getAffectedChildren();
                  for (int j = 0, m = removedChildren.length; j < m; j++)
                    if (!findSourceFiles(removedChildren[j], md, segmentCount)) return false;
                  return true;
                }
              }
            }
            if ((sourceDelta.getFlags() & IResourceDelta.MOVED_TO) != 0) {
              // same idea as moving a source file
              // see bug 163200
              IResource movedFolder =
                  this.javaBuilder.workspaceRoot.getFolder(sourceDelta.getMovedToPath());
              JavaBuilder.removeProblemsAndTasksFor(movedFolder);
            }
            IFolder removedPackageFolder = md.binaryFolder.getFolder(removedPackagePath);
            if (removedPackageFolder.exists()) removedPackageFolder.delete(IResource.FORCE, null);
            // add dependents even when the package thinks it does not exist to be on the safe side
            if (JavaBuilder.DEBUG)
              System.out.println("Found removed package " + removedPackagePath); // $NON-NLS-1$
            addDependentsOf(removedPackagePath, true);
            this.newState.removePackage(sourceDelta);
        }
        return true;
      case IResource.FILE:
        if (isExcluded) return true;

        String resourceName = resource.getName();
        // GROOVY start
        // determine if this is a Groovy project
        final boolean isInterestingProject =
            LanguageSupportFactory.isInterestingProject(this.javaBuilder.getProject());
        // GROOVY end

        // GROOVY start
        /* old {
        if (org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(resourceName)) {
        } new */
        // GRECLIPSE-404 must call 'isJavaLikeFile' directly in order to make the Scala-Eclipse
        // plugin's weaving happy
        if ((!isInterestingProject
                && org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(resourceName)
                && !LanguageSupportFactory.isInterestingSourceFile(resourceName))
            || (isInterestingProject
                && LanguageSupportFactory.isSourceFile(resourceName, isInterestingProject))) {
          // GROOVY end
          IPath typePath =
              resource.getFullPath().removeFirstSegments(segmentCount).removeFileExtension();
          String typeLocator = resource.getProjectRelativePath().toString();
          switch (sourceDelta.getKind()) {
            case IResourceDelta.ADDED:
              if (JavaBuilder.DEBUG)
                System.out.println("Compile this added source file " + typeLocator); // $NON-NLS-1$
              this.sourceFiles.add(new SourceFile((IFile) resource, md, true));
              String typeName = typePath.toString();
              if (!this.newState.isDuplicateLocator(
                  typeName, typeLocator)) { // adding dependents results in 2 duplicate errors
                if (JavaBuilder.DEBUG)
                  System.out.println("Found added source file " + typeName); // $NON-NLS-1$
                addDependentsOf(typePath, true);
              }
              return true;
            case IResourceDelta.REMOVED:
              char[][] definedTypeNames = this.newState.getDefinedTypeNamesFor(typeLocator);
              if (definedTypeNames == null) { // defined a single type matching typePath
                removeClassFile(typePath, md.binaryFolder);
                if ((sourceDelta.getFlags() & IResourceDelta.MOVED_TO) != 0) {
                  // remove problems and tasks for a compilation unit that is being moved (to
                  // another package or renamed)
                  // if the target file is a compilation unit, the new cu will be recompiled
                  // if the target file is a non-java resource, then markers are removed
                  // see bug 2857
                  IResource movedFile =
                      this.javaBuilder.workspaceRoot.getFile(sourceDelta.getMovedToPath());
                  JavaBuilder.removeProblemsAndTasksFor(movedFile);
                }
              } else {
                if (JavaBuilder.DEBUG)
                  System.out.println(
                      "Found removed source file " + typePath.toString()); // $NON-NLS-1$
                addDependentsOf(
                    typePath,
                    true); // add dependents of the source file since it may be involved in a name
                // collision
                if (definedTypeNames.length
                    > 0) { // skip it if it failed to successfully define a type
                  IPath packagePath = typePath.removeLastSegments(1);
                  for (int i = 0, l = definedTypeNames.length; i < l; i++)
                    removeClassFile(
                        packagePath.append(new String(definedTypeNames[i])), md.binaryFolder);
                }
              }
              this.newState.removeLocator(typeLocator);
              return true;
            case IResourceDelta.CHANGED:
              if ((sourceDelta.getFlags() & IResourceDelta.CONTENT) == 0
                  && (sourceDelta.getFlags() & IResourceDelta.ENCODING) == 0)
                return true; // skip it since it really isn't changed
              if (JavaBuilder.DEBUG)
                System.out.println(
                    "Compile this changed source file " + typeLocator); // $NON-NLS-1$
              this.sourceFiles.add(new SourceFile((IFile) resource, md, true));
          }
          return true;
        } else if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(resourceName)) {
          // perform full build if a managed class file has been changed
          if (this.makeOutputFolderConsistent) {
            IPath typePath =
                resource.getFullPath().removeFirstSegments(segmentCount).removeFileExtension();
            if (this.newState.isKnownType(typePath.toString())) {
              if (JavaBuilder.DEBUG)
                System.out.println(
                    "MUST DO FULL BUILD. Found change to class file " + typePath); // $NON-NLS-1$
              return false;
            }
          }
          return true;
        } else if (md.hasIndependentOutputFolder) {
          if (this.javaBuilder.filterExtraResource(resource)) return true;

          // copy all other resource deltas to the output folder
          IPath resourcePath = resource.getFullPath().removeFirstSegments(segmentCount);
          IResource outputFile = md.binaryFolder.getFile(resourcePath);
          switch (sourceDelta.getKind()) {
            case IResourceDelta.ADDED:
              if (outputFile.exists()) {
                if (JavaBuilder.DEBUG)
                  System.out.println("Deleting existing file " + resourcePath); // $NON-NLS-1$
                outputFile.delete(IResource.FORCE, null);
              }
              if (JavaBuilder.DEBUG)
                System.out.println("Copying added file " + resourcePath); // $NON-NLS-1$
              createFolder(
                  resourcePath.removeLastSegments(1),
                  md.binaryFolder); // ensure package exists in the output folder
              copyResource(resource, outputFile);
              return true;
            case IResourceDelta.REMOVED:
              if (outputFile.exists()) {
                if (JavaBuilder.DEBUG)
                  System.out.println("Deleting removed file " + resourcePath); // $NON-NLS-1$
                outputFile.delete(IResource.FORCE, null);
              }
              return true;
            case IResourceDelta.CHANGED:
              if ((sourceDelta.getFlags() & IResourceDelta.CONTENT) == 0
                  && (sourceDelta.getFlags() & IResourceDelta.ENCODING) == 0)
                return true; // skip it since it really isn't changed
              if (outputFile.exists()) {
                if (JavaBuilder.DEBUG)
                  System.out.println("Deleting existing file " + resourcePath); // $NON-NLS-1$
                outputFile.delete(IResource.FORCE, null);
              }
              if (JavaBuilder.DEBUG)
                System.out.println("Copying changed file " + resourcePath); // $NON-NLS-1$
              createFolder(
                  resourcePath.removeLastSegments(1),
                  md.binaryFolder); // ensure package exists in the output folder
              copyResource(resource, outputFile);
          }
          return true;
        }
    }
    return true;
  }
    /**
     * Provides visitor pattern due to implement <code>IResourceDeltaVisitor</code>. This method
     * must not be called by client because it is called by EclipseSensorPlugin instance. Note that
     * <code>true</code> is returned if the parameter of IResourceDelta instance has children.
     * <code>false</code> is returned when either Project is opened, closed, or file is saved
     * because no more traverse of children of the IResourceDelta instance is needed.
     *
     * @param delta IResourceDelta instance to contains delta resource.
     * @return true if the resource delta's children should be visited; false if they should be
     *     skipped.
     * @throws CoreException if the visit fails for some reason.
     */
    public boolean visit(IResourceDelta delta) throws CoreException {
      IResource resource = delta.getResource();
      int flag = delta.getFlags();
      int kind = delta.getKind();

      // If there is compilation problem with the current java file then send out the activity data.
      if ((flag & IResourceDelta.MARKERS) != 0 && EclipseSensor.this.buildErrorSensor != null) {
        EclipseSensor.this.buildErrorSensor.findBuildProblem(delta);
      }

      // :RESOLVED: 26 May 2003
      // Note that the 147456 enumeration type is not listed in the IResourceDelta static filed.
      // However, its number is generated when Project is either opened or closed so that
      // it is checked in the logical condition.
      if (resource instanceof IProject && ((flag == IResourceDelta.OPEN) || (flag == 147456))) {
        IProject project = resource.getProject();
        String projectName = project.getName();
        URI projectResoruce = project.getFile(".project").getLocationURI();

        Map<String, String> keyValueMap = new HashMap<String, String>();
        keyValueMap.put(EclipseSensorConstants.UNIT_TYPE, "project");
        keyValueMap.put(EclipseSensorConstants.UNIT_NAME, projectName);

        if (((IProject) resource).isOpen()) {
          keyValueMap.put(EclipseSensorConstants.SUBTYPE, "Open");
          EclipseSensor.this.addDevEvent(
              EclipseSensorConstants.DEVEVENT_EDIT,
              projectResoruce,
              keyValueMap,
              projectResoruce.toString());
        } else {
          keyValueMap.put(EclipseSensorConstants.SUBTYPE, "Close");
          EclipseSensor.this.addDevEvent(
              EclipseSensorConstants.DEVEVENT_EDIT,
              projectResoruce,
              keyValueMap,
              projectResoruce.toString());
        }
        return false;
      }
      if ((kind == IResourceDelta.CHANGED)
          && (flag == IResourceDelta.CONTENT)
          && resource instanceof IFile) {
        if (resource.getLocation().toString().endsWith(EclipseSensorConstants.JAVA_EXT)) {
          IFile file = (IFile) resource;

          Map<String, String> keyValueMap = new HashMap<String, String>();

          keyValueMap.put("Language", "java");
          keyValueMap.put(EclipseSensorConstants.UNIT_TYPE, EclipseSensorConstants.FILE);

          // Fully qualified class path
          String className = EclipseSensor.this.getFullyQualifedClassName(file);
          keyValueMap.put("Class-Name", className);

          // Size of the file in buffer
          String bufferSize = String.valueOf(activeBufferSize);
          keyValueMap.put("Current-Size", bufferSize);

          // Measure java file.
          JavaStatementMeter testCounter = measureJavaFile(file);
          testCounter = measureJavaFile(file);
          String methodCount = String.valueOf(testCounter.getNumOfMethods());
          keyValueMap.put("Current-Methods", methodCount);

          String statementCount = String.valueOf(testCounter.getNumOfStatements());
          keyValueMap.put("Current-Statements", statementCount);

          // Number of test method and assertion statements.
          if (testCounter.hasTest()) {
            String testMethodCount = String.valueOf(testCounter.getNumOfTestMethods());
            keyValueMap.put("Current-Test-Methods", testMethodCount);

            String testAssertionCount = String.valueOf(testCounter.getNumOfTestAssertions());
            keyValueMap.put("Current-Test-Assertions", testAssertionCount);
          }

          // EclipseSensor.this.eclipseSensorShell.doCommand("Activity", activityData);
          // Construct message to display on Eclipse status bar.
          URI fileResource = file.getLocationURI();

          StringBuffer message = new StringBuffer("Save File");
          message.append(" : ").append(EclipseSensor.this.extractFileName(fileResource));

          keyValueMap.put(EclipseSensorConstants.SUBTYPE, "Save");
          EclipseSensor.this.addDevEvent(
              EclipseSensorConstants.DEVEVENT_EDIT, fileResource, keyValueMap, message.toString());
        }

        // Visit the children because it is not necessary for the saving file to be only one file.
        return true;
      }
      return true; // visit the children
    }
 public void resourceChanged(IResourceChangeEvent event) {
   IResourceDelta delta = event.getDelta();
   if (delta.getFlags() != IResourceDelta.MARKERS && delta.getAffectedChildren().length > 0) {
     CMPKeySynchronizationAdapter.flushUnresolvedKeyAttributesOnCleanBuild();
   }
 }
 private IResourceDelta resourceDelta(int flags) {
   IResourceDelta classResourceDelta = mock(IResourceDelta.class);
   when(classResourceDelta.getResource()).thenReturn(resource);
   when(classResourceDelta.getFlags()).thenReturn(flags);
   return classResourceDelta;
 }
 private void handleCopy(IResourceDelta delta) {
   if ((delta.getFlags() & IResourceDelta.COPIED_FROM) != 0) {
     IResource source = createSourceResource(delta);
     ensureResourceCovered(source, copiedRoots);
   }
 }