Java 类com.intellij.util.ArrayUtilRt 实例源码

项目:intellij-ce-playground    文件:InferenceSession.java   
private static PsiType getTypeByMethod(PsiElement context,
                                       PsiExpressionList argumentList,
                                       PsiElement parentMethod,
                                       boolean varargs,
                                       PsiSubstitutor substitutor) {
  if (parentMethod instanceof PsiMethod) {
    final PsiParameter[] parameters = ((PsiMethod)parentMethod).getParameterList().getParameters();
    if (parameters.length == 0) return null;
    final PsiExpression[] args = argumentList.getExpressions();
    if (!((PsiMethod)parentMethod).isVarArgs() && parameters.length != args.length) return null;
    PsiElement arg = context;
    while (arg.getParent() instanceof PsiParenthesizedExpression) {
      arg = arg.getParent();
    }
    final int i = ArrayUtilRt.find(args, arg);
    if (i < 0) return null;
    final PsiType parameterType = getParameterType(parameters, i, substitutor, varargs);
    final boolean isRaw = substitutor != null && PsiUtil.isRawSubstitutor((PsiMethod)parentMethod, substitutor);
    return isRaw ? TypeConversionUtil.erasure(parameterType) : parameterType;
  }
  return null;
}
项目:intellij-ce-playground    文件:InlineSuperClassRefactoringProcessor.java   
@Nullable
private static PsiType getPlaceExpectedType(PsiElement parent) {
  PsiType type = PsiTypesUtil.getExpectedTypeByParent((PsiExpression)parent);
  if (type == null) {
    final PsiElement arg = PsiUtil.skipParenthesizedExprUp(parent);
    final PsiElement gParent = arg.getParent();
    if (gParent instanceof PsiExpressionList) {
      int i = ArrayUtilRt.find(((PsiExpressionList)gParent).getExpressions(), arg);
      final PsiElement pParent = gParent.getParent();
      if (pParent instanceof PsiCallExpression) {
        final PsiMethod method = ((PsiCallExpression)pParent).resolveMethod();
        if (method != null) {
          final PsiParameter[] parameters = method.getParameterList().getParameters();
          if (i >= parameters.length) {
            if (method.isVarArgs()) {
              return ((PsiEllipsisType)parameters[parameters.length - 1].getType()).getComponentType();
            }
          } else {
            return parameters[i].getType();
          }
        }
      }
    }
  }
  return type;
}
项目:intellij-ce-playground    文件:JsonReaders.java   
public static long[] readLongArray(JsonReaderEx reader) {
  checkIsNull(reader, null);
  reader.beginArray();
  if (!reader.hasNext()) {
    reader.endArray();
    return ArrayUtilRt.EMPTY_LONG_ARRAY;
  }

  TLongArrayList result = new TLongArrayList();
  do {
    result.add(reader.nextLong());
  }
  while (reader.hasNext());
  reader.endArray();
  return result.toNativeArray();
}
项目:intellij-ce-playground    文件:JsonReaders.java   
public static int[] readIntArray(JsonReaderEx reader) {
  checkIsNull(reader, null);
  reader.beginArray();
  if (!reader.hasNext()) {
    reader.endArray();
    return ArrayUtilRt.EMPTY_INT_ARRAY;
  }

  TIntArrayList result = new TIntArrayList();
  do {
    result.add(reader.nextInt());
  }
  while (reader.hasNext());
  reader.endArray();
  return result.toNativeArray();
}
项目:intellij-ce-playground    文件:ControlFlowBuilderUtil.java   
private static boolean isLastStatementInCaseSection(GrCaseSection caseSection, GrSwitchStatement switchStatement) {
  final GrCaseSection[] sections = switchStatement.getCaseSections();
  final int i = ArrayUtilRt.find(sections, caseSection);
  if (i == sections.length - 1) {
    return true;
  }

  for (int j = i + 1; j < sections.length; j++) {
    GrCaseSection section = sections[j];
    for (GrStatement statement : section.getStatements()) {
      if (!(statement instanceof GrBreakStatement)) {
        return false;
      }
    }
  }
  return true;
}
项目:intellij-ce-playground    文件:InvertIfIntention.java   
private static boolean isTailAfterIf(@NotNull GrIfStatement ifStatement, @NotNull GrStatementOwner owner) {
  final GrControlFlowOwner flowOwner = ControlFlowUtils.findControlFlowOwner(ifStatement);
  if (flowOwner == null) return false;

  final Instruction[] flow = flowOwner.getControlFlow();

  final GrStatement[] statements = owner.getStatements();
  final int index = ArrayUtilRt.find(statements, ifStatement);
  if (index == statements.length - 1) return false;

  final GrStatement then = ifStatement.getThenBranch();

  for (Instruction i : flow) {
    final PsiElement element = i.getElement();
    if (element == null || !PsiTreeUtil.isAncestor(then, element, true)) continue;

    for (Instruction succ : i.allSuccessors()) {
      if (succ instanceof IfEndInstruction) {
        return false;
      }
    }
  }

  return true;
}
项目:intellij-ce-playground    文件:JavaFxLocationReferenceProvider.java   
private static PsiReference[] collectRefs(@NotNull PsiElement element, String value, final int startInElement, final FileType... acceptedFileTypes) {
  final FileReferenceSet set = new FileReferenceSet(value, element, startInElement, null, true){
    @Override
    protected Condition<PsiFileSystemItem> getReferenceCompletionFilter() {
      return new Condition<PsiFileSystemItem>() {
        @Override
        public boolean value(PsiFileSystemItem item) {
          if (item instanceof PsiDirectory) return true;
          final VirtualFile virtualFile = item.getVirtualFile();
          if (virtualFile == null) return false;
          final FileType fileType = virtualFile.getFileType();
          return ArrayUtilRt.find(acceptedFileTypes, fileType) >= 0;
        }
      };
    }
  };
  if (value.startsWith("/")) {
    set.addCustomization(FileReferenceSet.DEFAULT_PATH_EVALUATOR_OPTION, FileReferenceSet.ABSOLUTE_TOP_LEVEL);
  }
  return set.getAllReferences();
}
项目:tools-idea    文件:InlineSuperClassRefactoringProcessor.java   
@Nullable
private static PsiType getPlaceExpectedType(PsiElement parent) {
  PsiType type = PsiTypesUtil.getExpectedTypeByParent((PsiExpression)parent);
  if (type == null) {
    final PsiElement arg = PsiUtil.skipParenthesizedExprUp(parent);
    final PsiElement gParent = arg.getParent();
    if (gParent instanceof PsiExpressionList) {
      int i = ArrayUtilRt.find(((PsiExpressionList)gParent).getExpressions(), arg);
      final PsiElement pParent = gParent.getParent();
      if (pParent instanceof PsiCallExpression) {
        final PsiMethod method = ((PsiCallExpression)pParent).resolveMethod();
        if (method != null) {
          final PsiParameter[] parameters = method.getParameterList().getParameters();
          if (i >= parameters.length) {
            if (method.isVarArgs()) {
              return ((PsiEllipsisType)parameters[parameters.length - 1].getType()).getComponentType();
            }
          } else {
            return parameters[i].getType();
          }
        }
      }
    }
  }
  return type;
}
项目:tools-idea    文件:HighlightInfo.java   
@Nullable
@Override
public HighlightInfo create() {
  HighlightInfo info = createUnconditionally();
  LOG.assertTrue(psiElement != null || severity == HighlightInfoType.SYMBOL_TYPE_SEVERITY || severity == HighlightInfoType.INJECTED_FRAGMENT_SEVERITY || ArrayUtilRt.find(HighlightSeverity.DEFAULT_SEVERITIES, severity) != -1,
                 "Custom type demands element to detect its text attributes");

  PsiFile file = psiElement == null ? null : psiElement.getContainingFile();
  for (HighlightInfoFilter filter : FILTERS) {
    if (!filter.accept(info, file)) {
      return null;
    }
  }

  return info;
}
项目:tools-idea    文件:ControlFlowBuilderUtil.java   
private static boolean isLastStatementInCaseSection(GrCaseSection caseSection, GrSwitchStatement switchStatement) {
  final GrCaseSection[] sections = switchStatement.getCaseSections();
  final int i = ArrayUtilRt.find(sections, caseSection);
  if (i == sections.length - 1) {
    return true;
  }

  for (int j = i + 1; j < sections.length; j++) {
    GrCaseSection section = sections[j];
    for (GrStatement statement : section.getStatements()) {
      if (!(statement instanceof GrBreakStatement)) {
        return false;
      }
    }
  }
  return true;
}
项目:tools-idea    文件:InvertIfIntention.java   
private static boolean isTailAfterIf(@NotNull GrIfStatement ifStatement, @NotNull GrStatementOwner owner) {
  final GrControlFlowOwner flowOwner = ControlFlowUtils.findControlFlowOwner(ifStatement);
  if (flowOwner == null) return false;

  final Instruction[] flow = flowOwner.getControlFlow();

  final GrStatement[] statements = owner.getStatements();
  final int index = ArrayUtilRt.find(statements, ifStatement);
  if (index == statements.length - 1) return false;

  final GrStatement then = ifStatement.getThenBranch();

  for (Instruction i : flow) {
    final PsiElement element = i.getElement();
    if (element == null || !PsiTreeUtil.isAncestor(then, element, true)) continue;

    for (Instruction succ : i.allSuccessors()) {
      if (succ instanceof IfEndInstruction) {
        return false;
      }
    }
  }

  return true;
}
项目:tools-idea    文件:AbstractJavaFxPackager.java   
private void copyLibraries(String zipPath, File tempUnzippedArtifactOutput) throws IOException {
  final File[] outFiles = new File(getArtifactOutputPath()).listFiles();
  if (outFiles != null) {
    final String[] generatedItems = new String[] {JB_JFX_JKS, zipPath + ".jar", zipPath + ".jnlp", zipPath + ".html"};
    for (File file : outFiles) {
      final String fileName = file.getName();
      if (ArrayUtilRt.find(generatedItems, fileName) < 0) {
        final File destination = new File(tempUnzippedArtifactOutput, fileName);
        if (file.isFile()) {
          FileUtil.copy(file, destination);
        } else {
          FileUtil.copyDir(file, destination, true);
        }
      }
    }
  }
}
项目:tools-idea    文件:JavaFxLocationReferenceProvider.java   
private static PsiReference[] collectRefs(PsiElement element, String value, final int startInElement, final FileType... acceptedFileTypes) {
  final FileReferenceSet set = new FileReferenceSet(value, element, startInElement, null, true){
    @Override
    protected Condition<PsiFileSystemItem> getReferenceCompletionFilter() {
      return new Condition<PsiFileSystemItem>() {
        @Override
        public boolean value(PsiFileSystemItem item) {
          if (item instanceof PsiDirectory) return true;
          final VirtualFile virtualFile = item.getVirtualFile();
          if (virtualFile == null) return false;
          final FileType fileType = virtualFile.getFileType();
          return ArrayUtilRt.find(acceptedFileTypes, fileType) >= 0;
        }
      };
    }
  };
  if (value.startsWith("/")) {
    set.addCustomization(FileReferenceSet.DEFAULT_PATH_EVALUATOR_OPTION, FileReferenceSet.ABSOLUTE_TOP_LEVEL);
  }
  return set.getAllReferences();
}
项目:consulo-javafx    文件:AbstractJavaFxPackager.java   
private void copyLibraries(String zipPath, File tempUnzippedArtifactOutput) throws IOException {
  final File[] outFiles = new File(getArtifactOutputPath()).listFiles();
  if (outFiles != null) {
    final String[] generatedItems = new String[] {JB_JFX_JKS, zipPath + ".jar", zipPath + ".jnlp", zipPath + ".html"};
    for (File file : outFiles) {
      final String fileName = file.getName();
      if (ArrayUtilRt.find(generatedItems, fileName) < 0) {
        final File destination = new File(tempUnzippedArtifactOutput, fileName);
        if (file.isFile()) {
          FileUtil.copy(file, destination);
        } else {
          FileUtil.copyDir(file, destination, true);
        }
      }
    }
  }
}
项目:consulo-javafx    文件:JavaFxLocationReferenceProvider.java   
private static PsiReference[] collectRefs(PsiElement element, String value, final int startInElement, final FileType... acceptedFileTypes) {
  final FileReferenceSet set = new FileReferenceSet(value, element, startInElement, null, true){
    @Override
    protected Condition<PsiFileSystemItem> getReferenceCompletionFilter() {
      return new Condition<PsiFileSystemItem>() {
        @Override
        public boolean value(PsiFileSystemItem item) {
          if (item instanceof PsiDirectory) return true;
          final VirtualFile virtualFile = item.getVirtualFile();
          if (virtualFile == null) return false;
          final FileType fileType = virtualFile.getFileType();
          return ArrayUtilRt.find(acceptedFileTypes, fileType) >= 0;
        }
      };
    }
  };
  if (value.startsWith("/")) {
    set.addCustomization(FileReferenceSet.DEFAULT_PATH_EVALUATOR_OPTION, FileReferenceSet.ABSOLUTE_TOP_LEVEL);
  }
  return set.getAllReferences();
}
项目:consulo    文件:ComponentStoreImpl.java   
@Override
public final void save(@Nonnull List<Pair<StateStorage.SaveSession, VirtualFile>> readonlyFiles) {
  ExternalizationSession externalizationSession = myComponents.isEmpty() ? null : getStateStorageManager().startExternalization();
  if (externalizationSession != null) {
    String[] names = ArrayUtilRt.toStringArray(myComponents.keySet());
    Arrays.sort(names);
    for (String name : names) {
      StateComponentInfo<?> componentInfo = myComponents.get(name);

      commitComponent(componentInfo, externalizationSession);
    }
  }

  for (SettingsSavingComponent settingsSavingComponent : mySettingsSavingComponents) {
    try {
      settingsSavingComponent.save();
    }
    catch (Throwable e) {
      LOG.error(e);
    }
  }

  doSave(externalizationSession == null ? null : externalizationSession.createSaveSessions(), readonlyFiles);
}
项目:consulo-java    文件:InlineSuperClassRefactoringProcessor.java   
@Nullable
private static PsiType getPlaceExpectedType(PsiElement parent) {
  PsiType type = PsiTypesUtil.getExpectedTypeByParent((PsiExpression)parent);
  if (type == null) {
    final PsiElement arg = PsiUtil.skipParenthesizedExprUp(parent);
    final PsiElement gParent = arg.getParent();
    if (gParent instanceof PsiExpressionList) {
      int i = ArrayUtilRt.find(((PsiExpressionList)gParent).getExpressions(), arg);
      final PsiElement pParent = gParent.getParent();
      if (pParent instanceof PsiCallExpression) {
        final PsiMethod method = ((PsiCallExpression)pParent).resolveMethod();
        if (method != null) {
          final PsiParameter[] parameters = method.getParameterList().getParameters();
          if (i >= parameters.length) {
            if (method.isVarArgs()) {
              return ((PsiEllipsisType)parameters[parameters.length - 1].getType()).getComponentType();
            }
          } else {
            return parameters[i].getType();
          }
        }
      }
    }
  }
  return type;
}
项目:intellij-ce-playground    文件:ProcessCandidateParameterTypeInferencePolicy.java   
@Override
public Pair<PsiType, ConstraintType> inferTypeConstraintFromCallContext(PsiExpression innerMethodCall,
                                                                        PsiExpressionList expressionList,
                                                                        @NotNull PsiCallExpression contextCall,
                                                                        PsiTypeParameter typeParameter) {
  PsiExpression[] expressions = expressionList.getExpressions();
  PsiElement parent = innerMethodCall;
  while (parent.getParent() instanceof PsiParenthesizedExpression) {
    parent = parent.getParent();
  }
  int i = ArrayUtilRt.find(expressions, parent);
  if (i < 0) return null;
  PsiMethod owner = (PsiMethod)typeParameter.getOwner();
  if (owner == null) return null;

  try {
    final JavaResolveResult[] results = getResults(contextCall, i);
    final PsiType innerReturnType = owner.getReturnType();
    for (final JavaResolveResult result : results) {
      if (result == null) continue;
      final PsiSubstitutor substitutor = getSubstitutor(contextCall, expressions, i, result);
      final Pair<PsiType, ConstraintType> constraint = inferConstraint(typeParameter, innerMethodCall, i, innerReturnType, result, substitutor);
      if (constraint != null) return constraint;
    }
  }
  catch (MethodProcessorSetupFailedException ev) {
    return null;
  }

  return null;
}
项目:intellij-ce-playground    文件:RefCountHolder.java   
private static boolean isParameterUsedRecursively(@NotNull PsiElement element, @NotNull Collection<PsiReference> array) {
  if (!(element instanceof PsiParameter)) return false;
  PsiParameter parameter = (PsiParameter)element;
  PsiElement scope = parameter.getDeclarationScope();
  if (!(scope instanceof PsiMethod)) return false;
  PsiMethod method = (PsiMethod)scope;
  int paramIndex = ArrayUtilRt.find(method.getParameterList().getParameters(), parameter);

  for (PsiReference reference : array) {
    if (!(reference instanceof PsiElement)) return false;
    PsiElement argument = (PsiElement)reference;

    PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)new PsiMatcherImpl(argument)
      .dot(PsiMatchers.hasClass(PsiReferenceExpression.class))
      .parent(PsiMatchers.hasClass(PsiExpressionList.class))
      .parent(PsiMatchers.hasClass(PsiMethodCallExpression.class))
      .getElement();
    if (methodCallExpression == null) return false;
    PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression();
    if (method != methodExpression.resolve()) return false;
    PsiExpressionList argumentList = methodCallExpression.getArgumentList();
    PsiExpression[] arguments = argumentList.getExpressions();
    int argumentIndex = ArrayUtilRt.find(arguments, argument);
    if (paramIndex != argumentIndex) return false;
  }

  return true;
}
项目:intellij-ce-playground    文件:SurroundWithArrayFix.java   
@Nullable
private PsiExpression checkMethod(final PsiElement element, final PsiMethod psiMethod) {
  final PsiParameter[] psiParameters = psiMethod.getParameterList().getParameters();
  final PsiExpressionList argumentList = myMethodCall.getArgumentList();
  int idx = 0;
  for (PsiExpression expression : argumentList.getExpressions()) {
    if (element != null && PsiTreeUtil.isAncestor(expression, element, false)) {
      if (psiParameters.length > idx) {
        final PsiType paramType = psiParameters[idx].getType();
        if (paramType instanceof PsiArrayType) {
          final PsiType expressionType = expression.getType();
          if (expressionType != null) {
            final PsiType componentType = ((PsiArrayType)paramType).getComponentType();
            if (expressionType.isAssignableFrom(componentType)) {
              return expression;
            }
            final PsiClass psiClass = PsiUtil.resolveClassInType(componentType);
            if (ArrayUtilRt.find(psiMethod.getTypeParameters(), psiClass) != -1) {
              for (PsiClassType superType : psiClass.getSuperTypes()) {
                if (TypeConversionUtil.isAssignable(superType, expressionType)) return expression;
              }
            }
          }
        }
      }
    }
    idx++;
  }
  return null;
}
项目:intellij-ce-playground    文件:JavaDocInfoGenerator.java   
public static void enumConstantOrdinal(StringBuilder buffer, PsiField field, PsiClass parentClass, final String newLine) {
  if (parentClass != null && field instanceof PsiEnumConstant) {
    final PsiField[] fields = parentClass.getFields();
    final int idx = ArrayUtilRt.find(fields, field);
    if (idx >= 0) {
      buffer.append(newLine);
      buffer.append("Enum constant ordinal: ").append(idx);
    }
  }
}
项目:intellij-ce-playground    文件:RenameJavaClassProcessor.java   
public void addClassCollisions(PsiElement referenceElement, String newName, List<UsageInfo> results) {
  final PsiResolveHelper resolveHelper = JavaPsiFacade.getInstance(referenceElement.getProject()).getResolveHelper();
  final PsiClass aClass = resolveHelper.resolveReferencedClass(newName, referenceElement);
  if (aClass == null) return;
  if (aClass instanceof PsiTypeParameter && myRenamedClass instanceof PsiTypeParameter) {
    final PsiTypeParameterListOwner member = PsiTreeUtil.getParentOfType(referenceElement, PsiTypeParameterListOwner.class);
    if (member != null) {
      final PsiTypeParameterList typeParameterList = member.getTypeParameterList();
      if (typeParameterList != null && ArrayUtilRt.find(typeParameterList.getTypeParameters(), myRenamedClass) > -1) {
        if (member.hasModifierProperty(PsiModifier.STATIC)) return;
      }
    }
  }
  final PsiFile containingFile = referenceElement.getContainingFile();
  final String text = referenceElement.getText();
  if (Comparing.equal(myRenamedClassQualifiedName, removeSpaces(text))) return;
  if (myProcessedFiles.contains(containingFile)) return;
  for (PsiReference reference : ReferencesSearch.search(aClass, new LocalSearchScope(containingFile))) {
    final PsiElement collisionReferenceElement = reference.getElement();
    if (collisionReferenceElement instanceof PsiJavaCodeReferenceElement) {
      final PsiElement parent = collisionReferenceElement.getParent();
      if (parent instanceof PsiImportStatement) {
        results.add(new CollidingClassImportUsageInfo((PsiImportStatement)parent, myRenamedClass));
      }
      else {
        if (aClass.getQualifiedName() != null) {
          results.add(new ClassHidesImportedClassUsageInfo((PsiJavaCodeReferenceElement)collisionReferenceElement,
                                                           myRenamedClass, aClass));
        }
        else {
          results.add(new ClassHidesUnqualifiableClassUsageInfo((PsiJavaCodeReferenceElement)collisionReferenceElement,
                                                                myRenamedClass, aClass));
        }
      }
    }
  }
  myProcessedFiles.add(containingFile);
}
项目:intellij-ce-playground    文件:JavaMoveFilesOrDirectoriesHandler.java   
@Nullable
private static PsiFile obtainContainingFile(@NotNull PsiElement element, PsiElement[] elements) {
  final PsiFile containingFile = element.getContainingFile();
  final PsiClass[] classes = ((PsiClassOwner)containingFile).getClasses();
  final Set<PsiClass> nonMovedClasses = new HashSet<PsiClass>();
  for (PsiClass aClass : classes) {
    if (ArrayUtilRt.find(elements, aClass) < 0) {
      nonMovedClasses.add(aClass);
    }
  }
  if (nonMovedClasses.isEmpty()) {
    return containingFile;
  }
  else {
    final PsiDirectory containingDirectory = containingFile.getContainingDirectory();
    if (containingDirectory != null) {
      try {
        JavaDirectoryServiceImpl.checkCreateClassOrInterface(containingDirectory, ((PsiClass)element).getName());
        final PsiElement createdClass = containingDirectory.add(element);
        element.delete();
        return createdClass.getContainingFile();
      }
      catch (IncorrectOperationException e) {
        final Iterator<PsiClass> iterator = nonMovedClasses.iterator();
        final PsiClass nonMovedClass = iterator.next();
        final PsiElement createdFile = containingDirectory.add(nonMovedClass).getContainingFile();
        nonMovedClass.delete();
        while (iterator.hasNext()) {
          final PsiClass currentClass = iterator.next();
          createdFile.add(currentClass);
          currentClass.delete();
        }
        return containingFile;
      }
    }
  }
  return null;
}
项目:intellij-ce-playground    文件:Conditions.java   
public static <T> Condition<T> oneOf(final T... options) {
  return new Condition<T>() {
    @Override
    public boolean value(T t) {
      return ArrayUtilRt.find(options, t) >= 0;
    }
  };
}
项目:intellij-ce-playground    文件:LibraryImpl.java   
@Override
@NotNull
public String[] getUrls(@NotNull OrderRootType rootType) {
  checkDisposed();

  VirtualFilePointerContainer result = myRoots.get(rootType);
  return result == null ? ArrayUtilRt.EMPTY_STRING_ARRAY : result.getUrls();
}
项目:intellij-ce-playground    文件:HighlightInfo.java   
@Nullable
@Override
public HighlightInfo create() {
  HighlightInfo info = createUnconditionally();
  LOG.assertTrue(psiElement != null || severity == HighlightInfoType.SYMBOL_TYPE_SEVERITY || severity == HighlightInfoType.INJECTED_FRAGMENT_SEVERITY || ArrayUtilRt.find(HighlightSeverity.DEFAULT_SEVERITIES, severity) != -1,
                 "Custom type requires not-null element to detect its text attributes");

  if (!isAcceptedByFilters(info, psiElement)) return null;

  return info;
}
项目:intellij-ce-playground    文件:TodoFilter.java   
/**
 * @param element in which all data will be stored
 * @param patterns all available patterns
 */
