Java Code Examples for com.intellij.util.ArrayUtil#find()

The following examples show how to use com.intellij.util.ArrayUtil#find() . 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: GotoTargetHandler.java    From consulo with Apache License 2.0 6 votes vote down vote up
public boolean addTarget(final PsiElement element) {
  if (ArrayUtil.find(targets, element) > -1) return false;
  targets = ArrayUtil.append(targets, element);
  renderers.put(element, createRenderer(this, element));
  if (!hasDifferentNames && element instanceof PsiNamedElement) {
    final String name = ApplicationManager.getApplication().runReadAction(new Computable<String>() {
      @Override
      public String compute() {
        return ((PsiNamedElement)element).getName();
      }
    });
    myNames.add(name);
    hasDifferentNames = myNames.size() > 1;
  }
  return true;
}
 
Example 2
Source File: CSharpStubVariableImplUtil.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nullable
private static DotNetVariable getPrevVariable(@Nonnull CSharpStubVariableImpl<?> variable)
{
	if(isMultipleDeclaration(variable))
	{
		CSharpVariableDeclStub<?> stub = variable.getStub();
		if(stub != null)
		{
			StubElement<?> parentStub = stub.getParentStub();
			PsiElement[] stubVariables = parentStub.getChildrenByType(variable.getElementType(), PsiElement.ARRAY_FACTORY);

			int i = ArrayUtil.find(stubVariables, variable);
			if(i <= 0)
			{
				LOGGER.error("Variable dont have type but dont second");
				return null;
			}

			return (DotNetVariable) stubVariables[i - 1];
		}
		else
		{
			CSharpStubVariableImpl<?> prevVariable = PsiTreeUtil.getPrevSiblingOfType(variable, variable.getClass());
			if(prevVariable == null)
			{
				LOGGER.error("Variable dont have type but dont second");
				return null;
			}
			return prevVariable;
		}
	}
	return null;
}
 
Example 3
Source File: CSharpGenericParameterImpl.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
public int getIndex()
{
	PsiElement parentByStub = getParentByStub();
	if(parentByStub instanceof DotNetGenericParameterList)
	{
		return ArrayUtil.find(((DotNetGenericParameterList) parentByStub).getParameters(), this);
	}
	return -1;
}
 
Example 4
Source File: PsiAnnotationSearchUtil.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nullable
private static PsiAnnotation findAnnotationQuick(@Nullable PsiAnnotationOwner annotationOwner, @NotNull String... qualifiedNames) {
  if (annotationOwner == null || qualifiedNames.length == 0) {
    return null;
  }

  PsiAnnotation[] annotations = annotationOwner.getAnnotations();
  if (annotations.length == 0) {
    return null;
  }

  final String[] shortNames = new String[qualifiedNames.length];
  for (int i = 0; i < qualifiedNames.length; i++) {
    shortNames[i] = StringUtil.getShortName(qualifiedNames[i]);
  }

  for (PsiAnnotation annotation : annotations) {
    final PsiJavaCodeReferenceElement referenceElement = annotation.getNameReferenceElement();
    if (null != referenceElement) {
      final String referenceName = referenceElement.getReferenceName();
      if (ArrayUtil.find(shortNames, referenceName) > -1) {

        if (referenceElement.isQualified() && referenceElement instanceof SourceJavaCodeReference) {
          final String possibleFullQualifiedName = ((SourceJavaCodeReference) referenceElement).getClassNameText();

          if (ArrayUtil.find(qualifiedNames, possibleFullQualifiedName) > -1) {
            return annotation;
          }
        }

        final String annotationQualifiedName = getAndCacheFQN(annotation, referenceName);
        if (ArrayUtil.find(qualifiedNames, annotationQualifiedName) > -1) {
          return annotation;
        }
      }
    }
  }

  return null;
}
 
Example 5
Source File: AnalysisScope.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static Set<Module> getDirectBackwardDependencies(@Nonnull Module module, @Nonnull Module[] allModules) {
  Set<Module> result = new HashSet<Module>();
  for (Module dependency : allModules) {
    if (ArrayUtil.find(ModuleRootManager.getInstance(dependency).getDependencies(), module) > -1) {
      result.add(dependency);
    }
  }
  return result;
}
 
