private Map promptForOverwrite(List plugins, List locales) {
    Map overwrites = new HashMap();

    if (overwriteWithoutAsking) return overwrites;

    for (Iterator iter = plugins.iterator(); iter.hasNext(); ) {
      IPluginModelBase plugin = (IPluginModelBase) iter.next();
      for (Iterator it = locales.iterator(); it.hasNext(); ) {
        Locale locale = (Locale) it.next();
        IProject project = getNLProject(plugin, locale);

        if (project.exists() && !overwrites.containsKey(project.getName())) {
          boolean overwrite =
              MessageDialog.openConfirm(
                  PDEPlugin.getActiveWorkbenchShell(),
                  PDEUIMessages.InternationalizeWizard_NLSFragmentGenerator_overwriteTitle,
                  NLS.bind(
                      PDEUIMessages.InternationalizeWizard_NLSFragmentGenerator_overwriteMessage,
                      pluginName(plugin, locale)));
          overwrites.put(project.getName(), overwrite ? OVERWRITE : null);
        }
      }
    }

    return overwrites;
  }
  public void addSelectedFilesToTargetList() {
    ISelection selection = sourceFileViewer.getSelection();

    if (isValidSourceFileViewerSelection(selection)) {
      java.util.List list = null;
      if (selection instanceof IStructuredSelection) {
        list = ((IStructuredSelection) selection).toList();

        if (list != null) {
          list = ((IStructuredSelection) selection).toList();
          for (Iterator i = list.iterator(); i.hasNext(); ) {
            IResource resource = (IResource) i.next();
            if (resource instanceof IFile) {
              // Check if its in the list. Don't add it if it is.
              String resourceName = resource.getFullPath().toString();
              if (selectedListBox.indexOf(resourceName) == -1) selectedListBox.add(resourceName);
            }
          }
          setFiles(selectedListBox.getItems());
        }

        setAddButtonEnabled(false);

        if (selectedListBox.getItemCount() > 0) {
          removeAllButton.setEnabled(true);
          if (isFileMandatory) setPageComplete(true);
          if (selectedListBox.getSelectionCount() > 0) setRemoveButtonEnabled(true);
          else setRemoveButtonEnabled(false);
        }
      }
    }
  }
예제 #3
0
 public static IMarker[] getProblemsFor(IResource resource) {
   try {
     if (resource != null && resource.exists()) {
       IMarker[] markers =
           resource.findMarkers(
               IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_INFINITE);
       Set markerTypes =
           JavaModelManager.getJavaModelManager().compilationParticipants.managedMarkerTypes();
       if (markerTypes.isEmpty()) return markers;
       ArrayList markerList = new ArrayList(5);
       for (int i = 0, length = markers.length; i < length; i++) {
         markerList.add(markers[i]);
       }
       Iterator iterator = markerTypes.iterator();
       while (iterator.hasNext()) {
         markers = resource.findMarkers((String) iterator.next(), false, IResource.DEPTH_INFINITE);
         for (int i = 0, length = markers.length; i < length; i++) {
           markerList.add(markers[i]);
         }
       }
       IMarker[] result;
       markerList.toArray(result = new IMarker[markerList.size()]);
       return result;
     }
   } catch (CoreException e) {
     // assume there are no problems
   }
   return new IMarker[0];
 }
 private void ensureResourceCovered(IResource resource, List list) {
   IPath path = resource.getFullPath();
   for (Iterator iter = list.iterator(); iter.hasNext(); ) {
     IResource root = (IResource) iter.next();
     if (root.getFullPath().isPrefixOf(path)) {
       return;
     }
   }
   list.add(resource);
 }
 public void setVisible(boolean visible) {
   if (visible == true) {
     if (fFilters != null) {
       sourceFileViewer.resetFilters();
       for (Iterator i = fFilters.iterator(); i.hasNext(); )
         sourceFileViewer.addFilter((ViewerFilter) i.next());
     }
     sourceFileViewer.setInput(ResourcesPlugin.getWorkspace().getRoot());
   }
   super.setVisible(visible);
 }
 /* (non-Javadoc)
  * @see org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector#dispose()
  */
 public synchronized void dispose() {
   Iterator iterator = fSourceContainerMap.values().iterator();
   while (iterator.hasNext()) {
     ISourceContainer[] containers = (ISourceContainer[]) iterator.next();
     for (int i = 0; i < containers.length; i++) {
       containers[i].dispose();
     }
   }
   fSourceContainerMap.clear();
   super.dispose();
 }
 /**
  * @param element
  * @param schemaElement
  */
 private void validateMaxElementMult(Element element, ISchemaElement schemaElement) {
   // Validate max element occurence violations
   int maxSeverity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_ELEMENT);
   if (maxSeverity != CompilerFlags.IGNORE) {
     HashSet maxElementSet =
         ElementOccurenceChecker.findMaxOccurenceViolations(schemaElement, element);
     Iterator maxIterator = maxElementSet.iterator();
     while (maxIterator.hasNext()) {
       reportMaxOccurenceViolation((ElementOccurrenceResult) maxIterator.next(), maxSeverity);
     }
   }
 }
    public boolean include(Object object) {
      if (object instanceof IResource) {
        IResource resource = (IResource) object;
        IPath path =
            IResource.FILE == resource.getType()
                ? resource.getFullPath()
                : resource.getFullPath().addTrailingSeparator();
        object = path.toPortableString();
      }

      for (Iterator iter = filters.iterator(); iter.hasNext(); ) {
        Filter filter = (Filter) iter.next();
        if (filter.matches(object)) {
          return filter.inclusive();
        }
      }
      return default_;
    }
