Java Code Examples for com.intellij.openapi.extensions.Extensions#getExtensions()

The following examples show how to use com.intellij.openapi.extensions.Extensions#getExtensions() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TemplateState.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void considerNextTabOnLookupItemSelected(LookupElement item) {
  if (item != null) {
    ExpressionContext context = getCurrentExpressionContext();
    for (TemplateCompletionProcessor processor : Extensions.getExtensions(TemplateCompletionProcessor.EP_NAME)) {
      if (!processor.nextTabOnItemSelected(context, item)) {
        return;
      }
    }
  }
  TextRange range = getCurrentVariableRange();
  if (range != null && range.getLength() > 0) {
    int caret = myEditor.getCaretModel().getOffset();
    if (caret == range.getEndOffset() || isCaretInsideNextVariable()) {
      nextTab();
    }
    else if (caret > range.getEndOffset()) {
      gotoEnd(true);
    }
  }
}
 
Example 2
Source File: ColorSettingsUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void addInspectionSeverityAttributes(List<AttributesDescriptor> descriptors) {
  descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.unknown.symbol"), CodeInsightColors.WRONG_REFERENCES_ATTRIBUTES));
  descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.deprecated.symbol"), CodeInsightColors.DEPRECATED_ATTRIBUTES));
  descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.unused.symbol"), CodeInsightColors.NOT_USED_ELEMENT_ATTRIBUTES));
  descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.error"), CodeInsightColors.ERRORS_ATTRIBUTES));
  descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.warning"), CodeInsightColors.WARNINGS_ATTRIBUTES));
  descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.weak.warning"), CodeInsightColors.WEAK_WARNING_ATTRIBUTES));
  descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.server.problems"), CodeInsightColors.GENERIC_SERVER_ERROR_OR_WARNING));
  descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.server.duplicate"), CodeInsightColors.DUPLICATE_FROM_SERVER));

  for (SeveritiesProvider provider : Extensions.getExtensions(SeveritiesProvider.EP_NAME)) {
    for (HighlightInfoType highlightInfoType : provider.getSeveritiesHighlightInfoTypes()) {
      final TextAttributesKey attributesKey = highlightInfoType.getAttributesKey();
      descriptors.add(new AttributesDescriptor(toDisplayName(attributesKey), attributesKey));
    }
  }
}
 
Example 3
Source File: SafeDeleteProcessor.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static SafeDeleteProcessor createInstance(Project project,
                                                 @Nullable Runnable prepareSuccessfulCallBack,
                                                 PsiElement[] elementsToDelete,
                                                 boolean isSearchInComments,
                                                 boolean isSearchNonJava,
                                                 boolean askForAccessors) {
  ArrayList<PsiElement> elements = new ArrayList<PsiElement>(Arrays.asList(elementsToDelete));
  HashSet<PsiElement> elementsToDeleteSet = new HashSet<PsiElement>(Arrays.asList(elementsToDelete));

  for (PsiElement psiElement : elementsToDelete) {
    for (SafeDeleteProcessorDelegate delegate : Extensions.getExtensions(SafeDeleteProcessorDelegate.EP_NAME)) {
      if (delegate.handlesElement(psiElement)) {
        Collection<PsiElement> addedElements = delegate.getAdditionalElementsToDelete(psiElement, elementsToDeleteSet, askForAccessors);
        if (addedElements != null) {
          elements.addAll(addedElements);
        }
        break;
      }
    }
  }

  return new SafeDeleteProcessor(project, prepareSuccessfulCallBack, PsiUtilCore.toPsiElementArray(elements), isSearchInComments, isSearchNonJava);
}
 
Example 4
Source File: AbstractInspectionTestCase.java    From BashSupport with Apache License 2.0 6 votes vote down vote up
/**
 * This method looks at the LocalInspectionTool extension points registered in BashSupport's plugin.xml.
 * The base InspectionTestCase doesn't handle inspections well which are only registered in the plugin.xml and
 * which do not have a seperately overridden displayName implementation.
 *
 * @param folderName
 * @param clazz
 * @param onTheFly
 */
public void doTest(String folderName, Class<? extends LocalInspectionTool> clazz, boolean onTheFly) {
    LocalInspectionEP[] extensions = Extensions.getExtensions(LocalInspectionEP.LOCAL_INSPECTION);
    for (LocalInspectionEP extension : extensions) {
        if (extension.implementationClass.equals(clazz.getCanonicalName())) {
            extension.enabledByDefault = true;

            InspectionProfileEntry instance = extension.instantiateTool();

            super.doTest(folderName, onTheFly ? withOnTheFly((LocalInspectionTool) instance) : (LocalInspectionTool) instance);

            return;
        }
    }

    Assert.fail("Inspection not found for type " + clazz.getName());
}
 
