Java Code Examples for com.intellij.openapi.extensions.Extensions

The following examples show how to use com.intellij.openapi.extensions.Extensions. These examples are extracted from open source projects. 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 Project: consulo   Source File: TemplateState.java    License: 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 Project: consulo   Source File: ProjectViewImpl.java    License: Apache License 2.0 6 votes vote down vote up
private void ensurePanesLoaded() {
  if (myExtensionsLoaded) return;
  myExtensionsLoaded = true;
  AbstractProjectViewPane[] extensions = Extensions.getExtensions(AbstractProjectViewPane.EP_NAME, myProject);
  Arrays.sort(extensions, PANE_WEIGHT_COMPARATOR);
  for (AbstractProjectViewPane pane : extensions) {
    if (myUninitializedPaneState.containsKey(pane.getId())) {
      try {
        pane.readExternal(myUninitializedPaneState.get(pane.getId()));
      }
      catch (InvalidDataException e) {
        // ignore
      }
      myUninitializedPaneState.remove(pane.getId());
    }
    if (pane.isInitiallyVisible() && !myId2Pane.containsKey(pane.getId())) {
      addProjectPane(pane);
    }
  }
}
 
Example 3
Source Project: buck   Source File: BuckClientTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testConnectDisconnect() {
  Extensions.registerAreaClass("IDEA_PROJECT", null);
  MockDisposable mockDisposable = new MockDisposable();

  MockApplication application = new MockApplicationEx(mockDisposable);
  ApplicationManager.setApplication(application, mockDisposable);

  Project project = new MockProjectEx(new MockDisposable());

  TestBuckEventHandler handler = new TestBuckEventHandler();
  BuckSocket buckSocket = new BuckSocket(handler);
  BuckClientManager.getOrCreateClient(project, handler).setBuckSocket(buckSocket);

  BuckClientManager.getOrCreateClient(project, handler).connect();
  buckSocket.onConnect(new MockSession());

  BuckClientManager.getOrCreateClient(project, handler).disconnectWithoutRetry();
  buckSocket.onClose(0, "FOO");

  assertFalse(BuckClientManager.getOrCreateClient(project, handler).isConnected());
}
 
Example 4
Source Project: consulo   Source File: ElementPreviewHintProvider.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
private static LightweightHint getHint(@Nonnull PsiElement element) {
  for (PreviewHintProvider hintProvider : Extensions.getExtensions(PreviewHintProvider.EP_NAME)) {
    JComponent preview;
    try {
      preview = hintProvider.getPreviewComponent(element);
    }
    catch (Exception e) {
      LOG.error(e);
      continue;
    }
    if (preview != null) {
      return new LightweightHint(preview);
    }
  }
  return null;
}
 
Example 5
Source Project: consulo   Source File: RenameInputValidatorRegistry.java    License: Apache License 2.0 6 votes vote down vote up
@javax.annotation.Nullable
public static Function<String, String> getInputErrorValidator(final PsiElement element) {
  for(final RenameInputValidator validator: Extensions.getExtensions(RenameInputValidator.EP_NAME)) {
    if (!(validator instanceof RenameInputValidatorEx)) continue;
    final ProcessingContext context = new ProcessingContext();
    if (validator.getPattern().accepts(element, context)) {
      return new Function<String, String>() {
        @Override
        public String fun(String newName) {
          return ((RenameInputValidatorEx)validator).getErrorMessage(newName, element.getProject());
        }
      };
    }
  }
  return null;
}
 
