use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock in project intellij-community by JetBrains.
the class GrIntroduceParameterDialog method init.
@Override
protected void init() {
super.init();
JavaRefactoringSettings settings = JavaRefactoringSettings.getInstance();
initReplaceFieldsWithGetters(settings);
myDeclareFinalCheckBox.setSelected(hasFinalModifier());
myDelegateViaOverloadingMethodCheckBox.setVisible(myInfo.getToSearchFor() != null);
setTitle(RefactoringBundle.message("introduce.parameter.title"));
myTable.init(myInfo);
final GrParameter[] parameters = myInfo.getToReplaceIn().getParameters();
toRemoveCBs.forEachEntry(new TObjectIntProcedure<JCheckBox>() {
@Override
public boolean execute(JCheckBox checkbox, int index) {
checkbox.setSelected(true);
final GrParameter param = parameters[index];
final ParameterInfo pinfo = findParamByOldName(param.getName());
if (pinfo != null) {
pinfo.passAsParameter = false;
}
return true;
}
});
updateSignature();
if (myCanIntroduceSimpleParameter) {
mySignaturePanel.setVisible(false);
//action to hide signature panel if we have variants to introduce simple parameter
myTypeComboBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
mySignaturePanel.setVisible(myTypeComboBox.isClosureSelected());
pack();
}
});
}
final PsiType closureReturnType = inferClosureReturnType();
if (PsiType.VOID.equals(closureReturnType)) {
myForceReturnCheckBox.setEnabled(false);
myForceReturnCheckBox.setSelected(false);
} else {
myForceReturnCheckBox.setSelected(isForceReturn());
}
if (myInfo.getToReplaceIn() instanceof GrClosableBlock) {
myDelegateViaOverloadingMethodCheckBox.setEnabled(false);
myDelegateViaOverloadingMethodCheckBox.setToolTipText("Delegating is not allowed in closure context");
}
pack();
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock in project intellij-community by JetBrains.
the class GroovyIntroduceParameterUtil method addClosureToCall.
@Nullable
public static GrExpression addClosureToCall(PsiElement initializer, GrArgumentList list) {
if (!(initializer instanceof GrClosableBlock))
return null;
final PsiElement parent = list.getParent();
if (!(parent instanceof GrMethodCallExpression))
return null;
PsiElement anchor;
final GrClosableBlock[] cls = ((GrMethodCallExpression) parent).getClosureArguments();
if (cls.length > 0) {
anchor = cls[cls.length - 1];
} else {
anchor = list;
}
return (GrExpression) parent.addAfter(initializer, anchor);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock in project intellij-community by JetBrains.
the class GroovyIntroduceParameterUtil method removeParamsFromUnresolvedCall.
public static void removeParamsFromUnresolvedCall(GrCall callExpression, PsiParameter[] parameters, TIntArrayList parametersToRemove) {
final GrExpression[] arguments = callExpression.getExpressionArguments();
final GrClosableBlock[] closureArguments = callExpression.getClosureArguments();
final GrNamedArgument[] namedArguments = callExpression.getNamedArguments();
final boolean hasNamedArgs;
if (namedArguments.length > 0) {
if (parameters.length > 0) {
final PsiType type = parameters[0].getType();
hasNamedArgs = InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_UTIL_MAP);
} else {
hasNamedArgs = false;
}
} else {
hasNamedArgs = false;
}
parametersToRemove.forEachDescending(new TIntProcedure() {
@Override
public boolean execute(int paramNum) {
try {
if (paramNum == 0 && hasNamedArgs) {
for (GrNamedArgument namedArgument : namedArguments) {
namedArgument.delete();
}
} else {
if (hasNamedArgs)
paramNum--;
if (paramNum < arguments.length) {
arguments[paramNum].delete();
} else if (paramNum < arguments.length + closureArguments.length) {
closureArguments[paramNum - arguments.length].delete();
}
}
} catch (IncorrectOperationException e) {
LOG.error(e);
}
return true;
}
});
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock in project intellij-community by JetBrains.
the class GroovyIntroduceParameterMethodUsagesProcessor method removeParamsFromUnresolvedCall.
private static void removeParamsFromUnresolvedCall(GrCall callExpression, IntroduceParameterData data) {
final GrExpression[] arguments = callExpression.getExpressionArguments();
final GrClosableBlock[] closureArguments = callExpression.getClosureArguments();
final GrNamedArgument[] namedArguments = callExpression.getNamedArguments();
final boolean hasNamedArgs;
if (namedArguments.length > 0) {
final PsiMethod method = data.getMethodToSearchFor();
final PsiParameter[] parameters = method.getParameterList().getParameters();
if (parameters.length > 0) {
final PsiType type = parameters[0].getType();
hasNamedArgs = InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_UTIL_MAP);
} else {
hasNamedArgs = false;
}
} else {
hasNamedArgs = false;
}
data.getParametersToRemove().forEachDescending(new TIntProcedure() {
@Override
public boolean execute(int paramNum) {
try {
if (paramNum == 0 && hasNamedArgs) {
for (GrNamedArgument namedArgument : namedArguments) {
namedArgument.delete();
}
} else {
if (hasNamedArgs)
paramNum--;
if (paramNum < arguments.length) {
arguments[paramNum].delete();
} else if (paramNum < arguments.length + closureArguments.length) {
closureArguments[paramNum - arguments.length].delete();
}
}
} catch (IncorrectOperationException e) {
LOG.error(e);
}
return true;
}
});
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock in project intellij-community by JetBrains.
the class GroovyLineMarkerProvider method getGroovyCategory.
private static int getGroovyCategory(@NotNull PsiElement element, @NotNull CharSequence documentChars) {
if (element instanceof GrVariableDeclarationImpl) {
GrVariable[] variables = ((GrVariableDeclarationImpl) element).getVariables();
if (variables.length == 1 && variables[0] instanceof GrField && variables[0].getInitializerGroovy() instanceof GrClosableBlock) {
return 2;
}
}
if (element instanceof GrField || element instanceof GrTypeParameter)
return 1;
if (element instanceof GrTypeDefinition || element instanceof GrClassInitializer)
return 2;
if (element instanceof GrMethod) {
if (((GrMethod) element).hasModifierProperty(PsiModifier.ABSTRACT) && !(((GrMethod) element).getBlock() != null && GrTraitUtil.isTrait(((GrMethod) element).getContainingClass()))) {
return 1;
}
TextRange textRange = element.getTextRange();
int start = textRange.getStartOffset();
int end = Math.min(documentChars.length(), textRange.getEndOffset());
int crlf = StringUtil.getLineBreakCount(documentChars.subSequence(start, end));
return crlf == 0 ? 1 : 2;
}
return 0;
}
Aggregations