@NotNull public String[] getArray() { return ArrayUtil.toStringArray(getList()); }
@Nullable protected GoExpression getExpression(@NotNull PsiElement[] elements) { return ObjectUtils.tryCast(ArrayUtil.getFirstElement(elements), GoExpression.class); } }
@NotNull @Override public GoExpression[] getActualParameters(@NotNull GoArgumentList o) { return ArrayUtil.toObjectArray(o.getExpressionList(), GoExpression.class); }
@Nullable protected TextRange surroundStatementsWithIfElse(@NotNull Project project, @NotNull PsiElement container, @NotNull PsiElement[] statements, boolean withElse) { PsiElement first = ArrayUtil.getFirstElement(statements); PsiElement last = ArrayUtil.getLastElement(statements); String block = StringUtil.join(statements, PsiElement::getText, "\n"); GoIfStatement ifStatement = GoElementFactory.createIfStatement(project, "", block, withElse ? "" : null); ifStatement = (GoIfStatement)container.addAfter(ifStatement, last); container.deleteChildRange(first, last); int offset = getOffsetLBraceOfBlock(ifStatement.getBlock()); return offset > -1 ? new TextRange(offset, offset) : null; }
compiler.parseArguments(ArrayUtil.toStringArray(args), arguments); } else { for (String path : pluginClassPaths) { if (ArrayUtil.indexOf(arguments.getPluginClasspaths(), path) < 0) { arguments.setPluginClasspaths(ArrayUtil.append(arguments.getPluginClasspaths(), path));
@NotNull @Contract(pure=true) public static String[] mergeArrays(@NotNull String[] a1, @NotNull String... a2) { return mergeArrays(a1, a2, STRING_ARRAY_FACTORY); }
@Override public void visitElement(PsiElement element) { if(!(element instanceof MethodReference) || !ArrayUtil.contains(((MethodReference) element).getName(), "add", "create") || !PhpElementsUtil.isMethodReferenceInstanceOf((MethodReference) element, "Symfony\\Component\\Form\\FormBuilderInterface") ) { super.visitElement(element); return; } PsiElement[] parameters = ((MethodReference) element).getParameters(); if(parameters.length < 2) { super.visitElement(element); return; } if(!(parameters[1] instanceof StringLiteralExpression) || ((StringLiteralExpression) parameters[1]).getContents().contains("\\")) { super.visitElement(element); return; } holder.registerProblem( parameters[1], MESSAGE, ProblemHighlightType.WEAK_WARNING, new MyLocalQuickFix(parameters[1]) ); super.visitElement(element); }
/** * Returns the previous sibling of the PSI element. * * @return the previous sibling, or null if the node is the first in the list of siblings. */ @Override public PsiElement getPrevSibling() { @SuppressWarnings("ConstantConditions") final PsiElement[] siblings = getParent().getChildren(); final int i = ArrayUtil.indexOf(siblings, this); PsiElement prevSibling; if (i < 1) { prevSibling = null; } else { prevSibling = siblings[i - 1]; } return prevSibling; }
@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter") static <T> void executeActionWithRecursiveGuard(@NotNull T object, @NotNull List<T> recursiveGuard, @NotNull final ObjectTreeAction<T> action) { synchronized (recursiveGuard) { if (ArrayUtil.indexOf(recursiveGuard, object, ContainerUtil.<T>identityStrategy()) != -1) return; recursiveGuard.add(object); } try { action.execute(object); } finally { synchronized (recursiveGuard) { int i = ArrayUtil.lastIndexOf(recursiveGuard, object, ContainerUtil.<T>identityStrategy()); assert i != -1; recursiveGuard.remove(i); } } }
public void excludePath(@NotNull String importPath) { setExcludedPackages(ArrayUtil.append(myExcludedPackages, importPath)); } }
public void killContainer(@NotNull String... containers) throws ExecutionException { runCommand(ArrayUtil.mergeArrays(new String[]{KILL}, containers)); }
@Nullable @Override protected TextRange surroundStatements(@NotNull Project project, @NotNull PsiElement container, @NotNull PsiElement[] statements) throws IncorrectOperationException { String text = StringUtil.join(statements, PsiElement::getText, "\n"); GoForStatement forStatement = GoElementFactory.createForStatement(project, text); PsiElement first = ArrayUtil.getFirstElement(statements); PsiElement last = ArrayUtil.getLastElement(statements); forStatement = (GoForStatement)container.addAfter(forStatement, last); container.deleteChildRange(first, last); int offset = getOffsetLBraceOfBlock(forStatement.getBlock()); return offset > -1 ? new TextRange(offset, offset) : null; } }
@Override public boolean value(final Class<? extends T> aClass) { final Class<?>[] interfaces = aClass.getInterfaces(); return ArrayUtil.contains(parentType, (Object[]) interfaces) || aClass.getSuperclass() == parentType; } });
/** * Returns the next sibling of the PSI element. * * @return the next sibling, or null if the node is the last in the list of siblings. */ @Override public PsiElement getNextSibling() { @SuppressWarnings("ConstantConditions") final PsiElement[] siblings = getParent().getChildren(); final int i = ArrayUtil.indexOf(siblings, this); PsiElement nextSibling; if (i < 0 || i >= siblings.length - 1) { nextSibling = null; } else { nextSibling = siblings[i + 1]; } return nextSibling; }
/** * Appends <code>element</code> to the <code>src</code> array. As you can * imagine the appended element will be the last one in the returned result. * * @param src array to which the <code>element</code> should be appended. * @param element object to be appended to the end of <code>src</code> array. * @return new array */ @NotNull @Contract(pure=true) public static <T> T[] append(@NotNull final T[] src, @Nullable final T element) { return append(src, element, (Class<T>)src.getClass().getComponentType()); }
@NotNull private String[] selectedCustomTags() { return ArrayUtil.toStringArray(StringUtil.split(myCustomTagsField.getText(), " ")); }
@Nullable @Override public Result calculateResult(ExpressionContext context) { LookupElement firstElement = ArrayUtil.getFirstElement(calculateLookupItems(context)); return new TextResult(firstElement != null ? firstElement.getLookupString() : ""); }
public GoInplaceVariableIntroducer(GoIntroduceOperation operation) { super(operation.getVar(), operation.getEditor(), operation.getProject(), "Introduce Variable", ArrayUtil.toObjectArray(operation.getOccurrences(), PsiElement.class), null); } }
private static void addOrReplaceScopes(@NotNull Project project, @NotNull List<NamedScope> newScopes) { final Set<String> newScopeNames = newScopes .stream() .map(NamedScope::getName) .collect(Collectors.toSet()); final NamedScopeManager namedScopeManager = NamedScopeManager.getInstance(project); final NamedScope[] existingScopes = namedScopeManager.getEditableScopes(); final NamedScope[] filteredScopes = Arrays .stream(existingScopes) .filter(it -> !newScopeNames.contains(it.getName())) .toArray(NamedScope[]::new); namedScopeManager.setScopes(ArrayUtil.mergeArrays( filteredScopes, newScopes.toArray(new NamedScope[0]) )); }
@Nullable @Override protected TextRange surroundStatements(@NotNull Project project, @NotNull PsiElement container, @NotNull PsiElement[] statements) throws IncorrectOperationException { GoBlock block = GoElementFactory.createBlock(project); PsiElement first = ArrayUtil.getFirstElement(statements); PsiElement last = ArrayUtil.getLastElement(statements); block = (GoBlock)container.addAfter(block, last); block.addRangeAfter(first, last, block.getLbrace()); CodeEditUtil.markToReformat(block.getNode(), true); container.deleteChildRange(first, last); int offset = block.getTextRange().getEndOffset(); return new TextRange(offset, offset); } }