Example 6
Source Project: buck   Source File: BuckClientTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void hasBuckDisconnectedThenWeReconnectIfSoSpecified() {
  Extensions.registerAreaClass("IDEA_PROJECT", null);
  MockDisposable mockDisposable = new MockDisposable();

  MockApplication application = new MockApplicationEx(mockDisposable);
  ApplicationManager.setApplication(application, mockDisposable);

  Project project = new MockProjectEx(new MockDisposable());

  TestBuckEventHandler handler = new TestBuckEventHandler();
  BuckSocket buckSocket = new BuckSocket(handler);
  BuckClientManager.getOrCreateClient(project, handler).setBuckSocket(buckSocket);

  BuckClientManager.getOrCreateClient(project, handler).connect();
  buckSocket.onConnect(new MockSession());

  BuckClientManager.getOrCreateClient(project, handler).disconnectWithRetry();
  buckSocket.onClose(0, "FOO");
  buckSocket.onConnect(new MockSession());

  assertTrue(BuckClientManager.getOrCreateClient(project, handler).isConnected());
}
 
Example 7
Source Project: consulo   Source File: InlineRefactoringActionHandler.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void invoke(@Nonnull Project project, @Nonnull PsiElement[] elements, DataContext dataContext) {
  LOG.assertTrue(elements.length == 1);
  if (dataContext == null) {
    dataContext = DataManager.getInstance().getDataContext();
  }
  final Editor editor = dataContext.getData(PlatformDataKeys.EDITOR);
  for(InlineActionHandler handler: Extensions.getExtensions(InlineActionHandler.EP_NAME)) {
    if (handler.canInlineElement(elements[0])) {
      handler.inlineElement(project, editor, elements [0]);
      return;
    }
  }

  invokeInliner(editor, elements[0]);
}
 
Example 8
private void assertNavigationMatch(ElementPattern<?> pattern) {

        PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());

        Set<String> targetStrings = 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) {
                continue;
            }

            for (PsiElement gotoDeclarationTarget : gotoDeclarationTargets) {
                targetStrings.add(gotoDeclarationTarget.toString());
                if(pattern.accepts(gotoDeclarationTarget)) {
                    return;
                }
            }
        }

        fail(String.format("failed that PsiElement (%s) navigate matches one of %s", psiElement.toString(), targetStrings.toString()));
    }
 
Example 9
Source Project: SVNToolBox   Source File: SvnToolBoxApp.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void initComponent() {
    myExecutor = Executors.newCachedThreadPool(
            new ThreadFactoryBuilder()
                    .setDaemon(true)
                    .setNameFormat(getComponentName()+"-pool-%s")
                    .setPriority(Thread.NORM_PRIORITY)
                    .build()
    );
    myScheduledExecutor = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder()
            .setDaemon(true)
            .setNameFormat(getComponentName() + "-scheduled-pool-%s")
            .setPriority(Thread.NORM_PRIORITY)
            .build()
    );
    List<NodeDecorationEP> nodeDecorationEPs = Arrays.asList(Extensions.getExtensions(NodeDecorationEP.POINT_NAME));
    Collections.sort(nodeDecorationEPs);
    for (NodeDecorationEP decorationEP : nodeDecorationEPs) {
        NodeDecoration decoration = decorationEP.instantiate();
        myNodeDecorations.add(decoration);
      LOG.debug("Added decoration ", decorationEP.priority, " ", decoration);
    }
}
 
Example 10
public void testNoopMetrics() throws Throwable {
  class NoopMetricsListener extends EmptyMetricsTestListener {

    private boolean lastWasNoop;

    @Override
    public void logIsPantsNoopCompile(boolean isNoop) throws Throwable {
      lastWasNoop = isNoop;
    }
  }

  NoopMetricsListener listener = new NoopMetricsListener();
  Extensions.getRootArea().getExtensionPoint(PantsExternalMetricsListener.EP_NAME).registerExtension(listener);

  doImport("examples/tests/scala/org/pantsbuild/example/hello/welcome");
  // The first compile has to execute.
  assertPantsCompileExecutesAndSucceeds(pantsCompileProject());
  assertFalse("Last compile should not be noop, it was.", listener.lastWasNoop);

  // Second compile without any change should be lastWasNoop.
  assertPantsCompileNoop(pantsCompileProject());
  assertTrue("Last compile should be noop, but was not.", listener.lastWasNoop);
}
 