Example 6
Source File: GuiUtils.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void iterateChildren(Component container, Consumer<Component> consumer, JComponent... excludeComponents) {
  if (excludeComponents != null && ArrayUtil.find(excludeComponents, container) != -1) return;
  consumer.consume(container);
  if (container instanceof Container) {
    final Component[] components = ((Container)container).getComponents();
    for (Component child : components) {
      iterateChildren(child, consumer, excludeComponents);
    }
  }
}
 
Example 7
Source File: DesktopEditorWithProviderComposite.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public HistoryEntry currentStateAsHistoryEntry() {
  final FileEditor[] editors = getEditors();
  final FileEditorState[] states = new FileEditorState[editors.length];
  for (int j = 0; j < states.length; j++) {
    states[j] = editors[j].getState(FileEditorStateLevel.FULL);
    LOG.assertTrue(states[j] != null);
  }
  final int selectedProviderIndex = ArrayUtil.find(editors, getSelectedEditor());
  LOG.assertTrue(selectedProviderIndex != -1);
  final FileEditorProvider[] providers = getProviders();
  return HistoryEntry.createLight(getFile(), providers, states, providers[selectedProviderIndex]);
}
 
Example 8
Source File: TabNavigationActionBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void navigateImpl(final DataContext dataContext, Project project, VirtualFile selectedFile, final int dir) {
  LOG.assertTrue(dir == 1 || dir == -1);
  final FileEditorManagerEx editorManager = FileEditorManagerEx.getInstanceEx(project);
  EditorWindow currentWindow = dataContext.getData(EditorWindow.DATA_KEY);
  if (currentWindow == null) {
    currentWindow = editorManager.getCurrentWindow();
  }
  final VirtualFile[] files = currentWindow.getFiles();
  int index = ArrayUtil.find(files, selectedFile);
  LOG.assertTrue(index != -1);
  editorManager.openFile(files[(index + files.length + dir) % files.length], true);
}
 
Example 9
Source File: PluginTable.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void select(PluginDescriptor... descriptors) {
  PluginTableModel tableModel = (PluginTableModel)getModel();
  getSelectionModel().clearSelection();
  for (int i = 0; i < tableModel.getRowCount(); i++) {
    PluginDescriptor descriptorAt = tableModel.getObjectAt(i);
    if (ArrayUtil.find(descriptors, descriptorAt) != -1) {
      final int row = convertRowIndexToView(i);
      getSelectionModel().addSelectionInterval(row, row);
    }
  }
  TableUtil.scrollSelectionToVisible(this);
}
 
Example 10
Source File: OpenedInEditorWeigher.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Comparable weigh(@Nonnull final PsiElement element, @Nonnull final ProximityLocation location) {
  if (location.getProject() == null){
    return null;
  }
  final PsiFile psiFile = element.getContainingFile();
  if (psiFile == null) return false;

  final VirtualFile virtualFile = psiFile.getOriginalFile().getVirtualFile();
  return virtualFile != null && ArrayUtil.find(OPENED_EDITORS.getValue(location), virtualFile) != -1;
}
 
Example 11
Source File: DirectoryChooser.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
@RequiredReadAction
private static PsiDirectory getDefaultSelection(PsiDirectory[] directories, Project project) {
  final String defaultSelectionPath = PropertiesComponent.getInstance(project).getValue(DEFAULT_SELECTION);
  if (defaultSelectionPath != null) {
    final VirtualFile directoryByDefault = LocalFileSystem.getInstance().findFileByPath(defaultSelectionPath);
    if (directoryByDefault != null) {
      final PsiDirectory directory = PsiManager.getInstance(project).findDirectory(directoryByDefault);
      return directory != null && ArrayUtil.find(directories, directory) > -1 ? directory : null;
    }
  }
  return null;
}
 
Example 12
Source File: DnDEventImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
public boolean isDataFlavorSupported(DataFlavor flavor) {
  DataFlavor[] flavors = getTransferDataFlavors();
  return ArrayUtil.find(flavors, flavor) != -1;
}