use of org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter in project intellij-community by JetBrains.
the class GrClosableBlockImpl method addParameter.
@Override
public GrParameter addParameter(GrParameter parameter) {
GrParameterList parameterList = getParameterList();
if (getArrow() == null) {
final GrParameterList newParamList = (GrParameterList) addAfter(parameterList, getLBrace());
parameterList.delete();
ASTNode next = newParamList.getNode().getTreeNext();
getNode().addLeaf(GroovyTokenTypes.mCLOSABLE_BLOCK_OP, "->", next);
return (GrParameter) newParamList.add(parameter);
}
return (GrParameter) parameterList.add(parameter);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter in project intellij-community by JetBrains.
the class GroovyPropertyUtils method generateSetterPrototype.
public static GrMethod generateSetterPrototype(PsiField field) {
Project project = field.getProject();
JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(project);
GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(project);
String name = field.getName();
boolean isStatic = field.hasModifierProperty(PsiModifier.STATIC);
VariableKind kind = codeStyleManager.getVariableKind(field);
String propertyName = codeStyleManager.variableNameToPropertyName(name, kind);
String setName = getSetterName(field.getName());
final PsiClass containingClass = field.getContainingClass();
try {
GrMethod setMethod = factory.createMethod(setName, PsiType.VOID);
String parameterName = codeStyleManager.propertyNameToVariableName(propertyName, VariableKind.PARAMETER);
final PsiType type = field instanceof GrField ? ((GrField) field).getDeclaredType() : field.getType();
GrParameter param = factory.createParameter(parameterName, type);
annotateWithNullableStuff(field, param);
setMethod.getParameterList().add(param);
PsiUtil.setModifierProperty(setMethod, PsiModifier.STATIC, isStatic);
@NonNls StringBuilder builder = new StringBuilder();
if (name.equals(parameterName)) {
if (!isStatic) {
builder.append("this.");
} else {
String className = containingClass.getName();
if (className != null) {
builder.append(className);
builder.append(".");
}
}
}
builder.append(name);
builder.append("=");
builder.append(parameterName);
builder.append("\n");
GrCodeBlock body = factory.createMethodBodyFromText(builder.toString());
setMethod.getBlock().replace(body);
return setMethod;
} catch (IncorrectOperationException e) {
LOG.error(e);
return null;
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter in project intellij-community by JetBrains.
the class GrReflectedMethodImpl method initParameterList.
private void initParameterList(GrParameter[] parameters, int optionalParams, PsiClassType categoryType) {
final GrLightParameterListBuilder parameterList = (GrLightParameterListBuilder) getParameterList();
List<GrParameter> skipped = new ArrayList<>();
if (categoryType != null) {
parameterList.addParameter(new GrLightParameter(CATEGORY_PARAMETER_NAME, categoryType, this));
}
for (GrParameter parameter : parameters) {
if (parameter.isOptional()) {
if (optionalParams < 1) {
skipped.add(parameter);
continue;
}
optionalParams--;
}
parameterList.addParameter(createLightParameter(parameter));
}
LOG.assertTrue(optionalParams == 0);
mySkippedParameters = skipped.toArray(new GrParameter[skipped.size()]);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter in project intellij-community by JetBrains.
the class GrMethodBaseImpl method getNamedParameters.
@Override
@NotNull
public Map<String, NamedArgumentDescriptor> getNamedParameters() {
final GrMethodStub stub = getStub();
if (stub != null) {
String[] namedParameters = stub.getNamedParameters();
if (namedParameters.length == 0)
return Collections.emptyMap();
Map<String, NamedArgumentDescriptor> result = ContainerUtil.newHashMap();
for (String parameter : namedParameters) {
result.put(parameter, GrNamedArgumentSearchVisitor.CODE_NAMED_ARGUMENTS_DESCR);
}
return result;
}
GrOpenBlock body = getBlock();
if (body == null)
return Collections.emptyMap();
GrParameter[] parameters = getParameters();
if (parameters.length == 0)
return Collections.emptyMap();
GrParameter firstParameter = parameters[0];
PsiType type = firstParameter.getTypeGroovy();
GrTypeElement typeElement = firstParameter.getTypeElementGroovy();
if (type != null && typeElement != null && type.getPresentableText() != null && !type.getPresentableText().endsWith("Map")) {
return Collections.emptyMap();
}
GrNamedArgumentSearchVisitor visitor = new GrNamedArgumentSearchVisitor(firstParameter.getNameIdentifierGroovy().getText());
body.accept(visitor);
return visitor.getResult();
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter in project intellij-community by JetBrains.
the class GrReflectedMethodImpl method doCreateReflectedMethods.
@NotNull
public static GrReflectedMethod[] doCreateReflectedMethods(@NotNull GrMethod targetMethod, @Nullable PsiClassType categoryType, @NotNull GrParameter[] parameters) {
int count = 0;
for (GrParameter parameter : parameters) {
if (parameter.isOptional())
count++;
}
if (count == 0 && categoryType == null)
return GrReflectedMethod.EMPTY_ARRAY;
final GrReflectedMethod[] methods = new GrReflectedMethod[count + 1];
for (int i = 0; i <= count; i++) {
methods[i] = new GrReflectedMethodImpl(targetMethod, parameters, count - i, categoryType);
}
return methods;
}
Aggregations