예제 #9
0
  public static void removeProblemsFor(IResource resource) {
    try {
      if (resource != null && resource.exists()) {
        resource.deleteMarkers(
            IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_INFINITE);

        // delete managed markers
        Set markerTypes =
            JavaModelManager.getJavaModelManager().compilationParticipants.managedMarkerTypes();
        if (markerTypes.size() == 0) return;
        Iterator iterator = markerTypes.iterator();
        while (iterator.hasNext())
          resource.deleteMarkers((String) iterator.next(), false, IResource.DEPTH_INFINITE);
      }
    } catch (CoreException e) {
      // assume there were no problems
    }
  }
예제 #10
0
 /**
  * Return a list of nature ids based on the natures that have been configured for this project.
  *
  * @return list of configured nature ids.
  * @param project
  */
 public static List getRegisteredRuntimeIDs(IProject project) {
   List result = null;
   String natureID = null;
   if (project != null && project.isAccessible()) {
     Iterator it = EMFNatureRegistry.singleton().REGISTERED_NATURE_IDS.iterator();
     while (it.hasNext()) {
       natureID = (String) it.next();
       try {
         if (project.hasNature(natureID)) {
           if (result == null) result = new ArrayList(2);
           result.add(natureID);
         }
       } catch (CoreException e) {
       }
     }
   }
   return result == null ? Collections.EMPTY_LIST : result;
 }
