Search in sources :

Example 1 with TIntProcedure

use of gnu.trove.TIntProcedure in project intellij-community by JetBrains.

the class GrIntroduceClosureParameterProcessor method removeParametersFromCall.

private static void removeParametersFromCall(GrMethodCallExpression methodCall, GrIntroduceParameterSettings settings) {
    final GroovyResolveResult resolveResult = methodCall.advancedResolve();
    final PsiElement resolved = resolveResult.getElement();
    LOG.assertTrue(resolved instanceof PsiMethod);
    final GrClosureSignature signature = GrClosureSignatureUtil.createSignature((PsiMethod) resolved, resolveResult.getSubstitutor());
    final GrClosureSignatureUtil.ArgInfo<PsiElement>[] argInfos = GrClosureSignatureUtil.mapParametersToArguments(signature, methodCall);
    LOG.assertTrue(argInfos != null);
    settings.parametersToRemove().forEach(new TIntProcedure() {

        @Override
        public boolean execute(int value) {
            final List<PsiElement> args = argInfos[value].args;
            for (PsiElement arg : args) {
                arg.delete();
            }
            return true;
        }
    });
}
Also used : GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) TIntProcedure(gnu.trove.TIntProcedure) GrClosureSignature(org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature) GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) List(java.util.List) ArrayList(java.util.ArrayList) GrParameterList(org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameterList)

Example 2 with TIntProcedure

use of gnu.trove.TIntProcedure in project intellij-community by JetBrains.

the class GroovyIntroduceParameterUtil method removeParametersFromCall.

private static void removeParametersFromCall(GrMethodCallExpression methodCall, GrIntroduceParameterSettings settings) {
    final GroovyResolveResult resolveResult = methodCall.advancedResolve();
    final PsiElement resolved = resolveResult.getElement();
    LOG.assertTrue(resolved instanceof PsiMethod);
    final GrClosureSignature signature = GrClosureSignatureUtil.createSignature((PsiMethod) resolved, resolveResult.getSubstitutor());
    final GrClosureSignatureUtil.ArgInfo<PsiElement>[] argInfos = GrClosureSignatureUtil.mapParametersToArguments(signature, methodCall);
    LOG.assertTrue(argInfos != null);
    settings.parametersToRemove().forEach(new TIntProcedure() {

        @Override
        public boolean execute(int value) {
            final List<PsiElement> args = argInfos[value].args;
            for (PsiElement arg : args) {
                arg.delete();
            }
            return true;
        }
    });
}
Also used : GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) TIntProcedure(gnu.trove.TIntProcedure) GrClosureSignature(org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature) GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) TIntArrayList(gnu.trove.TIntArrayList) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)

Example 3 with TIntProcedure

use of gnu.trove.TIntProcedure in project intellij-community by JetBrains.

the class GroovyIntroduceParameterMethodUsagesProcessor method processChangeMethodSignature.

@Override
public boolean processChangeMethodSignature(IntroduceParameterData data, UsageInfo usage, UsageInfo[] usages) throws IncorrectOperationException {
    if (!(usage.getElement() instanceof GrMethod) || !isGroovyUsage(usage))
        return true;
    GrMethod method = (GrMethod) usage.getElement();
    final FieldConflictsResolver fieldConflictsResolver = new FieldConflictsResolver(data.getParameterName(), method.getBlock());
    final MethodJavaDocHelper javaDocHelper = new MethodJavaDocHelper(method);
    final PsiParameter[] parameters = method.getParameterList().getParameters();
    data.getParametersToRemove().forEachDescending(new TIntProcedure() {

        @Override
        public boolean execute(final int paramNum) {
            try {
                PsiParameter param = parameters[paramNum];
                PsiDocTag tag = javaDocHelper.getTagForParameter(param);
                if (tag != null) {
                    tag.delete();
                }
                param.delete();
            } catch (IncorrectOperationException e) {
                LOG.error(e);
            }
            return true;
        }
    });
    addParameter(method, javaDocHelper, data.getForcedType(), data.getParameterName(), data.isDeclareFinal(), data.getProject());
    fieldConflictsResolver.fix();
    return false;
}
Also used : MethodJavaDocHelper(com.intellij.refactoring.util.javadoc.MethodJavaDocHelper) TIntProcedure(gnu.trove.TIntProcedure) PsiDocTag(com.intellij.psi.javadoc.PsiDocTag) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) IncorrectOperationException(com.intellij.util.IncorrectOperationException)

Example 4 with TIntProcedure

use of gnu.trove.TIntProcedure in project intellij-community by JetBrains.

the class PropertiesSeparatorManager method guessSeparator.

