/**
  * Visits the given resource delta that corresponds to a file.
  *
  * @param delta The given resource delta
  * @param file The file concerning by this delta
  * @return <code>true</code> if the resource delta's children should be visited; <code>false
  *     </code> if they should be skipped.
  * @exception CoreException if the visit fails for some reason.
  */
 protected boolean visitFile(IResourceDelta delta, IFile currentFile) throws CoreException {
   // By default, we do not visit the resource delta's children
   boolean visitChildren = false;
   final Option<ModelingProject> optionalModelingProject =
       ModelingProject.asModelingProject(currentFile.getProject());
   if (optionalModelingProject.some()) {
     if (IResourceDelta.REMOVED == delta.getKind()) {
       if (optionalModelingProject.get().isValid()) {
         // Check that this IFile is not the main representations
         // file of this project
         if (optionalModelingProject.get().isMainRepresentationsFile(currentFile)) {
           mainRepresentationsFileToDelete.add(currentFile);
         }
       } else if (new FileQuery(currentFile).isSessionResourceFile()) {
         // If the project is not valid and the deleted file is a
         // representations file, validate the project again.
         optionalModelingProject
             .get()
             .getMainRepresentationsFileURI(new NullProgressMonitor(), true, false);
       }
     } else if (IResourceDelta.ADDED == delta.getKind()) {
       // Check that the corresponding project does not already
       // have a main representations file
       if (SiriusUtil.SESSION_RESOURCE_EXTENSION.equals(currentFile.getFileExtension())) {
         if (optionalModelingProject.get().isValid()) {
           representationsFileToAddOnValidModelingProject.add(currentFile);
         }
       }
     }
   }
   return visitChildren;
 }
Exemplo n.º 2
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;
 }
Exemplo n.º 3
0
 @Override
 public void resourceChanged(IResourceChangeEvent event) {
   IResourceDelta delta = event.getDelta();
   if (delta == null) {
     return;
   }
   IEditorInput input = getEditorInput();
   IPath localPath = null;
   if (input instanceof IPathEditorInput) {
     localPath = ((IPathEditorInput) input).getPath();
   }
   if (localPath == null) {
     return;
   }
   localPath = ContentUtils.convertPathToWorkspacePath(localPath);
   delta = delta.findMember(localPath);
   if (delta == null) {
     return;
   }
   if (delta.getKind() == IResourceDelta.CHANGED) {
     // Refresh editor
     DBeaverUI.asyncExec(
         new Runnable() {
           @Override
           public void run() {
             loadImage();
           }
         });
   }
 }
Exemplo n.º 4
0
          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;
          }
Exemplo n.º 5
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);
     }
   }
 }
Exemplo n.º 6
0
    public boolean visit(IResourceDelta delta) throws CoreException {
      IResource resource = delta.getResource();
      if (!(resource instanceof IFile)
          || !resource.getName().endsWith(".java")
          || !resource.exists()) {
        return true;
      }
      monitor.subTask(resource.getName());

      switch (delta.getKind()) {
        case IResourceDelta.ADDED:
          check(resource, architecture, true);
          monitor.worked(1);
          break;
        case IResourceDelta.REMOVED:
          delete(resource);
          monitor.worked(1);
          break;
        case IResourceDelta.CHANGED:
          check(resource, architecture, true);
          monitor.worked(1);
          break;
      }

      /* return true to continue visiting children */
      return true;
    }
  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);
       }
     }
   }
 }