예제 #11
0
  private Map<IFile, Program> collectReferencingFiles(IFile sourceFile, IProgressMonitor pm) {
    ISourceModule sourceModule = DLTKCore.createSourceModuleFrom(sourceFile);

    Map<IFile, Program> participantFiles = new HashMap<IFile, Program>();

    Collection<Node> references = MoveUtils.getReferencingFiles(sourceModule);
    if (references != null) {
      for (Iterator<Node> it = references.iterator(); it.hasNext(); ) {
        Node node = it.next();
        IFile file = (IFile) node.getFile().getResource();
        try {
          participantFiles.put(file, RefactoringUtility.getProgramForFile(file));
        } catch (Exception e) {
        }
      }
    }

    return participantFiles;
  }
  /**
   * Creates an NL fragment project along with the locale specific properties files.
   *
   * @throws CoreException
   * @throws IOException
   * @throws InvocationTargetException
   * @throws InterruptedException
   */
  private void internationalizePlugins(List plugins, List locales, Map overwrites)
      throws CoreException, IOException, InvocationTargetException, InterruptedException {

    Set created = new HashSet();

    for (Iterator it = plugins.iterator(); it.hasNext(); ) {
      IPluginModelBase plugin = (IPluginModelBase) it.next();

      for (Iterator iter = locales.iterator(); iter.hasNext(); ) {
        Locale locale = (Locale) iter.next();

        IProject project = getNLProject(plugin, locale);
        if (created.contains(project)
            || overwriteWithoutAsking
            || !project.exists()
            || OVERWRITE == overwrites.get(project.getName())) {
          if (!created.contains(project) && project.exists()) {
            project.delete(true, getProgressMonitor());
          }

          if (!created.contains(project)) {
            createNLFragment(plugin, project, locale);
            created.add(project);
            project.getFolder(RESOURCE_FOLDER_PARENT).create(false, true, getProgressMonitor());
          }

          project
              .getFolder(RESOURCE_FOLDER_PARENT)
              .getFolder(locale.toString())
              .create(true, true, getProgressMonitor());
          createLocaleSpecificPropertiesFile(project, plugin, locale);
        }
      }
    }
  }
 /** Renames the main type in <code>cu</code>. */
 private void updateTypeName(
     ICompilationUnit cu,
     CompilationUnit astCU,
     String oldName,
     String newName,
     ASTRewrite rewriter)
     throws JavaModelException {
   if (newName != null) {
     String oldTypeName = Util.getNameWithoutJavaLikeExtension(oldName);
     String newTypeName = Util.getNameWithoutJavaLikeExtension(newName);
     AST ast = astCU.getAST();
     // update main type name
     IType[] types = cu.getTypes();
     for (int i = 0, max = types.length; i < max; i++) {
       IType currentType = types[i];
       if (currentType.getElementName().equals(oldTypeName)) {
         AbstractTypeDeclaration typeNode =
             (AbstractTypeDeclaration) ((JavaElement) currentType).findNode(astCU);
         if (typeNode != null) {
           // rename type
           rewriter.replace(typeNode.getName(), ast.newSimpleName(newTypeName), null);
           // rename constructors
           Iterator bodyDeclarations = typeNode.bodyDeclarations().iterator();
           while (bodyDeclarations.hasNext()) {
             Object bodyDeclaration = bodyDeclarations.next();
             if (bodyDeclaration instanceof MethodDeclaration) {
               MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration;
               if (methodDeclaration.isConstructor()) {
                 SimpleName methodName = methodDeclaration.getName();
                 if (methodName.getIdentifier().equals(oldTypeName)) {
                   rewriter.replace(methodName, ast.newSimpleName(newTypeName), null);
                 }
               }
             }
           }
         }
       }
     }
   }
 }
예제 #14
0
 /*
  * Instruct the build manager that this project is involved in a cycle and
  * needs to propagate structural changes to the other projects in the cycle.
  */
 void mustPropagateStructuralChanges() {
   LinkedHashSet cycleParticipants = new LinkedHashSet(3);
   this.javaProject.updateCycleParticipants(
       new ArrayList(), cycleParticipants, this.workspaceRoot, new HashSet(3), null);
   IPath currentPath = this.javaProject.getPath();
   Iterator i = cycleParticipants.iterator();
   while (i.hasNext()) {
     IPath participantPath = (IPath) i.next();
     if (participantPath != currentPath) {
       IProject project = this.workspaceRoot.getProject(participantPath.segment(0));
       if (hasBeenBuilt(project)) {
         if (DEBUG)
           System.out.println(
               "JavaBuilder: Requesting another build iteration since cycle participant "
                   + project.getName() // $NON-NLS-1$
                   + " has not yet seen some structural changes"); //$NON-NLS-1$
         needRebuild();
         return;
       }
     }
   }
 }
 /** Process all of the changed deltas generated by this operation. */
 protected void processDeltas() {
   for (Iterator deltas = this.deltasPerProject.values().iterator(); deltas.hasNext(); ) {
     addDelta((IJavaElementDelta) deltas.next());
   }
 }
