use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrConstructorInvocation in project intellij-community by JetBrains.
the class GroovyIntroduceParameterMethodUsagesProcessor method processAddSuperCall.
@Override
public boolean processAddSuperCall(IntroduceParameterData data, UsageInfo usage, UsageInfo[] usages) throws IncorrectOperationException {
if (!(usage.getElement() instanceof GrMethod) || !isGroovyUsage(usage))
return true;
GrMethod constructor = (GrMethod) usage.getElement();
if (!constructor.isConstructor())
return true;
final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(data.getProject());
GrConstructorInvocation superCall = factory.createConstructorInvocation("super();");
GrOpenBlock body = constructor.getBlock();
final GrStatement[] statements = body.getStatements();
if (statements.length > 0) {
superCall = (GrConstructorInvocation) body.addStatementBefore(superCall, statements[0]);
} else {
superCall = (GrConstructorInvocation) body.addStatementBefore(superCall, null);
}
processChangeMethodUsage(data, new UsageInfo(superCall), usages);
return false;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrConstructorInvocation in project intellij-community by JetBrains.
the class StubGenerator method writeConstructor.
@Override
public void writeConstructor(final StringBuilder text, PsiMethod constructor, boolean isEnum) {
LOG.assertTrue(constructor.isConstructor());
if (!isEnum) {
text.append("public ");
//writeModifiers(text, constructor.getModifierList(), JAVA_MODIFIERS);
}
/************* name **********/
//append constructor name
text.append(constructor.getName());
/************* parameters **********/
GenerationUtil.writeParameterList(text, constructor.getParameterList().getParameters(), classNameProvider, null);
final Set<String> throwsTypes = collectThrowsTypes(constructor, new THashSet<>());
if (!throwsTypes.isEmpty()) {
text.append("throws ").append(StringUtil.join(throwsTypes, ", ")).append(' ');
}
/************* body **********/
text.append("{\n");
if (constructor instanceof GrReflectedMethod) {
constructor = ((GrReflectedMethod) constructor).getBaseMethod();
}
if (constructor instanceof GrMethod) {
final GrConstructorInvocation invocation = PsiImplUtil.getChainingConstructorInvocation((GrMethod) constructor);
if (invocation != null) {
final GroovyResolveResult resolveResult = resolveChainingConstructor((GrMethod) constructor);
if (resolveResult != null) {
text.append(invocation.isSuperCall() ? "super(" : "this(");
writeStubConstructorInvocation(text, (PsiMethod) resolveResult.getElement(), resolveResult.getSubstitutor(), invocation);
text.append(");");
}
} else if (constructor instanceof LightElement) {
writeStubConstructorInvocation(constructor, text);
}
}
text.append("\n}\n");
}
Aggregations