Exemplo n.º 9
0
  protected void incrementalBuild(IResourceDelta delta, final IProgressMonitor monitor) {
    int deltaKind = delta.getKind();

    if (deltaKind == IResourceDelta.REMOVED) {
      return;
    }

    // final boolean[] buildCSS = new boolean[1];

    try {
      delta.accept(
          new IResourceDeltaVisitor() {
            public boolean visit(IResourceDelta delta) {
              final IResource resource = delta.getResource();
              IPath fullResourcePath = resource.getFullPath();

              for (String segment : fullResourcePath.segments()) {
                if ("_diffs".equals(segment)) // $NON-NLS-1$
                {
                  // IDE-110 IDE-648
                  final IWebProject webproject =
                      LiferayCore.create(IWebProject.class, getProject());

                  if (webproject != null && webproject.getDefaultDocrootFolder() != null) {
                    IFolder webappRoot = webproject.getDefaultDocrootFolder();

                    if (webappRoot != null) {
                      IFolder diffs = webappRoot.getFolder(new Path("_diffs")); // $NON-NLS-1$

                      if (diffs != null
                          && diffs.exists()
                          && diffs.getFullPath().isPrefixOf(fullResourcePath)) {
                        applyDiffsDeltaToDocroot(delta, diffs.getParent(), monitor);

                        return false;
                      }
                    }
                  }
                } else if ("build.xml".equals(segment)) // IDE-828 //$NON-NLS-1$
                {
                  IPath relPath = resource.getProjectRelativePath();

                  if (relPath != null && relPath.segmentCount() == 1) {
                    try {
                      compileTheme(resource.getProject());
                    } catch (CoreException e) {
                      ThemeCore.logError("Error compiling theme.", e); // $NON-NLS-1$
                    }
                  }
                }
              }

              return true; // visit children too
            }
          });
    } catch (CoreException e) {
      ThemeCore.logError(e);
    }
  }
 protected boolean findSourceFiles(IResourceDelta delta) throws CoreException {
   ArrayList visited =
       this.makeOutputFolderConsistent ? new ArrayList(this.sourceLocations.length) : null;
   for (int i = 0, l = this.sourceLocations.length; i < l; i++) {
     ClasspathMultiDirectory md = this.sourceLocations[i];
     if (this.makeOutputFolderConsistent
         && md.hasIndependentOutputFolder
         && !visited.contains(md.binaryFolder)) {
       // even a project which acts as its own source folder can have an independent/nested output
       // folder
       visited.add(md.binaryFolder);
       IResourceDelta binaryDelta = delta.findMember(md.binaryFolder.getProjectRelativePath());
       if (binaryDelta != null) {
         int segmentCount = binaryDelta.getFullPath().segmentCount();
         IResourceDelta[] children = binaryDelta.getAffectedChildren();
         for (int j = 0, m = children.length; j < m; j++)
           if (!checkForClassFileChanges(children[j], md, segmentCount)) return false;
       }
     }
     if (md.sourceFolder.equals(this.javaBuilder.currentProject)) {
       // skip nested source & output folders when the project is a source folder
       int segmentCount = delta.getFullPath().segmentCount();
       IResourceDelta[] children = delta.getAffectedChildren();
       for (int j = 0, m = children.length; j < m; j++)
         if (!isExcludedFromProject(children[j].getFullPath()))
           if (!findSourceFiles(children[j], md, segmentCount)) return false;
     } else {
       IResourceDelta sourceDelta = delta.findMember(md.sourceFolder.getProjectRelativePath());
       if (sourceDelta != null) {
         if (sourceDelta.getKind() == IResourceDelta.REMOVED) {
           if (JavaBuilder.DEBUG)
             System.out.println(
                 "ABORTING incremental build... found removed source folder"); //$NON-NLS-1$
           return false; // removed source folder should not make it here, but handle anyways
           // (ADDED is supported)
         }
         int segmentCount = sourceDelta.getFullPath().segmentCount();
         IResourceDelta[] children = sourceDelta.getAffectedChildren();
         try {
           for (int j = 0, m = children.length; j < m; j++)
             if (!findSourceFiles(children[j], md, segmentCount)) return false;
         } catch (CoreException e) {
           // catch the case that a package has been renamed and collides on disk with an
           // as-yet-to-be-deleted package
           if (e.getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) {
             if (JavaBuilder.DEBUG)
               System.out.println(
                   "ABORTING incremental build... found renamed package"); //$NON-NLS-1$
             return false;
           }
           throw e; // rethrow
         }
       }
     }
     this.notifier.checkCancel();
   }
   return true;
 }
 protected boolean findAffectedSourceFiles(
     IResourceDelta delta, ClasspathLocation[] classFoldersAndJars, IProject prereqProject) {
   for (int i = 0, l = classFoldersAndJars.length; i < l; i++) {
     ClasspathLocation bLocation = classFoldersAndJars[i];
     // either a .class file folder or a zip/jar file
     if (bLocation != null) { // skip unchanged output folder
       IPath p = bLocation.getProjectRelativePath();
       if (p != null) {
         IResourceDelta binaryDelta = delta.findMember(p);
         if (binaryDelta != null) {
           if (bLocation instanceof ClasspathJar) {
             if (JavaBuilder.DEBUG)
               System.out.println(
                   "ABORTING incremental build... found delta to jar/zip file"); //$NON-NLS-1$
             return false; // do full build since jar file was changed (added/removed were caught
             // as classpath change)
           }
           if (binaryDelta.getKind() == IResourceDelta.ADDED
               || binaryDelta.getKind() == IResourceDelta.REMOVED) {
             if (JavaBuilder.DEBUG)
               System.out.println(
                   "ABORTING incremental build... found added/removed binary folder"); //$NON-NLS-1$
             return false; // added/removed binary folder should not make it here (classpath
             // change), but handle anyways
           }
           int segmentCount = binaryDelta.getFullPath().segmentCount();
           IResourceDelta[] children =
               binaryDelta.getAffectedChildren(); // .class files from class folder
           StringSet structurallyChangedTypes = null;
           if (bLocation.isOutputFolder())
             structurallyChangedTypes =
                 this.newState.getStructurallyChangedTypes(
                     this.javaBuilder.getLastState(prereqProject));
           for (int j = 0, m = children.length; j < m; j++)
             findAffectedSourceFiles(children[j], segmentCount, structurallyChangedTypes);
           this.notifier.checkCancel();
         }
       }
     }
   }
   return true;
 }
