use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightParameter in project intellij-community by JetBrains.
the class GradleResolverUtil method createMethodWithClosure.
@Nullable
public static GrLightMethodBuilder createMethodWithClosure(@NotNull String name, @Nullable String returnType, @Nullable String closureTypeParameter, @NotNull PsiElement place) {
PsiClassType closureType;
PsiClass closureClass = JavaPsiFacade.getInstance(place.getProject()).findClass(GroovyCommonClassNames.GROOVY_LANG_CLOSURE, place.getResolveScope());
if (closureClass == null)
return null;
if (closureClass.getTypeParameters().length != 1) {
GradleLog.LOG.debug(String.format("Unexpected type parameters found for closureClass(%s) : (%s)", closureClass, Arrays.toString(closureClass.getTypeParameters())));
return null;
}
PsiElementFactory factory = JavaPsiFacade.getElementFactory(place.getManager().getProject());
if (closureTypeParameter != null) {
PsiClassType closureClassTypeParameter = factory.createTypeByFQClassName(closureTypeParameter, place.getResolveScope());
closureType = factory.createType(closureClass, closureClassTypeParameter);
} else {
PsiClassType closureClassTypeParameter = factory.createTypeByFQClassName(CommonClassNames.JAVA_LANG_OBJECT, place.getResolveScope());
closureType = factory.createType(closureClass, closureClassTypeParameter);
}
GrLightMethodBuilder methodWithClosure = new GrLightMethodBuilder(place.getManager(), name);
GrLightParameter closureParameter = new GrLightParameter("closure", closureType, methodWithClosure);
methodWithClosure.addParameter(closureParameter);
PsiClassType retType = factory.createTypeByFQClassName(returnType != null ? returnType : CommonClassNames.JAVA_LANG_OBJECT, place.getResolveScope());
methodWithClosure.setReturnType(retType);
methodWithClosure.setContainingClass(retType.resolve());
return methodWithClosure;
}
use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightParameter in project intellij-community by JetBrains.
the class StreamingJsonBuilderContributor method addClosureParameter.
protected void addClosureParameter(GrLightMethodBuilder method) {
GrLightParameter closureParam = method.addAndGetParameter("closure", GROOVY_LANG_CLOSURE);
closureParam.putUserData(DELEGATES_TO_KEY, getDelegateClassName());
closureParam.putUserData(DELEGATES_TO_STRATEGY_KEY, Closure.OWNER_FIRST);
}
use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightParameter in project intellij-community by JetBrains.
the class GroovyFileImpl method getSyntheticArgsParameter.
private GrParameter getSyntheticArgsParameter() {
GrParameter parameter = mySyntheticArgsParameter;
if (parameter == null) {
final PsiType psiType = JavaPsiFacade.getElementFactory(getProject()).createTypeFromText("java.lang.String[]", this);
parameter = new GrLightParameter(SYNTHETIC_PARAMETER_NAME, psiType, this);
mySyntheticArgsParameter = parameter;
}
return parameter;
}
use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightParameter in project intellij-community by JetBrains.
the class ResolveUtil method findDuplicate.
public static PsiNamedElement findDuplicate(@NotNull GrVariable variable) {
if (isScriptField(variable)) {
final String name = variable.getName();
final GroovyScriptClass script = (GroovyScriptClass) ((GroovyFile) variable.getContainingFile()).getScriptClass();
assert script != null;
List<GrField> duplicates = ContainerUtil.filter(script.getFields(), (GrField f) -> {
if (!(f instanceof GrScriptField))
return false;
if (!name.equals(f.getName()))
return false;
if (((GrScriptField) f).getOriginalVariable() == variable)
return false;
return true;
});
return duplicates.size() > 0 ? duplicates.get(0) : null;
} else {
PsiNamedElement duplicate = resolveExistingElement(variable, new DuplicateVariablesProcessor(variable), GrVariable.class);
final PsiElement context1 = variable.getContext();
if (duplicate == null && variable instanceof GrParameter && context1 != null) {
final PsiElement context = context1.getContext();
if (context instanceof GrClosableBlock || context instanceof GrMethod && !(context.getParent() instanceof GroovyFile) || context instanceof GrTryCatchStatement) {
duplicate = resolveExistingElement(context.getParent(), new DuplicateVariablesProcessor(variable), GrVariable.class);
}
}
if (duplicate instanceof GrLightParameter && "args".equals(duplicate.getName())) {
return null;
} else {
return duplicate;
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightParameter in project intellij-community by JetBrains.
the class GrInnerClassConstructorUtil method addEnclosingInstanceParam.
@NotNull
public static GrParameter[] addEnclosingInstanceParam(@NotNull GrMethod method, @NotNull PsiClass enclosingClass, @NotNull GrParameter[] originalParams, boolean isOptional) {
final GrParameter[] parameters = new GrParameter[originalParams.length + 1];
final PsiClassType enclosingClassType = JavaPsiFacade.getElementFactory(method.getProject()).createType(enclosingClass, PsiSubstitutor.EMPTY);
final GrLightParameter enclosing = new GrLightParameter("enclosing", enclosingClassType, method);
if (isOptional) {
enclosing.setOptional(true);
enclosing.setInitializerGroovy(GroovyPsiElementFactory.getInstance(method.getProject()).createExpressionFromText("null"));
}
parameters[0] = enclosing;
System.arraycopy(originalParams, 0, parameters, 1, originalParams.length);
return parameters;
}
Aggregations