Example 11
private void assertNavigationMatch(ElementPattern<?> pattern) {

        PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());

        Set<String> targetStrings = 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) {
                continue;
            }

            for (PsiElement gotoDeclarationTarget : gotoDeclarationTargets) {
                targetStrings.add(gotoDeclarationTarget.toString());
                if(pattern.accepts(gotoDeclarationTarget)) {
                    return;
                }
            }
        }

        fail(String.format("failed that PsiElement (%s) navigate matches one of %s", psiElement.toString(), targetStrings.toString()));
    }
 
Example 12
Source Project: consulo   Source File: InlineRefactoringActionHandler.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void invoke(@Nonnull final Project project, Editor editor, PsiFile file, DataContext dataContext) {
  editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);

  PsiElement element = dataContext.getData(LangDataKeys.PSI_ELEMENT);
  if (element == null) {
    element = BaseRefactoringAction.getElementAtCaret(editor, file);
  }
  if (element != null) {
    for(InlineActionHandler handler: Extensions.getExtensions(InlineActionHandler.EP_NAME)) {
      if (handler.canInlineElementInEditor(element, editor)) {
        handler.inlineElement(project, editor, element);
        return;
      }
    }

    if (invokeInliner(editor, element)) return;

    String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("error.wrong.caret.position.method.or.local.name"));
    CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, null);
  }
}
 
Example 13
private void assertNavigationMatch(ElementPattern<?> pattern) {

        PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());

        Set<String> targetStrings = 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) {
                continue;
            }

            for (PsiElement gotoDeclarationTarget : gotoDeclarationTargets) {
                targetStrings.add(gotoDeclarationTarget.toString());
                if(pattern.accepts(gotoDeclarationTarget)) {
                    return;
                }
            }
        }

        fail(String.format("failed that PsiElement (%s) navigate matches one of %s", psiElement.toString(), targetStrings.toString()));
    }
 
Example 14
Source Project: consulo   Source File: FileTemplateManagerImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public String internalTemplateToSubject(@Nonnull @NonNls String templateName) {
  //noinspection HardCodedStringLiteral
  for (InternalTemplateBean bean : Extensions.getExtensions(InternalTemplateBean.EP_NAME)) {
    if (bean.name.equals(templateName) && bean.subject != null) {
      return bean.subject;
    }
  }
  return templateName.toLowerCase();
}
 
Example 15
Source Project: consulo   Source File: FindUsagesManager.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
public FindUsagesHandler getFindUsagesHandler(@Nonnull PsiElement element, final boolean forHighlightUsages) {
  for (FindUsagesHandlerFactory factory : Extensions.getExtensions(FindUsagesHandlerFactory.EP_NAME, myProject)) {
    if (factory.canFindUsages(element)) {
      final FindUsagesHandler handler = factory.createFindUsagesHandler(element, forHighlightUsages);
      if (handler == FindUsagesHandler.NULL_HANDLER) return null;
      if (handler != null) {
        return handler;
      }
    }
  }
  return null;
}
 
Example 16
Source Project: consulo   Source File: StructureViewFactoryImpl.java    License: 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 17
Source Project: consulo   Source File: ScopeEditorPanel.java    License: Apache License 2.0 5 votes vote down vote up
private JComponent createTreeToolbar() {
  final DefaultActionGroup group = new DefaultActionGroup();
  final Runnable update = new Runnable() {
    @Override
    public void run() {
      rebuild(true);
    }
  };
  group.add(new FlattenPackagesAction(update));
  final PatternDialectProvider[] dialectProviders = Extensions.getExtensions(PatternDialectProvider.EP_NAME);
  for (PatternDialectProvider provider : dialectProviders) {
    for (AnAction action : provider.createActions(myProject, update)) {
      group.add(action);
    }
  }
  group.add(new ShowFilesAction(update));
  final Module[] modules = ModuleManager.getInstance(myProject).getModules();
  if (modules.length > 1) {
    group.add(new ShowModulesAction(update));
    group.add(new ShowModuleGroupsAction(update));
  }
  group.add(new FilterLegalsAction(update));

  if (dialectProviders.length > 1) {
    group.add(new ChooseScopeTypeAction(update));
  }

  ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, true);
  return toolbar.getComponent();
}
 
