コード例 #1
0
  private void informUserModal(CompletionProposalComputerDescriptor descriptor, IStatus status) {
    String title = DartTextMessages.CompletionProposalComputerRegistry_error_dialog_title;
    CompletionProposalCategory category = descriptor.getCategory();
    IContributor culprit = descriptor.getContributor();
    Set affectedPlugins = getAffectedContributors(category, culprit);

    final String avoidHint;
    final String culpritName = culprit == null ? null : culprit.getName();
    if (affectedPlugins.isEmpty()) {
      avoidHint =
          Messages.format(
              DartTextMessages.CompletionProposalComputerRegistry_messageAvoidanceHint,
              new Object[] {culpritName, category.getDisplayName()});
    } else {
      avoidHint =
          Messages.format(
              DartTextMessages.CompletionProposalComputerRegistry_messageAvoidanceHintWithWarning,
              new Object[] {culpritName, category.getDisplayName(), toString(affectedPlugins)});
    }

    String message = status.getMessage();
    // inlined from MessageDialog.openError
    MessageDialog dialog =
        new MessageDialog(
            DartToolsPlugin.getActiveWorkbenchShell(),
            title,
            null /* default image */,
            message,
            MessageDialog.ERROR,
            new String[] {IDialogConstants.OK_LABEL},
            0) {
          @Override
          protected Control createCustomArea(Composite parent) {
            Link link = new Link(parent, SWT.NONE);
            link.setText(avoidHint);
            link.addSelectionListener(
                new SelectionAdapter() {
                  @Override
                  public void widgetSelected(SelectionEvent e) {
                    PreferencesUtil.createPreferenceDialogOn(
                            getShell(),
                            "com.google.dart.tools.ui.internal.preferences.CodeAssistPreferenceAdvanced",
                            null,
                            null)
                        .open(); //$NON-NLS-1$
                  }
                });
            GridData gridData = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
            gridData.widthHint = this.getMinimumMessageWidth();
            link.setLayoutData(gridData);
            return link;
          }
        };
    dialog.open();
  }
コード例 #2
0
 @Override
 public String getLabel() {
   String label =
       DartElementLabels.getTextLabel(
           fElement, DartElementLabels.ALL_DEFAULT | DartElementLabels.ALL_FULLY_QUALIFIED);
   return Messages.format(DartUIMessages.JavaUIHelp_link_label, label);
 }
コード例 #3
0
ファイル: CleanUpRegistry.java プロジェクト: hyamamoto/dart
 public CleanUpInitializerDescriptor(IConfigurationElement element) {
   fElement = element;
   String kind = fElement.getAttribute(ATTRIBUTE_NAME_KIND);
   fKind = getCleanUpKind(kind);
   if (fKind == -1) {
     DartToolsPlugin.logErrorMessage(
         Messages.format(
             FixMessages.CleanUpRegistry_UnknownInitializerKind_errorMessage,
             new String[] {element.getContributor().getName(), kind}));
   }
 }
コード例 #4
0
ファイル: CleanUpRegistry.java プロジェクト: hyamamoto/dart
 /** @param element the configuration element */
 public CleanUpTabPageDescriptor(IConfigurationElement element) {
   fElement = element;
   fName = element.getAttribute(ATTRIBUTE_ID_NAME);
   String kind = fElement.getAttribute(ATTRIBUTE_NAME_KIND);
   fKind = getCleanUpKind(kind);
   if (fKind == -1) {
     DartToolsPlugin.logErrorMessage(
         Messages.format(
             FixMessages.CleanUpRegistry_WrongKindForConfigurationUI_error,
             new String[] {fName, element.getContributor().getName(), kind}));
   }
 }
コード例 #5
0
 /**
  * Appends to modifier string of the given SWT modifier bit to the given modifierString.
  *
  * @param modifierString the modifier string
  * @param modifier an int with SWT modifier bit
  * @return the concatenated modifier string
  */
 private static String appendModifierString(String modifierString, int modifier) {
   if (modifierString == null) {
     modifierString = ""; // $NON-NLS-1$
   }
   String newModifierString = Action.findModifierString(modifier);
   if (modifierString.length() == 0) {
     return newModifierString;
   }
   return Messages.format(
       DartEditorMessages.EditorUtility_concatModifierStrings,
       new String[] {modifierString, newModifierString});
 }
