use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder in project intellij-community by JetBrains.
the class JsonDelegateContributor method processDynamicMethods.
@Override
boolean processDynamicMethods(@NotNull PsiType qualifierType, @NotNull PsiClass clazz, @NotNull String name, @NotNull PsiElement place, @NotNull Processor<PsiElement> processor) {
JavaPsiFacade facade = JavaPsiFacade.getInstance(place.getProject());
GrLightMethodBuilder method;
PsiClassType genericType;
// T (T)
method = createMethod(name, clazz, place);
genericType = facade.getElementFactory().createType(method.addTypeParameter("T"));
method.addParameter("value", genericType, false);
method.setReturnType(genericType);
if (!processor.process(method))
return false;
// List<T> (T[], Closure)
method = createMethod(name, clazz, place);
genericType = facade.getElementFactory().createType(method.addTypeParameter("T"));
method.addParameter("values", genericType.createArrayType(), false);
method.addAndGetParameter("c", GROOVY_LANG_CLOSURE, false).putUserData(DELEGATES_TO_KEY, DELEGATE_FQN);
method.setReturnType(TypesUtil.createListType(place, genericType));
if (!processor.process(method))
return false;
// List<T> (Iterable<T>, Closure)
method = createMethod(name, clazz, place);
genericType = facade.getElementFactory().createType(method.addTypeParameter("T"));
method.addParameter("values", TypesUtil.createIterableType(place, genericType), false);
method.addAndGetParameter("c", GROOVY_LANG_CLOSURE, false).putUserData(DELEGATES_TO_KEY, DELEGATE_FQN);
method.setReturnType(TypesUtil.createListType(place, genericType));
if (!processor.process(method))
return false;
// List<T> (T...)
method = createMethod(name, clazz, place);
genericType = facade.getElementFactory().createType(method.addTypeParameter("T"));
method.addAndGetParameter("values", new PsiEllipsisType(genericType), false);
method.setReturnType(TypesUtil.createListType(place, genericType));
return processor.process(method);
}
use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder in project intellij-community by JetBrains.
the class StreamingJsonBuilderContributor method createMethod.
@NotNull
private static GrLightMethodBuilder createMethod(@NotNull String name, @NotNull PsiElement place, @NotNull PsiType returnType, @NotNull PsiClass clazz) {
GrLightMethodBuilder method = new GrLightMethodBuilder(place.getManager(), name);
method.setModifiers(GrModifierFlags.PUBLIC_MASK);
method.setReturnType(returnType);
UtilsKt.setContainingClass(method, clazz);
method.setOriginInfo(ORIGIN_INFO);
return method;
}
use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder in project intellij-community by JetBrains.
the class SpockMemberContributor method processDynamicElements.
@Override
public void processDynamicElements(@NotNull PsiType qualifierType, PsiClass aClass, @NotNull PsiScopeProcessor processor, @NotNull PsiElement place, @NotNull ResolveState state) {
ElementClassHint classHint = processor.getHint(ElementClassHint.KEY);
if (ResolveUtil.shouldProcessProperties(classHint)) {
GrMethod method = PsiTreeUtil.getParentOfType(place, GrMethod.class);
if (method == null)
return;
if (aClass != method.getContainingClass())
return;
Map<String, SpockVariableDescriptor> cachedValue = SpockUtils.getVariableMap(method);
String nameHint = ResolveUtil.getNameHint(processor);
if (nameHint == null) {
for (SpockVariableDescriptor spockVar : cachedValue.values()) {
if (!processor.execute(spockVar.getVariable(), state))
return;
}
} else {
SpockVariableDescriptor spockVar = cachedValue.get(nameHint);
if (spockVar != null && spockVar.getNavigationElement() != place) {
if (!processor.execute(spockVar.getVariable(), state))
return;
}
}
}
if (ResolveUtil.shouldProcessMethods(classHint)) {
String nameHint = ResolveUtil.getNameHint(processor);
if (nameHint == null) {
nameHint = place instanceof GrReferenceExpression ? ((GrReferenceExpression) place).getReferenceName() : null;
if (nameHint != null)
nameHint = GroovyPropertyUtils.getGetterNameNonBoolean(nameHint);
}
if ("get_".equals(nameHint)) {
GrLightMethodBuilder m = new GrLightMethodBuilder(aClass.getManager(), "get_");
m.setReturnType(null);
if (!processor.execute(m, state))
return;
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder in project intellij-community by JetBrains.
the class GrTraitUtil method createTraitMethodFromCompiledHelperMethod.
private static PsiMethod createTraitMethodFromCompiledHelperMethod(PsiMethod compiledMethod, ClsClassImpl trait) {
final GrLightMethodBuilder result = new GrLightMethodBuilder(trait.getManager(), compiledMethod.getName());
result.setOriginInfo("via @Trait");
result.addModifier(PsiModifier.STATIC);
for (PsiTypeParameter parameter : compiledMethod.getTypeParameters()) {
result.getTypeParameterList().addParameter(parameter);
}
final PsiTypeVisitor<PsiType> corrector = createCorrector(compiledMethod, trait);
final PsiParameter[] methodParameters = compiledMethod.getParameterList().getParameters();
for (int i = 1; i < methodParameters.length; i++) {
final PsiParameter originalParameter = methodParameters[i];
final PsiType correctedType = originalParameter.getType().accept(corrector);
final String name = originalParameter.getName();
assert name != null : compiledMethod;
result.addParameter(name, correctedType, false);
}
for (PsiClassType type : compiledMethod.getThrowsList().getReferencedTypes()) {
final PsiType correctedType = type.accept(corrector);
result.getThrowsList().addReference(correctedType instanceof PsiClassType ? (PsiClassType) correctedType : type);
}
final PsiType originalType = compiledMethod.getReturnType();
result.setReturnType(originalType == null ? null : originalType.accept(corrector));
final PsiClass traitSource = trait.getSourceMirrorClass();
final PsiMethod sourceMethod = traitSource == null ? null : traitSource.findMethodBySignature(result, false);
result.setNavigationElement(sourceMethod != null ? sourceMethod : compiledMethod);
return result;
}
use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder in project intellij-community by JetBrains.
the class GdkMethodUtil method createMethod.
@NotNull
private static GrMethod createMethod(@NotNull GrClosureSignature signature, @NotNull String name, @NotNull GrAssignmentExpression statement, @NotNull PsiClass closure) {
final GrLightMethodBuilder builder = new GrLightMethodBuilder(statement.getManager(), name);
GrClosureParameter[] parameters = signature.getParameters();
for (int i = 0; i < parameters.length; i++) {
GrClosureParameter parameter = parameters[i];
final String parameterName = parameter.getName() != null ? parameter.getName() : "p" + i;
final PsiType type = parameter.getType() != null ? parameter.getType() : TypesUtil.getJavaLangObject(statement);
builder.addParameter(parameterName, type, parameter.isOptional());
}
builder.setNavigationElement(statement.getLValue());
builder.setReturnType(signature.getReturnType());
builder.setContainingClass(closure);
return builder;
}
Aggregations