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

The following examples show how to use com.intellij.util.ArrayUtil#indexOf() . 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: InjectedLanguageManagerImpl.java    From consulo with Apache License 2.0 7 votes vote down vote up
@TestOnly
public static void checkInjectorsAreDisposed(@Nullable Project project) {
  InjectedLanguageManagerImpl cachedManager = project == null ? null : (InjectedLanguageManagerImpl)project.getUserData(INSTANCE_CACHE);
  if (cachedManager == null) return;

  try {
    ClassMapCachingNulls<MultiHostInjector> cached = cachedManager.cachedInjectors;
    if (cached == null) return;
    for (Map.Entry<Class<?>, MultiHostInjector[]> entry : cached.getBackingMap().entrySet()) {
      Class<?> key = entry.getKey();
      if (cachedManager.myInjectorsClone.isEmpty()) return;
      MultiHostInjector[] oldInjectors = cachedManager.myInjectorsClone.get(key);
      for (MultiHostInjector injector : entry.getValue()) {
        if (ArrayUtil.indexOf(oldInjectors, injector) == -1) {
          throw new AssertionError("Injector was not disposed: " + key + " -> " + injector);
        }
      }
    }
  }
  finally {
    cachedManager.myInjectorsClone.clear();
  }
}
 
Example 2
Source File: MyDeviceChooser.java    From ADBWIFI with Apache License 2.0 6 votes vote down vote up
private void refreshTable() {
  IDevice[] devices = myDetectedDevicesRef.get();
  myDisplayedDevices = devices;

  final IDevice[] selectedDevices = getSelectedDevices();
  final TIntArrayList selectedRows = new TIntArrayList();
  for (int i = 0; i < devices.length; i++) {
    if (ArrayUtil.indexOf(selectedDevices, devices[i]) >= 0) {
      selectedRows.add(i);
    }
  }

  myProcessSelectionFlag = false;
  myDeviceTable.setModel(new MyDeviceTableModel(devices));
  if (selectedRows.size() == 0 && devices.length > 0) {
    myDeviceTable.getSelectionModel().setSelectionInterval(0, 0);
  }
  for (int selectedRow : selectedRows.toNativeArray()) {
    if (selectedRow < devices.length) {
      myDeviceTable.getSelectionModel().addSelectionInterval(selectedRow, selectedRow);
    }
  }
  fireSelectedDevicesChanged();
  myProcessSelectionFlag = true;
  updatePreviouslySelectedSerials();
}
 
Example 3
Source File: CS1722.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Override
public void invoke(@Nonnull Project project, Editor editor, PsiFile file) throws IncorrectOperationException
{
	DotNetType element = myTypePointer.getElement();
	if(element == null)
	{
		return;
	}

	DotNetTypeList parent = (DotNetTypeList) element.getParent();

	DotNetType[] types = parent.getTypes();

	int i = ArrayUtil.indexOf(types, element);
	if(i <= 0)
	{
		return;
	}
	DotNetType elementAtZeroPosition = types[0];

	PsiElement baseElementCopy = element.copy();
	PsiElement elementAtZeroCopy = elementAtZeroPosition.copy();

	elementAtZeroPosition.replace(baseElementCopy);
	element.replace(elementAtZeroCopy);
}
 
Example 4
Source File: CS1737.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
@Nullable
@Override
public HighlightInfoFactory checkImpl(@Nonnull CSharpLanguageVersion languageVersion, @Nonnull CSharpHighlightContext highlightContext, @Nonnull DotNetParameter dotNetParameter)
{
	if(dotNetParameter.getInitializer() == null)
	{
		return null;
	}

	DotNetParameterList parent = (DotNetParameterList) dotNetParameter.getParent();

	DotNetParameter[] parameters = parent.getParameters();

	int i = ArrayUtil.indexOf(parameters, dotNetParameter);

	DotNetParameter nextParameter = ArrayUtil2.safeGet(parameters, i + 1);
	if(nextParameter != null && !nextParameter.hasModifier(CSharpModifier.PARAMS) && nextParameter.getInitializer() == null)
	{
		return newBuilder(dotNetParameter);
	}
	return null;
}
 
Example 5
Source File: RoutesTable.java    From railways with MIT License 6 votes vote down vote up
private void handleRightClick(MouseEvent e) {
    if (!SwingUtilities.isRightMouseButton(e) || !e.isPopupTrigger())
        return;

    // Before showing the popup, we should update selection properly:
    //  * if right-clicked on existing selection - do nothing.
    //  * if clicked outside current selection - clear it and select
    //    only item that was clicked.
    int clickedRowIndex = rowAtPoint(e.getPoint());
    boolean isSelectionClicked =
            ArrayUtil.indexOf(getSelectedRows(), clickedRowIndex) >= 0;

    if (!isSelectionClicked && clickedRowIndex >= 0 &&
            clickedRowIndex < getRowCount()) {
        setRowSelectionInterval(clickedRowIndex, clickedRowIndex);
    }
}
 