コード例 #6
0
  private List getCategories(List elements) {
    IPreferenceStore store = DartToolsPlugin.getDefault().getPreferenceStore();
    String preference = store.getString(PreferenceConstants.CODEASSIST_EXCLUDED_CATEGORIES);
    Set disabled = new HashSet();
    StringTokenizer tok = new StringTokenizer(preference, "\0"); // $NON-NLS-1$
    while (tok.hasMoreTokens()) {
      disabled.add(tok.nextToken());
    }
    Map ordered = new HashMap();
    preference = store.getString(PreferenceConstants.CODEASSIST_CATEGORY_ORDER);
    tok = new StringTokenizer(preference, "\0"); // $NON-NLS-1$
    while (tok.hasMoreTokens()) {
      StringTokenizer inner = new StringTokenizer(tok.nextToken(), ":"); // $NON-NLS-1$
      String id = inner.nextToken();
      int rank = Integer.parseInt(inner.nextToken());
      ordered.put(id, new Integer(rank));
    }

    List categories = new ArrayList();
    for (Iterator iter = elements.iterator(); iter.hasNext(); ) {
      IConfigurationElement element = (IConfigurationElement) iter.next();
      try {
        if (element.getName().equals("proposalCategory")) { // $NON-NLS-1$
          iter.remove(); // remove from list to leave only computers

          CompletionProposalCategory category = new CompletionProposalCategory(element, this);
          categories.add(category);
          category.setIncluded(!disabled.contains(category.getId()));
          Integer rank = (Integer) ordered.get(category.getId());
          if (rank != null) {
            int r = rank.intValue();
            boolean separate = r < 0xffff;
            category.setSeparateCommand(separate);
            category.setSortOrder(r);
          }
        }
      } catch (InvalidRegistryObjectException x) {
        /*
         * Element is not valid any longer as the contributing plug-in was unloaded or for some
         * other reason. Do not include the extension in the list and inform the user about it.
         */
        Object[] args = {element.toString()};
        String message =
            Messages.format(
                DartTextMessages.CompletionProposalComputerRegistry_invalid_message, args);
        IStatus status =
            new Status(IStatus.WARNING, DartToolsPlugin.getPluginId(), IStatus.OK, message, x);
        informUser(status);
      }
    }
    return categories;
  }
コード例 #7
0
ファイル: CleanUpRegistry.java プロジェクト: hyamamoto/dart
 /** @return the clean up or <code>null</code> if the clean up could not be instantiated */
 public ICleanUp createCleanUp() {
   try {
     return (ICleanUp) fElement.createExecutableExtension(ATTRIBUTE_ID_CLASS);
   } catch (CoreException e) {
     String msg =
         Messages.format(
             FixMessages.CleanUpRegistry_cleanUpCreation_error,
             new String[] {
               fElement.getAttribute(ATTRIBUTE_ID_ID), fElement.getContributor().getName()
             });
     DartToolsPlugin.logErrorStatus(msg, e.getStatus());
     return null;
   }
 }
コード例 #8
0
ファイル: CleanUpRegistry.java プロジェクト: hyamamoto/dart
    @Override
    public Composite createContents(Composite parent) {
      Composite result = new Composite(parent, SWT.NONE);
      result.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
      result.setLayout(new GridLayout(1, false));

      Text text = new Text(result, SWT.MULTI | SWT.BORDER | SWT.READ_ONLY);
      text.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
      text.setText(
          Messages.format(
              FixMessages.CleanUpRegistry_ErrorTabPage_description,
              fException.getLocalizedMessage()));

      return result;
    }