Example 18
Source Project: consulo   Source File: ExportToHTMLManager.java    License: Apache License 2.0 5 votes vote down vote up
private static boolean exportPsiFile(final PsiFile psiFile, final String outputDirectoryName, final Project project, final HashMap<PsiFile,
        PsiFile> filesMap) {
  try {
    return ApplicationManager.getApplication().runReadAction(new ThrowableComputable<Boolean, FileNotFoundException>() {
      @Override
      public Boolean compute() throws FileNotFoundException {
        ExportToHTMLSettings exportToHTMLSettings = ExportToHTMLSettings.getInstance(project);

        if (psiFile instanceof PsiBinaryFile) {
          return true;
        }

        TreeMap<Integer, PsiReference> refMap = null;
        for (PrintOption printOption : Extensions.getExtensions(PrintOption.EP_NAME)) {
          final TreeMap<Integer, PsiReference> map = printOption.collectReferences(psiFile, filesMap);
          if (map != null) {
            refMap = new TreeMap<Integer, PsiReference>();
            refMap.putAll(map);
          }
        }

        String dirName = constructOutputDirectory(psiFile, outputDirectoryName);
        HTMLTextPainter textPainter = new HTMLTextPainter(psiFile, project, dirName, exportToHTMLSettings.PRINT_LINE_NUMBERS);
        textPainter.paint(refMap, psiFile.getFileType());
        return true;
      }
    });
  }
  catch (FileNotFoundException throwable) {
    myLastException = throwable;
    return true;
  }
}
 
Example 19
Source Project: consulo   Source File: GeneralColorsPage.java    License: Apache License 2.0 5 votes vote down vote up
private static String getCustomSeveritiesDemoText() {
  final StringBuilder buff = new StringBuilder();

  for (SeveritiesProvider provider : Extensions.getExtensions(SeveritiesProvider.EP_NAME)) {
    for (HighlightInfoType highlightInfoType : provider.getSeveritiesHighlightInfoTypes()) {
      final String tag = getHighlightDescTagName(highlightInfoType);
      buff.append("  <").append(tag).append(">");
      buff.append(tag.toLowerCase());
      buff.append("</").append(tag).append(">").append("\n");
    }
  }

  return buff.toString();
}
 
Example 20
@BeforeClass
public static void setUp() {
  Disposable disposable = Disposer.newDisposable();
  ApplicationManager.setApplication(new MockApplication(disposable), disposable);
  Extensions.registerAreaClass("IDEA_PROJECT", null);
  ourProject = new MockProject(ApplicationManager.getApplication().getPicoContainer(), disposable);
}
 
Example 21
Source Project: consulo   Source File: ProjectRootManagerComponent.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
private Pair<Set<String>, Set<String>> getAllRoots(boolean includeSourceRoots) {
  if (myProject.isDefault()) return null;

  final Set<String> recursive = new HashSet<String>();
  final Set<String> flat = new HashSet<String>();

  final String projectFilePath = myProject.getProjectFilePath();
  final File projectDirFile = projectFilePath == null ? null : new File(projectFilePath).getParentFile();
  if (projectDirFile != null && projectDirFile.getName().equals(Project.DIRECTORY_STORE_FOLDER)) {
    recursive.add(projectDirFile.getAbsolutePath());
  }
  else {
    flat.add(projectFilePath);
    final VirtualFile workspaceFile = myProject.getWorkspaceFile();
    if (workspaceFile != null) {
      flat.add(workspaceFile.getPath());
    }
  }

  for (WatchedRootsProvider extension : Extensions.getExtensions(WatchedRootsProvider.EP_NAME, myProject)) {
    recursive.addAll(extension.getRootsToWatch());
  }

  addRootsFromModules(includeSourceRoots, recursive, flat);

  return Pair.create(recursive, flat);
}
 