Exemplo n.º 12
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;
                }
Exemplo n.º 13
0
 private void checkInvalidate(IResourceDelta delta, IResource resource) {
   int kind = delta.getKind();
   if (kind == IResourceDelta.REMOVED
       || kind == IResourceDelta.ADDED
       || (kind == IResourceDelta.CHANGED && isErrorDelta(delta))) {
     // invalidate the path and all parent paths
     while (resource.getType() != IResource.ROOT && fChangedElements.add(resource)) {
       resource = resource.getParent();
     }
   }
 }
 public boolean visit(IResourceDelta delta) {
   // only interested in changed resources (not added or removed)
   if (delta.getKind() != IResourceDelta.REMOVED) {
     return true;
   }
   IResource resource = delta.getResource();
   if (resource.getType() == IResource.FILE
       && CALSourcePathMapper.CAL_FILE_EXTENSION.equalsIgnoreCase(resource.getFileExtension())) {
     removedCalFileFound = true;
   }
   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;
              }
Exemplo n.º 16
0
 @Override
 public boolean visit(IResourceDelta delta, IProgressMonitor monitor) throws CoreException {
   if (delta.getKind() == IResourceDelta.CHANGED) {
     IResource resource = delta.getResource();
     if (resource.getType() == IResource.FILE) {
       if (DartCore.isHTMLLikeFileName(resource.getName())) {
         processHtml((IFile) resource);
       }
     }
   }
   return true;
 }
  static boolean isRemove(IResourceDelta delta) {
    int kind = delta.getKind();

    if (IResourceDelta.REMOVED == kind) {
      return true;
    }

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

    return false;
  }
Exemplo n.º 18
0
 @Override
 public boolean visit(IResourceDelta delta) throws CoreException {
   IResource res = delta.getResource();
   if (res instanceof IProject && delta.getKind() == IResourceDelta.CHANGED) {
     IProject project = (IProject) res;
     if (!project.isAccessible()) {
       // only track open C projects
       return false;
     }
   }
   checkInvalidate(delta, res);
   return true;
 }
Exemplo n.º 19
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;
    }
