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;
}
});
}
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;
}
});
}
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;
}
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]);
}
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;
}
Aggregations