Example 22
Source Project: consulo   Source File: RunConfigurable.java    License: Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public JComponent createComponent() {
  for (RunConfigurationsSettings each : Extensions.getExtensions(RunConfigurationsSettings.EXTENSION_POINT)) {
    UnnamedConfigurable configurable = each.createConfigurable();
    myAdditionalSettings.add(Pair.create(configurable, configurable.createComponent()));
  }

  myWholePanel = new JPanel(new BorderLayout());
  DataManager.registerDataProvider(myWholePanel, new DataProvider() {
    @Nullable
    @Override
    public Object getData(@Nonnull @NonNls Key dataId) {
      return RunConfigurationSelector.KEY == dataId ? new RunConfigurationSelector() {
        @Override
        public void select(@Nonnull RunConfiguration configuration) {
          selectConfiguration(configuration);
        }
      } : null;
    }
  });

  mySplitter.setFirstComponent(createLeftPanel());
  mySplitter.setSecondComponent(myRightPanel);
  myWholePanel.add(mySplitter, BorderLayout.CENTER);

  updateDialog();

  Dimension d = myWholePanel.getPreferredSize();
  d.width = Math.max(d.width, 800);
  d.height = Math.max(d.height, 600);
  myWholePanel.setPreferredSize(d);

  mySplitter.setProportion(myProperties.getFloat(DIVIDER_PROPORTION, 0.3f));

  return myWholePanel;
}
 
Example 23
Source Project: consulo   Source File: NewEditChangelistPanel.java    License: Apache License 2.0 5 votes vote down vote up
public void init(final LocalChangeList initial) {
  myMakeActiveCheckBox.setSelected(VcsConfiguration.getInstance(myProject).MAKE_NEW_CHANGELIST_ACTIVE);
  for (EditChangelistSupport support : Extensions.getExtensions(EditChangelistSupport.EP_NAME, myProject)) {
    support.installSearch(myNameTextField, myDescriptionTextArea);
    myConsumer = support.addControls(myAdditionalControlsPanel, initial);
  }
  myNameTextField.getDocument().addDocumentListener(new DocumentAdapter() {
    @Override
    public void documentChanged(DocumentEvent event) {
      nameChangedImpl(myProject, initial);
    }
  });
  nameChangedImpl(myProject, initial);
}
 
Example 24
Source Project: consulo   Source File: GotoTargetHandler.java    License: Apache License 2.0 5 votes vote down vote up
public static PsiElementListCellRenderer createRenderer(@Nonnull GotoData gotoData, @Nonnull PsiElement eachTarget) {
  PsiElementListCellRenderer renderer = null;
  for (GotoTargetRendererProvider eachProvider : Extensions.getExtensions(GotoTargetRendererProvider.EP_NAME)) {
    renderer = eachProvider.getRenderer(eachTarget, gotoData);
    if (renderer != null) break;
  }
  return renderer;
}
 
Example 25
Source Project: intellij   Source File: CMakeNotificationFilter.java    License: Apache License 2.0 5 votes vote down vote up
public static void overrideProjectExtension(Project project) {
  ExtensionPoint<EditorNotifications.Provider> ep =
      Extensions.getArea(project).getExtensionPoint(EDITOR_NOTIFICATIONS_EPNAME);
  for (EditorNotifications.Provider<?> editorNotificationsProvider : ep.getExtensions()) {
    if (editorNotificationsProvider instanceof CMakeNotificationProvider) {
      ep.unregisterExtension(editorNotificationsProvider);
    }
  }
  ep.registerExtension(new CMakeNotificationFilter(project));
}
 