//returns most probable separator in properties files
private static String guessSeparator(final ResourceBundleImpl resourceBundle) {
    final TIntLongHashMap charCounts = new TIntLongHashMap();
    for (PropertiesFile propertiesFile : resourceBundle.getPropertiesFiles()) {
        if (propertiesFile == null)
            continue;
        List<IProperty> properties = propertiesFile.getProperties();
        for (IProperty property : properties) {
            String key = property.getUnescapedKey();
            if (key == null)
                continue;
            for (int i = 0; i < key.length(); i++) {
                char c = key.charAt(i);
                if (!Character.isLetterOrDigit(c)) {
                    charCounts.put(c, charCounts.get(c) + 1);
                }
            }
        }
    }
    final char[] mostProbableChar = new char[] { '.' };
    charCounts.forEachKey(new TIntProcedure() {

        long count = -1;

        public boolean execute(int ch) {
            long charCount = charCounts.get(ch);
            if (charCount > count) {
                count = charCount;
                mostProbableChar[0] = (char) ch;
            }
            return true;
        }
    });
    if (mostProbableChar[0] == 0) {
        mostProbableChar[0] = '.';
    }
    return Character.toString(mostProbableChar[0]);
}
Also used : TIntProcedure(gnu.trove.TIntProcedure) TIntLongHashMap(gnu.trove.TIntLongHashMap) IProperty(com.intellij.lang.properties.IProperty) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile)

Example 5 with TIntProcedure

use of gnu.trove.TIntProcedure in project intellij-community by JetBrains.

the class PyWhiteSpaceFormattingStrategy method adjustWhiteSpaceIfNecessary.

/**
   * Python uses backslashes at the end of the line as indication that next line is an extension of the current one.
   * <p/>
   * Hence, we need to preserve them during white space manipulation.
   *
   *
   * @param whiteSpaceText    white space text to use by default for replacing sub-sequence of the given text
   * @param text              target text which region is to be replaced by the given white space symbols
   * @param startOffset       start offset to use with the given text (inclusive)
   * @param endOffset         end offset to use with the given text (exclusive)
   * @param codeStyleSettings the code style settings
   * @param nodeAfter
   * @return                  symbols to use for replacing {@code [startOffset; endOffset)} sub-sequence of the given text
   */
@NotNull
@Override
public CharSequence adjustWhiteSpaceIfNecessary(@NotNull CharSequence whiteSpaceText, @NotNull CharSequence text, int startOffset, int endOffset, CodeStyleSettings codeStyleSettings, ASTNode nodeAfter) {
    // The general idea is that '\' symbol before line feed should be preserved.
    TIntIntHashMap initialBackSlashes = countBackSlashes(text, startOffset, endOffset);
    if (initialBackSlashes.isEmpty()) {
        if (nodeAfter != null && whiteSpaceText.length() > 0 && whiteSpaceText.charAt(0) == '\n' && PythonEnterHandler.needInsertBackslash(nodeAfter, false)) {
            return addBackslashPrefix(whiteSpaceText, codeStyleSettings);
        }
        return whiteSpaceText;
    }
    final TIntIntHashMap newBackSlashes = countBackSlashes(whiteSpaceText, 0, whiteSpaceText.length());
    final AtomicBoolean continueProcessing = new AtomicBoolean();
    initialBackSlashes.forEachKey(new TIntProcedure() {

        @Override
        public boolean execute(int key) {
            if (!newBackSlashes.containsKey(key)) {
                continueProcessing.set(true);
                return false;
            }
            return true;
        }
    });
    if (!continueProcessing.get()) {
        return whiteSpaceText;
    }
    PyCodeStyleSettings settings = codeStyleSettings.getCustomSettings(PyCodeStyleSettings.class);
    StringBuilder result = new StringBuilder();
    int line = 0;
    for (int i = 0; i < whiteSpaceText.length(); i++) {
        char c = whiteSpaceText.charAt(i);
        if (c != '\n') {
            result.append(c);
            continue;
        }
        if (!newBackSlashes.contains(line++)) {
            if ((i == 0 || (i > 0 && whiteSpaceText.charAt(i - 1) != ' ')) && settings.SPACE_BEFORE_BACKSLASH) {
                result.append(' ');
            }
            result.append('\\');
        }
        result.append(c);
    }
    return result;
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TIntProcedure(gnu.trove.TIntProcedure) TIntIntHashMap(gnu.trove.TIntIntHashMap) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

TIntProcedure (gnu.trove.TIntProcedure)24 IncorrectOperationException (com.intellij.util.IncorrectOperationException)8 TIntArrayList (gnu.trove.TIntArrayList)5 NotNull (org.jetbrains.annotations.NotNull)3 GrClosureSignature (org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature)3 PsiDocTag (com.intellij.psi.javadoc.PsiDocTag)2 MethodJavaDocHelper (com.intellij.refactoring.util.javadoc.MethodJavaDocHelper)2 DFSTBuilder (com.intellij.util.graph.DFSTBuilder)2 TIntHashSet (gnu.trove.TIntHashSet)2 ArrayList (java.util.ArrayList)2 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)2 GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)2 GrArgumentList (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList)2 GrNamedArgument (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument)2 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)2 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)2 GrParameter (org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter)2 GrParameterList (org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameterList)2 ConditionalGotoInstruction (com.intellij.codeInspection.dataFlow.instructions.ConditionalGotoInstruction)1 GotoInstruction (com.intellij.codeInspection.dataFlow.instructions.GotoInstruction)1