예제 #16
0
  /**
   * Creates the text changes for all the affected files. Updates all the include statements in the
   * current file and all the includes in the "including " files. In case of folders, creates the
   * changes recursively
   *
   * @param pm - progress monitor
   * @param rootChange - the root change that the new changes are added to
   * @param sourceResources
   * @return the root change after the additions
   * @throws CoreException
   */
  private Change createTextChanges(
      IProgressMonitor pm,
      CompositeChange rootChange,
      Set<IFile> phpFiles,
      IResource[] sourceResources)
      throws CoreException {
    List<ProgramFileChange> changes = new ArrayList<ProgramFileChange>();
    try {
      pm.beginTask(PhpRefactoringCoreMessages.getString("MoveDelegate.1"), 100); // $NON-NLS-1$

      // creat text changes:
      // for each file that will be moved, update its includes
      // and update all the files that include it,

      IResource[] uniqueSourceResources = removeDuplicateResources(sourceResources);

      for (Iterator<IFile> it = phpFiles.iterator(); it.hasNext(); ) {
        IFile currentMovedResource = it.next();

        Map<IFile, Program> participantFiles = collectReferencingFiles(currentMovedResource, pm);

        for (Entry<IFile, Program> entry : participantFiles.entrySet()) {
          final IFile file = entry.getKey();
          if (phpFiles.contains(file)) {
            continue;
          }
          final Program program = entry.getValue();

          final ChangeIncludePath rename =
              new ChangeIncludePath(
                  currentMovedResource, file, fMainDestinationPath, false, uniqueSourceResources);
          // aggregate the changes identifiers
          program.accept(rename);

          if (pm.isCanceled()) throw new OperationCanceledException();

          pm.worked(1);

          if (rename.hasChanges()) {
            ProgramFileChange change = new ProgramFileChange(file.getName(), file, program);
            change.setEdit(new MultiTextEdit());
            change.setTextType("php"); // $NON-NLS-1$

            changes.add(change);
            rename.updateChange(change);
          }
        }

        ISourceModule sourceModule = DLTKCore.createSourceModuleFrom(currentMovedResource);

        if (sourceModule instanceof ISourceModule) {

          Program program = null;
          try {
            program = ASTUtils.createProgramFromSource(sourceModule);
          } catch (Exception e) {
          }

          if (program != null) {
            final ChangeIncludePath rename =
                new ChangeIncludePath(
                    currentMovedResource,
                    currentMovedResource,
                    fMainDestinationPath,
                    true,
                    uniqueSourceResources);

            // aggregate the changes identifiers
            program.accept(rename);

            if (pm.isCanceled()) throw new OperationCanceledException();

            pm.worked(1);

            if (rename.hasChanges()) {
              ProgramFileChange change =
                  new ProgramFileChange(
                      currentMovedResource.getName(), currentMovedResource, program);
              change.setEdit(new MultiTextEdit());
              change.setTextType("php"); // $NON-NLS-1$

              changes.add(change);
              rename.updateChange(change);
            }
          }
        }
      }
      pm.worked(70);

    } finally {
      pm.done();
    } // getChildren()

    Map<IFile, List<TextEdit>> changeMap = new HashMap<IFile, List<TextEdit>>();
    Map<IFile, ProgramFileChange> fileMap = new HashMap<IFile, ProgramFileChange>();
    for (ProgramFileChange programFileChange : changes) {
      List<TextEdit> list = changeMap.get(programFileChange.getFile());
      if (list == null) {
        list = new ArrayList<TextEdit>();
        changeMap.put(programFileChange.getFile(), list);
        fileMap.put(programFileChange.getFile(), programFileChange);
      } else {

      }
      list.addAll(Arrays.asList(programFileChange.getEdit().getChildren()));
    }
    for (IFile file : changeMap.keySet()) {
      ProgramFileChange change =
          new ProgramFileChange(file.getName(), file, fileMap.get(file).getProgram());
      change.setEdit(new MultiTextEdit());
      change.setTextType("php"); // $NON-NLS-1$

      List<TextEdit> list = changeMap.get(file);
      Collections.sort(
          list,
          new Comparator<TextEdit>() {
            public int compare(TextEdit o1, TextEdit o2) {
              return o2.getOffset() - o1.getOffset();
            }
          });

      for (TextEdit textEdit : list) {
        if (textEdit instanceof ReplaceEdit) {
          ReplaceEdit replaceEdit = (ReplaceEdit) textEdit;
          change.addEdit(
              new ReplaceEdit(
                  replaceEdit.getOffset(), replaceEdit.getLength(), replaceEdit.getText()));
        }
      }
      rootChange.add(change);
    }
    return rootChange;
  }
예제 #17
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);
     }
   }
 }