Example 26
@Override
public void initComponent() {
  ExtensionPoint<GotoRelatedProvider> ep =
      Extensions.getRootArea().getExtensionPoint(GotoRelatedProvider.EP_NAME);
  for (GotoRelatedProvider provider : ep.getExtensions()) {
    if (provider.getClass().equals(OCSwitchToHeaderOrSourceRelatedProvider.class)) {
      ep.unregisterExtension(provider);
    }
  }
}
 
Example 27
Source Project: consulo   Source File: ImageOrColorPreviewManager.java    License: 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 28
Source Project: intellij   Source File: PyImportResolverStrategyTestCase.java    License: Apache License 2.0 5 votes vote down vote up
static AutoImportQuickFix getImportQuickFix(PyElement unresolvedSymbol) {
  PsiReference ref = unresolvedSymbol.getReference();
  assertThat(ref).isNotNull();

  String text = ref.getElement().getText();
  AutoImportQuickFix fix = new AutoImportQuickFix(unresolvedSymbol, ref.getClass(), text, false);
  for (PyImportCandidateProvider provider :
      Extensions.getExtensions(PyImportCandidateProvider.EP_NAME)) {
    provider.addImportCandidates(ref, text, fix);
  }
  fix.sortCandidates();
  return fix;
}
 
Example 29
Source Project: intellij   Source File: BlazeGoPackageTest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void init() {
  Extensions.getRootArea()
      .getExtensionPoint(GoImportResolver.EP_NAME)
      .registerExtension(importResolver, LoadingOrder.FIRST, getTestRootDisposable());

  createGoPackage(
      "foo/bar/foo",
      goFile(
          "foo/bar/foo.go", //
          "package foo",
          "func Foo() {}"),
      goFile( // same package different directory
          "foo/foo.go", //
          "package foo",
          "func Bar() {}"));
  // same directory different package
  createGoPackage(
      "foo/bar/bar",
      goFile(
          "foo/bar/bar.go", //
          "package bar",
          "func Foo() {}"));
  // same directory same package different import path
  createGoPackage(
      "foo/bar/baz",
      goFile(
          "foo/bar/baz.go", //
          "package foo",
          "func Foo() {}"));
}
 
Example 30
Source Project: consulo   Source File: ScopeTreeViewPanel.java    License: Apache License 2.0 5 votes vote down vote up
private void initTree() {
  myTree.setCellRenderer(new MyTreeCellRenderer());
  myTree.setRootVisible(false);
  myTree.setShowsRootHandles(true);
  UIUtil.setLineStyleAngled(myTree);
  TreeUtil.installActions(myTree);
  EditSourceOnDoubleClickHandler.install(myTree);
  new TreeSpeedSearch(myTree);
  myCopyPasteDelegator = new CopyPasteDelegator(myProject, this) {
    @Override
    @Nonnull
    protected PsiElement[] getSelectedElements() {
      return getSelectedPsiElements();
    }
  };
  myTreeExpansionMonitor = PackageTreeExpansionMonitor.install(myTree, myProject);
  final ScopeTreeStructureExpander[] extensions = Extensions.getExtensions(ScopeTreeStructureExpander.EP_NAME, myProject);
  for (ScopeTreeStructureExpander expander : extensions) {
    myTree.addTreeWillExpandListener(expander);
  }
  if (extensions.length == 0) {
    myTree.addTreeWillExpandListener(new SortingExpandListener());
  }
  myTree.addKeyListener(new KeyAdapter() {
    @Override
    public void keyPressed(KeyEvent e) {
      if (KeyEvent.VK_ENTER == e.getKeyCode()) {
        final Object component = myTree.getLastSelectedPathComponent();
        if (component instanceof DefaultMutableTreeNode) {
          final DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)component;
          if (selectedNode.isLeaf()) {
            OpenSourceUtil.openSourcesFrom(DataManager.getInstance().getDataContext(myTree), false);
          }
        }
      }
    }
  });
  CustomizationUtil.installPopupHandler(myTree, IdeActions.GROUP_PROJECT_VIEW_POPUP, ActionPlaces.PROJECT_VIEW_POPUP);
}