public void writeExternal(Element element, TodoPattern[] patterns){
  element.setAttribute(ATTRIBUTE_NAME,myName);
  for (TodoPattern pattern : myTodoPatterns) {
    int index = ArrayUtilRt.find(patterns, pattern);
    LOG.assertTrue(index != -1);
    Element child = new Element(ELEMENT_PATTERN);
    child.setAttribute(ATTRIBUTE_INDEX, Integer.toString(index));
    element.addContent(child);
  }
}
项目:intellij-ce-playground    文件:TreeSpeedSearch.java   
@Override
protected int getSelectedIndex() {
  if (myCanExpand) {
    return ArrayUtilRt.find(getAllElements(), myComponent.getSelectionPath());
  }
  int[] selectionRows = myComponent.getSelectionRows();
  return selectionRows == null || selectionRows.length == 0 ? -1 : selectionRows[0];
}
项目:intellij-ce-playground    文件:LockFreeCopyOnWriteArrayList.java   
@NotNull
private static Object[] createArrayRemove(@NotNull Object[] elements, int index) {
  int len = elements.length;
  int numMoved = len - index - 1;
  Object[] newElements = len == 1 ? ArrayUtilRt.EMPTY_OBJECT_ARRAY : new Object[len - 1];
  if (index != 0) {
    System.arraycopy(elements, 0, newElements, 0, index);
  }
  if (numMoved != 0) {
    System.arraycopy(elements, index + 1, newElements, index, numMoved);
  }
  return newElements;
}
项目:intellij-ce-playground    文件:LockFreeCopyOnWriteArrayList.java   
@Nullable
private static Object[] createArrayRemove(@NotNull Object[] elements, Object o) {
  int len = elements.length;
  if (len == 0) {
    return null;
  }
  // Copy while searching for element to remove
  // This wins in the normal case of element being present
  int newLen = len - 1;
  Object[] newElements = newLen == 0 ? ArrayUtilRt.EMPTY_OBJECT_ARRAY : new Object[newLen];

  int i;
  for (i = newLen; i != 0; --i) {
    Object element = elements[i];
    if (eq(o, element)) {
      // found one;  copy remaining and exit
      System.arraycopy(elements, 0, newElements, 0, i);
      break;
    }
    newElements[i-1] = element;
  }

  // special handling for last cell
  if (i == 0 && !eq(o, elements[0])) {
    return null;
  }
  return newElements;
}
项目:intellij-ce-playground    文件:XDebuggerTreeNode.java   
protected int[] getNodesIndices(@Nullable Collection<? extends TreeNode> children) {
  if (children == null) return ArrayUtilRt.EMPTY_INT_ARRAY;

  final int[] ints = new int[children.size()];
  int i = 0;
  for (TreeNode node : children) {
    ints[i++] = getIndex(node);
  }
  Arrays.sort(ints);
  return ints;
}
项目:intellij-ce-playground    文件:ProjectSdksModel.java   
private void doApply() {
  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    @Override
    public void run() {
      final ArrayList<Sdk> itemsInTable = new ArrayList<Sdk>();
      final ProjectJdkTable jdkTable = ProjectJdkTable.getInstance();
      final Sdk[] allFromTable = jdkTable.getAllJdks();

      // Delete removed and fill itemsInTable
      for (final Sdk tableItem : allFromTable) {
        if (myProjectSdks.containsKey(tableItem)) {
          itemsInTable.add(tableItem);
        }
        else {
          jdkTable.removeJdk(tableItem);
        }
      }

      // Now all removed items are deleted from table, itemsInTable contains all items in table
      for (Sdk originalJdk : itemsInTable) {
        final Sdk modifiedJdk = myProjectSdks.get(originalJdk);
        LOG.assertTrue(modifiedJdk != null);
        LOG.assertTrue(originalJdk != modifiedJdk);
        jdkTable.updateJdk(originalJdk, modifiedJdk);
      }
      // Add new items to table
      final Sdk[] allJdks = jdkTable.getAllJdks();
      for (final Sdk projectJdk : myProjectSdks.keySet()) {
        LOG.assertTrue(projectJdk != null);
        if (ArrayUtilRt.find(allJdks, projectJdk) == -1) {
          jdkTable.addJdk(projectJdk);
          jdkTable.updateJdk(projectJdk, myProjectSdks.get(projectJdk));
        }
      }
    }
  });
}
项目:intellij-ce-playground    文件:RunConfigurable.java   
static void collectNodesRecursively(DefaultMutableTreeNode parentNode, List<DefaultMutableTreeNode> nodes, NodeKind... allowed) {
  for (int i = 0; i < parentNode.getChildCount(); i++) {
    DefaultMutableTreeNode child = (DefaultMutableTreeNode)parentNode.getChildAt(i);
    if (ArrayUtilRt.find(allowed, getKind(child)) != -1) {
      nodes.add(child);
    }
    collectNodesRecursively(child, nodes, allowed);
  }
}
项目:intellij-ce-playground    文件:AndroidExtractStyleAction.java   
private static boolean canBeExtracted(@NotNull XmlAttribute attribute) {
  if (!(SdkConstants.NS_RESOURCES.equals(attribute.getNamespace()))) {
    return false;
  }
  final String name = attribute.getLocalName();
  if (ArrayUtilRt.find(NON_EXTRACTABLE_ATTRIBUTES, name) >= 0) {
    return false;
  }
  if (name.startsWith(ATTR_STYLE)) {
    return false;
  }
  return true;
}
项目:intellij-ce-playground    文件:AndroidRunningState.java   
private boolean isMyDevice(@NotNull IDevice device) {
  if (myTargetDevices.length > 0) {
    return ArrayUtilRt.find(myTargetDevices, device) >= 0;
  }
  Boolean compatible = isCompatibleDevice(device);
  return compatible == null || compatible.booleanValue();
}
项目:intellij-ce-playground    文件:SSHMain.java   
/**
 * Configure known host database for connection
 *
 * @param c a connection
 * @throws IOException if there is a IO problem
 */