Exemplo n.º 20
0
  protected void applyDiffsDeltaToDocroot(
      final IResourceDelta delta, final IContainer docroot, final IProgressMonitor monitor) {
    int deltaKind = delta.getKind();

    switch (deltaKind) {
      case IResourceDelta.REMOVED_PHANTOM:
        break;
    }

    final IPath path = CoreUtil.getResourceLocation(docroot);
    // final IPath restoreLocation = getRestoreLocation(docroot);

    final ILiferayProject liferayProject = LiferayCore.create(getProject());

    final String themeParent = liferayProject.getProperty("theme.parent", "_styled");

    final ILiferayPortal portal = liferayProject.adapt(ILiferayPortal.class);

    if (portal != null) {
      final IPath themesPath = portal.getAppServerPortalDir().append("html/themes");
      final List<IPath> restorePaths = new ArrayList<IPath>();

      for (int i = 0; i < IPluginProjectDataModelProperties.THEME_PARENTS.length; i++) {
        if (IPluginProjectDataModelProperties.THEME_PARENTS[i].equals(themeParent)) {
          restorePaths.add(themesPath.append(IPluginProjectDataModelProperties.THEME_PARENTS[i]));
        } else {
          if (restorePaths.size() > 0) {
            restorePaths.add(themesPath.append(IPluginProjectDataModelProperties.THEME_PARENTS[i]));
          }
        }
      }

      new Job("publish theme delta") // $NON-NLS-1$
      {
        @Override
        protected IStatus run(IProgressMonitor monitor) {
          buildHelper.publishDelta(delta, path, restorePaths.toArray(new IPath[0]), monitor);

          try {
            docroot.refreshLocal(IResource.DEPTH_INFINITE, monitor);
          } catch (Exception e) {
            ThemeCore.logError(e);
          }

          return Status.OK_STATUS;
        }
      }.schedule();
    }
  }
Exemplo n.º 21
0
  protected void incrementalBuild(IResourceDelta delta, IProgressMonitor monitor) {
    int deltaKind = delta.getKind();

    if (deltaKind == IResourceDelta.REMOVED || deltaKind == IResourceDelta.REMOVED_PHANTOM) {
      return;
    }

    final boolean[] buildCSS = new boolean[1];

    try {
      delta.accept(
          new IResourceDeltaVisitor() {

            private IFolder docroot = null;

            public boolean visit(IResourceDelta delta) {
              IPath fullResourcePath = delta.getResource().getFullPath();

              for (String segment : fullResourcePath.segments()) {
                if ("_diffs".equals(segment)) {
                  if (docroot == null) {
                    docroot = CoreUtil.getDocroot(getProject());
                  }

                  IFolder diffs = docroot.getFolder("_diffs");

                  if (diffs.exists() && diffs.getFullPath().isPrefixOf(fullResourcePath)) {
                    buildCSS[0] = true;

                    return false;
                  }
                }
              }

              return true; // visit children too
            }
          });
    } catch (CoreException e) {
      e.printStackTrace();
    }

    if (buildCSS[0]) {
      try {
        cssBuild(getProject());
      } catch (CoreException e) {
        ThemeCore.logError("Error in Theme CSS Builder", e);
      }
    }
  }
Exemplo n.º 22
0
  /**
   * 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;
  }
Exemplo n.º 23
0
  public boolean visit(IResourceDelta delta) {
    IResource res = delta.getResource();

    if (res != null && res instanceof IFile && delta.getKind() == IResourceDelta.CHANGED) {

      IFile file = (IFile) res;
      if (PatternRegistry.getInstance().getFiles().contains(file)) {
        RuntimeMatcherRegistrator registrator = new RuntimeMatcherRegistrator((IFile) file);
        injector.injectMembers(registrator);
        Display.getDefault().syncExec(registrator);
      }
      return false;
    }
    return true;
  }
Exemplo n.º 24
0
 private boolean hasStructuralDelta() {
   // handle case when currentProject has only .class file folders and/or jar files... no
   // source/output folders
   IResourceDelta delta = getDelta(this.currentProject);
   if (delta != null && delta.getKind() != IResourceDelta.NO_CHANGE) {
     ClasspathLocation[] classFoldersAndJars =
         (ClasspathLocation[]) this.binaryLocationsPerProject.get(this.currentProject);
     if (classFoldersAndJars != null) {
       for (int i = 0, l = classFoldersAndJars.length; i < l; i++) {
         ClasspathLocation classFolderOrJar =
             classFoldersAndJars[i]; // either a .class file folder or a zip/jar file
         if (classFolderOrJar != null) {
           IPath p = classFolderOrJar.getProjectRelativePath();
           if (p != null) {
             IResourceDelta binaryDelta = delta.findMember(p);
             if (binaryDelta != null && binaryDelta.getKind() != IResourceDelta.NO_CHANGE)
               return true;
           }
         }
       }
     }
   }
   return false;
 }
 /**
  * Record the change and return whether any child changes should be visited.
  *
  * @param delta the change
  * @return whether any child changes should be visited
  */
 public boolean recordChange(IResourceDelta delta) {
   switch (delta.getKind()) {
     case IResourceDelta.ADDED:
       handleAdded(delta);
       return true; // Need to traverse children to look  for moves or other changes under added
       // roots
     case IResourceDelta.REMOVED:
       handleRemoved(delta);
       // No need to look for further changes under a remove (such as moves).
       // Changes will be discovered in corresponding destination delta
       return false;
     case IResourceDelta.CHANGED:
       handleChange(delta);
       return true;
   }
   return true;
 }