Example 6
Source File: MyDeviceChooser.java    From ADB-Duang with MIT License 6 votes vote down vote up
private void refreshTable() {
  IDevice[] devices = myDetectedDevicesRef.get();
  myDisplayedDevices = devices;

  final IDevice[] selectedDevices = getSelectedDevices();
  final TIntArrayList selectedRows = new TIntArrayList();
  for (int i = 0; i < devices.length; i++) {
    if (ArrayUtil.indexOf(selectedDevices, devices[i]) >= 0) {
      selectedRows.add(i);
    }
  }

  myProcessSelectionFlag = false;
  myDeviceTable.setModel(new MyDeviceTableModel(devices));
  if (selectedRows.size() == 0 && devices.length > 0) {
    myDeviceTable.getSelectionModel().setSelectionInterval(0, 0);
  }
  for (int selectedRow : selectedRows.toNativeArray()) {
    if (selectedRow < devices.length) {
      myDeviceTable.getSelectionModel().addSelectionInterval(selectedRow, selectedRow);
    }
  }
  fireSelectedDevicesChanged();
  myProcessSelectionFlag = true;
  updatePreviouslySelectedSerials();
}
 
Example 7
Source File: LatteBaseFlexLexer.java    From intellij-latte with MIT License 5 votes vote down vote up
/**
 * Returns to previous state and checks that the previous state is one of give states.
 */
protected void popState(int... states) {
	int top = stateStack.pop();
	if (states.length > 0) {
		if (ArrayUtil.indexOf(states, top) < 0) {
			String list = StringUtil.join(states, ", ");
			throw new RuntimeException("Unexpected state on stack; expected one of " + list + " but found " + top + ".");
		}
	}
	yybegin(top);
}
 
Example 8
Source File: CSharpLambdaParameterImpl.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
@RequiredReadAction
private DotNetTypeRef resolveTypeForParameter()
{
	CSharpLambdaExpressionImpl lambdaExpression = PsiTreeUtil.getParentOfType(this, CSharpLambdaExpressionImpl.class);
	if(lambdaExpression == null)
	{
		return DotNetTypeRef.UNKNOWN_TYPE;
	}
	CSharpLambdaParameter[] parameters = ((CSharpLambdaParameterListImpl) getParent()).getParameters();

	int i = ArrayUtil.indexOf(parameters, this);

	return CSharpLambdaExpressionImplUtil.resolveTypeForParameter(lambdaExpression, i);
}
 
Example 9
Source File: Unity3dAssetUtil.java    From consulo-unity3d with Apache License 2.0 5 votes vote down vote up
private static int weight(VirtualFile virtualFile)
{
	int i = ArrayUtil.indexOf(Unity3dAssetFileTypeDetector.ourAssetExtensionsArray, virtualFile.getExtension());
	if(i == -1)
	{
		return 1000;
	}
	else
	{
		return (i + 1) * 10;
	}
}
 
Example 10
Source File: CS1722.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Nullable
@Override
public HighlightInfoFactory checkImpl(@Nonnull CSharpLanguageVersion languageVersion, @Nonnull CSharpHighlightContext highlightContext, @Nonnull DotNetTypeList element)
{
	if(element.getNode().getElementType() != CSharpStubElements.EXTENDS_LIST)
	{
		return null;
	}

	CSharpTypeDeclaration resolvedElement = null;
	DotNetType baseType = null;
	DotNetType[] types = element.getTypes();

	for(DotNetType type : types)
	{
		DotNetTypeRef typeRef = type.toTypeRef();
		PsiElement temp = typeRef.resolve().getElement();
		if(temp instanceof CSharpTypeDeclaration && !((CSharpTypeDeclaration) temp).isInterface())
		{
			resolvedElement = (CSharpTypeDeclaration) temp;
			baseType = type;
			break;
		}
	}

	if(baseType == null)
	{
		return null;
	}
	int i = ArrayUtil.indexOf(types, baseType);
	if(i != 0)
	{
		CSharpTypeDeclaration parent = (CSharpTypeDeclaration) element.getParent();
		return newBuilder(baseType, formatElement(parent), formatElement(resolvedElement)).addQuickFix(new MoveToFirstPositionFix(baseType));
	}
	return null;
}
 