private void configureKnownHosts(Connection c) throws IOException {
  File knownHostFile = new File(knownHostPath);
  if (knownHostFile.exists()) {
    database.addHostkeys(knownHostFile);
  }
  final List<String> algorithms = myHost.getHostKeyAlgorithms();
  c.setServerHostKeyAlgorithms(ArrayUtilRt.toStringArray(algorithms));
}
项目:intellij-ce-playground    文件:SSHMain.java   
/**
 * {@inheritDoc}
 */
@SuppressWarnings({"UseOfObsoleteCollectionType"})
@Nullable
public String[] replyToChallenge(final String name,
                                 final String instruction,
                                 final int numPrompts,
                                 final String[] prompt,
                                 final boolean[] echo) throws Exception {
  if (numPrompts == 0) {
    return ArrayUtilRt.EMPTY_STRING_ARRAY;
  }
  myPromptCount++;
  Vector<String> vPrompts = new Vector<String>(prompt.length);
  Collections.addAll(vPrompts, prompt);
  Vector<Boolean> vEcho = new Vector<Boolean>(prompt.length);
  for (boolean e : echo) {
    vEcho.add(e);
  }
  final Vector<String> result =
    myXmlRpcClient.replyToChallenge(myHandlerNo, getUserHostString(), name, instruction, numPrompts, vPrompts, vEcho, myLastError);
  if (result == null) {
    myCancelled = true;
    String[] rc = new String[numPrompts];
    Arrays.fill(rc, "");
    return rc;
  }
  else {
    return ArrayUtilRt.toStringArray(result);
  }
}
项目:intellij-ce-playground    文件:GrIntroduceLocalVariableProcessor.java   
@NotNull
public GrVariable processExpression(@NotNull GrVariableDeclaration declaration) {
  resolveLocalConflicts(myContext.getScope(), mySettings.getName());

  preprocessOccurrences();

  int expressionIndex = ArrayUtilRt.find(myOccurrences, myExpression);
  final PsiElement[] replaced = myProcessUsages ? processOccurrences() : myOccurrences;
  PsiElement replacedExpression = replaced[expressionIndex];
  GrStatement anchor = GrIntroduceHandlerBase.getAnchor(replaced, myContext.getScope());

  RefactoringUtil.highlightAllOccurrences(myContext.getProject(), replaced, myContext.getEditor());

  return insertVariableDefinition(declaration, anchor, replacedExpression);
}
项目:intellij-ce-playground    文件:AbstractJavaFxPackager.java   
private void copyLibraries(String zipPath, File tempUnzippedArtifactOutput) throws IOException {
  final File[] outFiles = new File(getArtifactOutputPath()).listFiles();
  if (outFiles != null) {
    final String[] generatedItems = new String[] {JB_JFX_JKS, zipPath + ".jar", zipPath + ".jnlp", zipPath + ".html"};
    for (File file : outFiles) {
      final String fileName = file.getName();
      if (ArrayUtilRt.find(generatedItems, fileName) < 0) {
        final File destination = new File(tempUnzippedArtifactOutput, fileName);
        FileUtil.copyFileOrDir(file, destination);
      }
    }
  }
}
项目:consulo-unity3d    文件:ShaderLabOrRole.java   
@NotNull
@Override
public String[] getValues()
{
    List<String> result = new ArrayList<>();
    for(ShaderLabRole role : myRoles)
    {
        Collections.addAll(result, role.getValues());
    }
    return ArrayUtilRt.toStringArray(result);
}