コード例 #9
0
  private synchronized void ensureSortersRead() {
    if (fSorters != null) {
      return;
    }

    Map<String, ProposalSorterHandle> sorters = new LinkedHashMap<String, ProposalSorterHandle>();
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    List<IConfigurationElement> elements =
        new ArrayList<IConfigurationElement>(
            Arrays.asList(
                registry.getConfigurationElementsFor(
                    DartToolsPlugin.getPluginId(), EXTENSION_POINT)));

    for (Iterator<IConfigurationElement> iter = elements.iterator(); iter.hasNext(); ) {
      IConfigurationElement element = iter.next();

      try {

        ProposalSorterHandle handle = new ProposalSorterHandle(element);
        final String id = handle.getId();
        sorters.put(id, handle);
        if (DEFAULT_ID.equals(id)) {
          fDefaultSorter = handle;
        }

      } catch (InvalidRegistryObjectException x) {
        /*
         * Element is not valid any longer as the contributing plug-in was unloaded or for some
         * other reason. Do not include the extension in the list and inform the user about it.
         */
        Object[] args = {element.toString()};
        String message =
            Messages.format(
                DartTextMessages.CompletionProposalComputerRegistry_invalid_message, args);
        IStatus status =
            new Status(IStatus.WARNING, DartToolsPlugin.getPluginId(), IStatus.OK, message, x);
        informUser(status);
      }
    }

    fSorters = sorters;
  }
コード例 #10
0
  /**
   * Reloads the extensions to the extension point.
   *
   * <p>This method can be called more than once in order to reload from a changed extension
   * registry.
   */
  public void reload() {
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    List elements =
        new ArrayList(
            Arrays.asList(
                registry.getConfigurationElementsFor(
                    DartToolsPlugin.getPluginId(), EXTENSION_POINT)));

    Map map = new HashMap();
    List all = new ArrayList();

    List categories = getCategories(elements);
    for (Iterator iter = elements.iterator(); iter.hasNext(); ) {
      IConfigurationElement element = (IConfigurationElement) iter.next();
      try {
        CompletionProposalComputerDescriptor desc =
            new CompletionProposalComputerDescriptor(element, this, categories);
        Set partitions = desc.getPartitions();
        for (Iterator it = partitions.iterator(); it.hasNext(); ) {
          String partition = (String) it.next();
          List list = (List) map.get(partition);
          if (list == null) {
            list = new ArrayList();
            map.put(partition, list);
          }
          list.add(desc);
        }
        all.add(desc);

      } catch (InvalidRegistryObjectException x) {
        /*
         * Element is not valid any longer as the contributing plug-in was unloaded or for some
         * other reason. Do not include the extension in the list and inform the user about it.
         */
        Object[] args = {element.toString()};
        String message =
            Messages.format(
                DartTextMessages.CompletionProposalComputerRegistry_invalid_message, args);
        IStatus status =
            new Status(IStatus.WARNING, DartToolsPlugin.getPluginId(), IStatus.OK, message, x);
        informUser(status);
      }
    }

    synchronized (this) {
      fCategories.clear();
      fCategories.addAll(categories);

      Set partitions = map.keySet();
      fDescriptorsByPartition.keySet().retainAll(partitions);
      fPublicDescriptorsByPartition.keySet().retainAll(partitions);
      for (Iterator it = partitions.iterator(); it.hasNext(); ) {
        String partition = (String) it.next();
        List old = (List) fDescriptorsByPartition.get(partition);
        List current = (List) map.get(partition);
        if (old != null) {
          old.clear();
          old.addAll(current);
        } else {
          fDescriptorsByPartition.put(partition, current);
          fPublicDescriptorsByPartition.put(partition, Collections.unmodifiableList(current));
        }
      }

      fDescriptors.clear();
      fDescriptors.addAll(all);
    }
  }