Example 5
Source File: FindUsagesManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public FindUsagesHandler getNewFindUsagesHandler(@Nonnull PsiElement element, final boolean forHighlightUsages) {
  for (FindUsagesHandlerFactory factory : Extensions.getExtensions(FindUsagesHandlerFactory.EP_NAME, myProject)) {
    if (factory.canFindUsages(element)) {
      Class<? extends FindUsagesHandlerFactory> aClass = factory.getClass();
      FindUsagesHandlerFactory copy = myProject.getInjectingContainer().getUnbindedInstance(aClass);
      final FindUsagesHandler handler = copy.createFindUsagesHandler(element, forHighlightUsages);
      if (handler == FindUsagesHandler.NULL_HANDLER) return null;
      if (handler != null) {
        return handler;
      }
    }
  }
  return null;
}
 
Example 6
Source File: ScopeTreeViewPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
  Font font = UIUtil.getTreeFont();
  setFont(font.deriveFont(font.getSize() + JBUI.scale(1f)));

  if (value instanceof PackageDependenciesNode) {
    PackageDependenciesNode node = (PackageDependenciesNode)value;
    try {
      setIcon(node.getIcon());
    }
    catch (IndexNotReadyException ignore) {
    }
    final SimpleTextAttributes regularAttributes = SimpleTextAttributes.REGULAR_ATTRIBUTES;
    TextAttributes textAttributes = regularAttributes.toTextAttributes();
    if (node instanceof BasePsiNode && ((BasePsiNode)node).isDeprecated()) {
      textAttributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.DEPRECATED_ATTRIBUTES).clone();
    }
    final PsiElement psiElement = node.getPsiElement();
    textAttributes.setForegroundColor(CopyPasteManager.getInstance().isCutElement(psiElement) ? CopyPasteManager.CUT_COLOR : node.getColor());
    append(node.toString(), SimpleTextAttributes.fromTextAttributes(textAttributes));

    String oldToString = toString();
    if (!myProject.isDisposed()) {
      for (ProjectViewNodeDecorator decorator : Extensions.getExtensions(ProjectViewNodeDecorator.EP_NAME, myProject)) {
        decorator.decorate(node, this);
      }
    }
    if (toString().equals(oldToString)) {   // nothing was decorated
      final String locationString = node.getComment();
      if (locationString != null && locationString.length() > 0) {
        append(" (" + locationString + ")", SimpleTextAttributes.GRAY_ATTRIBUTES);
      }
    }
  }
}
 
Example 7
Source File: FavoritesTreeNodeDescriptor.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static String getLocation(final AbstractTreeNode element, final Project project) {
  Object nodeElement = element.getValue();
  if (nodeElement instanceof SmartPsiElementPointer) {
    nodeElement = ((SmartPsiElementPointer)nodeElement).getElement();
  }
  if (nodeElement instanceof PsiElement) {
    if (nodeElement instanceof PsiDirectory) {
      return ((PsiDirectory)nodeElement).getVirtualFile().getPresentableUrl();
    }
    if (nodeElement instanceof PsiFile) {
      final PsiFile containingFile = (PsiFile)nodeElement;
      final VirtualFile virtualFile = containingFile.getVirtualFile();
      return virtualFile != null ? virtualFile.getPresentableUrl() : "";
    }
  }

  if (nodeElement instanceof LibraryGroupElement) {
    return ((LibraryGroupElement)nodeElement).getModule().getName();
  }
  if (nodeElement instanceof NamedLibraryElement) {
    final NamedLibraryElement namedLibraryElement = ((NamedLibraryElement)nodeElement);
    final Module module = namedLibraryElement.getModule();
    return (module != null ? module.getName() : "") + ":" + namedLibraryElement.getOrderEntry().getPresentableName();
  }

  final FavoriteNodeProvider[] nodeProviders = Extensions.getExtensions(FavoriteNodeProvider.EP_NAME, project);
  for (FavoriteNodeProvider provider : nodeProviders) {
    String location = provider.getElementLocation(nodeElement);
    if (location != null) return location;
  }
  return null;
}
 