Example 11
Source File: RangeBlinker.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void removeHighlights() {
  MarkupModel markupModel = myEditor.getMarkupModel();
  RangeHighlighter[] allHighlighters = markupModel.getAllHighlighters();
  
  for (RangeHighlighter highlighter : myAddedHighlighters) {
    if (ArrayUtil.indexOf(allHighlighters, highlighter) != -1) {
      highlighter.dispose();
    }
  }
  myAddedHighlighters.clear();
}
 
Example 12
Source File: ProcessPopup.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void removeExtraSeparator(final InlineProgressIndicator indicator) {
  final Component[] all = myProcessBox.getComponents();
  final int index = ArrayUtil.indexOf(all, indicator.getComponent());
  if (index == -1) return;


  if (index == 0 && all.length > 1) {
    myProcessBox.remove(1);
  } else if (all.length > 2 && index < all.length - 1) {
    myProcessBox.remove(index + 1);
  }

  myProcessBox.remove(indicator.getComponent());
}
 
Example 13
Source File: VirtualDirectoryImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public VirtualFileSystemEntry doFindChildById(int id) {
  int i = ArrayUtil.indexOf(myData.myChildrenIds, id);
  if (i >= 0) {
    return mySegment.vfsData.getFileById(id, this);
  }

  String name = ourPersistence.getName(id);
  return findChild(name, false, false, getFileSystem());
}
 
Example 14
Source File: ObjectStubTree.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean execute(Object a, int[] b) {
  if (b.length == 1) return true;
  int firstZero = ArrayUtil.indexOf(b, 0);
  if (firstZero != -1) {
    int[] shorterList = ArrayUtil.realloc(b, firstZero);
    myProcessingMap.put(a, shorterList);
  }
  return true;
}
 
Example 15
Source File: CSharpMethodDeclStub.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
public static int getOperatorIndex(@Nonnull CSharpMethodDeclaration methodDeclaration)
{
	IElementType operatorElementType = methodDeclaration.getOperatorElementType();
	return operatorElementType == null ? -1 : ArrayUtil.indexOf(CSharpTokenSets.OVERLOADING_OPERATORS_AS_ARRAY, operatorElementType);
}
 
Example 16
Source File: PantsTreeStructureProvider.java    From intellij-pants-plugin with Apache License 2.0 4 votes vote down vote up
private boolean isModuleRoot(@NotNull PsiDirectoryNode node, Module module) {
  return ArrayUtil.indexOf(ModuleRootManager.getInstance(module).getContentRoots(), node.getVirtualFile()) >= 0;
}
 
Example 17
Source File: ImmutableElement.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public int indexOf(final Content child) {
  return ArrayUtil.indexOf(myContent, child);
}
 
Example 18
Source File: DFSTBuilder.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void strongConnect(@Nonnull List<List<Node>> sccs) {
  int successor = -1;
  nextNode:
  while (!frames.isEmpty()) {
    Frame pair = frames.peek();
    int i = pair.nodeI;

    // we have returned to the node
    if (index[i] == -1) {
      // actually we visit node first time, prepare
      index[i] = dfsIndex;
      lowLink[i] = dfsIndex;
      dfsIndex++;
      nodesOnStack.push(i);
      isOnStack[i] = true;
    }
    if (ArrayUtil.indexOf(pair.out, successor) != -1) {
      lowLink[i] = Math.min(lowLink[i], lowLink[successor]);
    }
    successor = i;

    // if unexplored children left, dfs there
    while (pair.nextUnexploredIndex < pair.out.length) {
      int nextI = pair.out[pair.nextUnexploredIndex++];
      if (index[nextI] == -1) {
        frames.push(new Frame(nextI));
        continue nextNode;
      }
      if (isOnStack[nextI]) {
        lowLink[i] = Math.min(lowLink[i], index[nextI]);

        if (myBackEdge == null) {
          myBackEdge = Couple.of(myAllNodes[nextI], myAllNodes[i]);
        }
      }
    }
    frames.pop();
    topo.add(i);
    // we are really back, pop a scc
    if (lowLink[i] == index[i]) {
      // found yer
      List<Node> scc = new ArrayList<Node>();
      int pushedI;
      do {
        pushedI = nodesOnStack.pop();
        Node pushed = myAllNodes[pushedI];
        isOnStack[pushedI] = false;
        scc.add(pushed);
      }
      while (pushedI != i);
      sccs.add(scc);
    }
  }
}
 
Example 19
Source File: TreeChangeImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static int getChildIndex(CompositeElement e) {
  return ArrayUtil.indexOf(e.getTreeParent().getChildren(null), e);
}
 
Example 20
Source File: ScopeOrderComparator.java    From consulo with Apache License 2.0 4 votes vote down vote up
private int getKey(String scope) {
  return myScopesOrder == null ? -1 : ArrayUtil.indexOf(myScopesOrder, scope);
}