コード例 #11
0
  @Override
  public IStatus run(IProgressMonitor monitor) {
    final DartSearchResult textResult = (DartSearchResult) getSearchResult();
    textResult.removeAll();
    SearchEngine engine = SearchEngineFactory.createSearchEngine();

    //  try {
    //  int totalTicks= 1000;
    // TODO (pquitslund): add search participant support
    //  IProject[] projects=
    // JavaSearchScopeFactory.getInstance().getProjects(fPatternData.getScope());
    //  final SearchParticipantRecord[] participantDescriptors=
    // SearchParticipantsExtensionPoint.getInstance().getSearchParticipants(projects);
    //  final int[] ticks= new int[participantDescriptors.length];
    //  for (int i= 0; i < participantDescriptors.length; i++) {
    //    final int iPrime= i;
    //    ISafeRunnable runnable= new ISafeRunnable() {
    //      public void handleException(Throwable exception) {
    //        ticks[iPrime]= 0;
    //        String message= SearchMessages.JavaSearchQuery_error_participant_estimate;
    //        DartToolsPlugin.log(new Status(IStatus.ERROR, DartToolsPlugin.getPluginId(), 0,
    // message, exception));
    //      }
    //
    //      public void run() throws Exception {
    //        ticks[iPrime]=
    // participantDescriptors[iPrime].getParticipant().estimateTicks(fPatternData);
    //      }
    //    };
    //
    //    SafeRunner.run(runnable);
    //    totalTicks+= ticks[i];
    //  }

    SearchResultCollector collector = new SearchResultCollector(textResult);
    SearchScope scope = patternData.getScope();

    if (patternData.hasElement()) {
      DartElement element = ((ElementQuerySpecification) patternData).getElement();
      if (!element.exists()) {
        String patternString =
            DartElementLabels.getElementLabel(element, DartElementLabels.ALL_DEFAULT);
        return new Status(
            IStatus.ERROR,
            DartToolsPlugin.getPluginId(),
            0,
            Messages.format(
                SearchMessages.DartSearchQuery_error_element_does_not_exist, patternString),
            null);
      }

      try {
        if (patternData.isReferencesSearch()) {
          searchForReferences(engine, element, scope, null, collector, monitor);
        }
        if (patternData.isDeclarationsSearch()) {
          searchForDeclarations(engine, element, scope, null, collector, monitor);
        }
        if (patternData.isOverridesSearch()) {
          searchForOverrides(engine, element, scope, null, collector, monitor);
        }
      } catch (SearchException e) {
        DartToolsPlugin.log(e);
        // TODO: do we need to update the UI as well? Or schedule another search?
      } catch (CoreException ex) {
        DartToolsPlugin.log(ex);
      }

    } else if (patternData.hasNode()) {

      DartNode node = ((NodeQuerySpecification) patternData).getNode();
      if (node instanceof DartIdentifier) {
        DartIdentifier id = (DartIdentifier) node;

        try {
          if (patternData.isReferencesSearch()) {
            searchForReferences(engine, id, scope, null, collector, monitor);
          }
          if (patternData.isDeclarationsSearch()) {
            searchForDeclarations(engine, id, scope, null, collector, monitor);
          }
        } catch (SearchException e) {
          DartToolsPlugin.log(e);
        } catch (CoreException ex) {
          DartToolsPlugin.log(ex);
        }
      }
    }

    //      engine.search(pattern, new SearchParticipant[] {
    // SearchEngine.getDefaultSearchParticipant() }, fPatternData.getScope(), collector,
    // mainSearchPM);
    // TODO (pquitslund): add search participant support
    //      for (int i= 0; i < participantDescriptors.length; i++) {
    //        final ISearchRequestor requestor= new
    // SearchRequestor(participantDescriptors[i].getParticipant(), textResult);
    //        final IProgressMonitor participantPM= new SubProgressMonitor(monitor, ticks[i]);
    //
    //        final int iPrime= i;
    //        ISafeRunnable runnable= new ISafeRunnable() {
    //          public void handleException(Throwable exception) {
    //            participantDescriptors[iPrime].getDescriptor().disable();
    //            String message= SearchMessages.JavaSearchQuery_error_participant_search;
    //            DartToolsPlugin.log(new Status(IStatus.ERROR, DartToolsPlugin.getPluginId(), 0,
    // message, exception));
    //          }
    //
    //          public void run() throws Exception {
    //
    //            final IQueryParticipant participant=
    // participantDescriptors[iPrime].getParticipant();
    //            final PerformanceStats stats= PerformanceStats.getStats(PERF_SEARCH_PARTICIPANT,
    // participant);
    //            stats.startRun();
    //
    //            participant.search(requestor, fPatternData, participantPM);
    //
    //            stats.endRun();
    //          }
    //        };

    //        SafeRunner.run(runnable);
    //      }

    //    } catch (CoreException e) {
    //      return e.getStatus();
    //    }

    String message =
        Messages.format(
            SearchMessages.DartSearchQuery_status_ok_message,
            String.valueOf(textResult.getMatchCount()));
    return new Status(IStatus.OK, DartToolsPlugin.getPluginId(), 0, message, null);
  }