Example 8
Source File: SymfonyLightCodeInsightFixtureTestCase.java    From idea-php-toolbox with MIT License 5 votes vote down vote up
public void assertNavigationContainsFile(LanguageFileType languageFileType, String configureByText, String targetShortcut) {
    myFixture.configureByText(languageFileType, configureByText);
    PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());

    Set<String> targets = new HashSet<>();

    for (GotoDeclarationHandler gotoDeclarationHandler : Extensions.getExtensions(GotoDeclarationHandler.EP_NAME)) {
        PsiElement[] gotoDeclarationTargets = gotoDeclarationHandler.getGotoDeclarationTargets(psiElement, 0, myFixture.getEditor());
        if (gotoDeclarationTargets != null && gotoDeclarationTargets.length > 0) {
            for (PsiElement gotoDeclarationTarget : gotoDeclarationTargets) {
                if(gotoDeclarationTarget instanceof PsiFile) {
                    targets.add(((PsiFile) gotoDeclarationTarget).getVirtualFile().getUrl());
                }
            }
        }
    }

    // its possible to have memory fields,
    // so simple check for ending conditions
    // temp:///src/interchange.en.xlf
    for (String target : targets) {
        if(target.endsWith(targetShortcut)) {
            return;
        }
    }

    fail(String.format("failed that PsiElement (%s) navigate to file %s", psiElement.toString(), targetShortcut));
}
 
Example 9
Source File: ImageOrColorPreviewManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void mouseMoved(@Nonnull EditorMouseEvent event) {
  Editor editor = event.getEditor();
  if (editor.isOneLineMode()) {
    return;
  }

  alarm.cancelAllRequests();
  Point point = event.getMouseEvent().getPoint();
  if (myElements == null && event.getMouseEvent().isShiftDown()) {
    alarm.addRequest(new PreviewRequest(point, editor, false), 100);
  }
  else {
    Collection<PsiElement> elements = myElements;
    if (!getPsiElementsAt(point, editor).equals(elements)) {
      myElements = null;
      for (ElementPreviewProvider provider : Extensions.getExtensions(ElementPreviewProvider.EP_NAME)) {
        try {
          if (elements != null) {
            for (PsiElement element : elements) {
              provider.hide(element, editor);
            }
          } else {
            provider.hide(null, editor);
          }
        }
        catch (Exception e) {
          LOG.error(e);
        }
      }
    }
  }
}
 
Example 10
Source File: PsiElementRenameHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static boolean isVetoed(PsiElement element) {
  if (element == null || element instanceof SyntheticElement) return true;
  for (Condition<PsiElement> condition : Extensions.getExtensions(VETO_RENAME_CONDITION_EP)) {
    if (condition.value(element)) return true;
  }
  return false;
}
 
Example 11
Source File: ElementPreviewHintProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isSupportedFile(@Nonnull PsiFile psiFile) {
  for (PreviewHintProvider hintProvider : Extensions.getExtensions(PreviewHintProvider.EP_NAME)) {
    if (hintProvider.isSupportedFile(psiFile)) {
      return true;
    }
  }
  return false;
}
 
Example 12
Source File: StructureViewFactoryImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
protected MultiValuesMap<Class<? extends PsiElement>, StructureViewExtension> compute() {
  MultiValuesMap<Class<? extends PsiElement>, StructureViewExtension> map =
    new MultiValuesMap<Class<? extends PsiElement>, StructureViewExtension>();
  StructureViewExtension[] extensions = Extensions.getExtensions(StructureViewExtension.EXTENSION_POINT_NAME);
  for (StructureViewExtension extension : extensions) {
    map.put(extension.getType(), extension);
  }
  return map;
}
 
Example 13
Source File: DrupalLightCodeInsightFixtureTestCase.java    From idea-php-drupal-symfony2-bridge with MIT License 5 votes vote down vote up
public void assertNavigationContainsFile(LanguageFileType languageFileType, String configureByText, String targetShortcut) {
    myFixture.configureByText(languageFileType, configureByText);
    PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());

    Set<String> targets = new HashSet<String>();

    for (GotoDeclarationHandler gotoDeclarationHandler : Extensions.getExtensions(GotoDeclarationHandler.EP_NAME)) {
        PsiElement[] gotoDeclarationTargets = gotoDeclarationHandler.getGotoDeclarationTargets(psiElement, 0, myFixture.getEditor());
        if (gotoDeclarationTargets != null && gotoDeclarationTargets.length > 0) {
            for (PsiElement gotoDeclarationTarget : gotoDeclarationTargets) {
                if(gotoDeclarationTarget instanceof PsiFile) {
                    targets.add(((PsiFile) gotoDeclarationTarget).getVirtualFile().getUrl());
                }
            }
        }
    }

    // its possible to have memory fields,
    // so simple check for ending conditions
    // temp:///src/interchange.en.xlf
    for (String target : targets) {
        if(target.endsWith(targetShortcut)) {
            return;
        }
    }

    fail(String.format("failed that PsiElement (%s) navigate to file %s", psiElement.toString(), targetShortcut));
}
 