Exemplo n.º 26
0
  /**
   * This will use the internal builders to traverse the delta. Note that the resource is always a
   * valid python file and is also always located in the pythonpath.
   */
  @Override
  protected void onVisitDelta(IResourceDelta delta) {
    // Note: removals happen now, additions and changes happen later (so that renames are
    // properly treated).

    switch (delta.getKind()) {
      case IResourceDelta.ADDED:
      case IResourceDelta.CHANGED:
        delayedVisits.add(delta);
        break;
      case IResourceDelta.REMOVED:
        IResource resource = delta.getResource();
        memo.put(PyDevBuilderVisitor.DOCUMENT_TIME, System.currentTimeMillis());
        visitRemovedResource(resource, null, monitor);
        break;
    }
  }
    /**
     * 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;
  }
 /**
  * Overridden to detect a support image change in the workspace.
  *
  * <p>{@inheritDoc}
  */
 public boolean visit(IResourceDelta delta) throws CoreException {
   boolean continueToVisit = true;
   boolean isWorkspaceImageChange = false;
   IResource resource = delta.getResource();
   if (isWorkspaceImage(resource)) {
     switch (delta.getKind()) {
       case IResourceDelta.ADDED:
         isWorkspaceImageChange = true;
         break;
       case IResourceDelta.CHANGED:
       case IResourceDelta.REMOVED:
         isWorkspaceImageChange = needClearCache(delta.getResource());
         break;
       default:
         break;
     }
     workspaceImageChangeDetected = workspaceImageChangeDetected || isWorkspaceImageChange;
     continueToVisit = !workspaceImageChangeDetected;
   }
   return continueToVisit;
 }
 /**
  * Returns a string representation of this delta's structure suitable for debug purposes.
  *
  * @see #toString()
  */
 public String toDebugString(int depth) {
   StringBuffer buffer = new StringBuffer();
   for (int i = 0; i < depth; i++) {
     buffer.append('\t');
   }
   buffer.append(((JavaElement) getElement()).toDebugString());
   toDebugString(buffer);
   IJavaScriptElementDelta[] children = getAffectedChildren();
   if (children != null) {
     for (int i = 0; i < children.length; ++i) {
       buffer.append("\n"); // $NON-NLS-1$
       buffer.append(((JavaElementDelta) children[i]).toDebugString(depth + 1));
     }
   }
   for (int i = 0; i < resourceDeltasCounter; i++) {
     buffer.append("\n"); // $NON-NLS-1$
     for (int j = 0; j < depth + 1; j++) {
       buffer.append('\t');
     }
     IResourceDelta resourceDelta = resourceDeltas[i];
     buffer.append(resourceDelta.toString());
     buffer.append("["); // $NON-NLS-1$
     switch (resourceDelta.getKind()) {
       case IResourceDelta.ADDED:
         buffer.append('+');
         break;
       case IResourceDelta.REMOVED:
         buffer.append('-');
         break;
       case IResourceDelta.CHANGED:
         buffer.append('*');
         break;
       default:
         buffer.append('?');
         break;
     }
     buffer.append("]"); // $NON-NLS-1$
   }
   return buffer.toString();
 }