Example 14
Source File: MyLookupExpression.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static LookupElement[] initLookupItems(LinkedHashSet<String> names,
                                               PsiNamedElement elementToRename, 
                                               PsiElement nameSuggestionContext,
                                               final boolean shouldSelectAll) {
  if (names == null) {
    names = new LinkedHashSet<String>();
    for (NameSuggestionProvider provider : Extensions.getExtensions(NameSuggestionProvider.EP_NAME)) {
      final SuggestedNameInfo suggestedNameInfo = provider.getSuggestedNames(elementToRename, nameSuggestionContext, names);
      if (suggestedNameInfo != null &&
          provider instanceof PreferrableNameSuggestionProvider &&
          !((PreferrableNameSuggestionProvider)provider).shouldCheckOthers()) {
        break;
      }
    }
  }
  final LookupElement[] lookupElements = new LookupElement[names.size()];
  final Iterator<String> iterator = names.iterator();
  for (int i = 0; i < lookupElements.length; i++) {
    final String suggestion = iterator.next();
    lookupElements[i] = LookupElementBuilder.create(suggestion).withInsertHandler(new InsertHandler<LookupElement>() {
      @Override
      public void handleInsert(InsertionContext context, LookupElement item) {
        if (shouldSelectAll) return;
        final Editor topLevelEditor = InjectedLanguageUtil.getTopLevelEditor(context.getEditor());
        final TemplateState templateState = TemplateManagerImpl.getTemplateState(topLevelEditor);
        if (templateState != null) {
          final TextRange range = templateState.getCurrentVariableRange();
          if (range != null) {
            topLevelEditor.getDocument().replaceString(range.getStartOffset(), range.getEndOffset(), suggestion);
          }
        }
      }
    });
  }
  return lookupElements;
}
 
Example 15
Source File: UnresolvedReferenceQuickFixProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static <T extends PsiReference> void registerReferenceFixes(T ref, QuickFixActionRegistrar registrar) {

    final boolean dumb = DumbService.getInstance(ref.getElement().getProject()).isDumb();
    UnresolvedReferenceQuickFixProvider[] fixProviders = Extensions.getExtensions(EXTENSION_NAME);
    Class<? extends PsiReference> referenceClass = ref.getClass();
    for (UnresolvedReferenceQuickFixProvider each : fixProviders) {
      if (dumb && !DumbService.isDumbAware(each)) {
        continue;
      }
      if (ReflectionUtil.isAssignable(each.getReferenceClass(), referenceClass)) {
        each.registerFixes(ref, registrar);
      }
    }
  }
 
Example 16
Source File: LanguageCodeStyleSettingsProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static Language[] getLanguagesWithCodeStyleSettings() {
  final ArrayList<Language> languages = new ArrayList<>();
  for (LanguageCodeStyleSettingsProvider provider : Extensions.getExtensions(EP_NAME)) {
    languages.add(provider.getLanguage());
  }
  return languages.toArray(new Language[0]);
}
 
Example 17
Source File: MoveHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static boolean canMove(DataContext dataContext) {
   for(MoveHandlerDelegate delegate: Extensions.getExtensions(MoveHandlerDelegate.EP_NAME)) {
    if (delegate.canMove(dataContext)) return true;
  }

  return false;
}
 
Example 18
Source File: CoverageOptionsConfigurable.java    From consulo with Apache License 2.0 4 votes vote down vote up
private CoverageOptions[] getExtensions() {
  return Extensions.getExtensions(CoverageOptions.EP_NAME, myProject);
}
 
Example 19
Source File: PatternDialectProvider.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static PatternDialectProvider getInstance(String shortName) {
  for (PatternDialectProvider provider : Extensions.getExtensions(EP_NAME)) {
    if (Comparing.strEqual(provider.getShortName(), shortName)) return provider;
  }
  return null; //todo replace with File
}
 
Example 20
Source File: MoveHandler.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static boolean isMoveRedundant(PsiElement source, PsiElement target) {
  for(MoveHandlerDelegate delegate: Extensions.getExtensions(MoveHandlerDelegate.EP_NAME)) {
    if (delegate.isMoveRedundant(source, target)) return true;
  }
  return false;
}