mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
provide context for new methods: createMethod(name, returnType, context)
This commit is contained in:
@@ -475,7 +475,7 @@ public class GenerateMembersUtil {
|
||||
if (method.isConstructor()) {
|
||||
return factory.createConstructor(method.getName(), target);
|
||||
}
|
||||
return factory.createMethodFromText("public void " + method.getName() + "(){}", target);
|
||||
return factory.createMethod(method.getName(), PsiType.VOID, target);
|
||||
}
|
||||
|
||||
private static void substituteReturnType(@NotNull PsiManager manager,
|
||||
|
||||
@@ -84,6 +84,9 @@ public interface JVMElementFactory {
|
||||
@NotNull
|
||||
PsiMethod createMethod(@NotNull @NonNls String name, PsiType returnType) throws IncorrectOperationException;
|
||||
|
||||
@NotNull
|
||||
PsiMethod createMethod(@NotNull @NonNls String name, PsiType returnType, PsiElement context) throws IncorrectOperationException;
|
||||
|
||||
/**
|
||||
* Creates an empty constructor.
|
||||
*
|
||||
|
||||
@@ -247,6 +247,12 @@ public class PsiElementFactoryImpl extends PsiJavaParserFacadeImpl implements Ps
|
||||
return (PsiMethod)CodeStyleManager.getInstance(myManager.getProject()).reformat(method);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiMethod createMethod(@NotNull @NonNls String name, PsiType returnType, PsiElement context) throws IncorrectOperationException {
|
||||
return createMethodFromText("public " + returnType.getCanonicalText(true) + " " + name + "() {}", context);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiMethod createConstructor() {
|
||||
|
||||
+4
@@ -265,6 +265,10 @@ public abstract class GroovyPsiElementFactory implements JVMElementFactory {
|
||||
@NotNull
|
||||
public abstract GrMethod createMethod(@NotNull @NonNls String name, @Nullable PsiType returnType) throws IncorrectOperationException;
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public abstract GrMethod createMethod(@NotNull @NonNls String name, @Nullable PsiType returnType, @Nullable PsiElement context) throws IncorrectOperationException;
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public abstract GrMethod createConstructor();
|
||||
|
||||
+7
-1
@@ -1016,6 +1016,12 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
|
||||
@NotNull
|
||||
@Override
|
||||
public GrMethod createMethod(@NotNull @NonNls String name, @Nullable PsiType returnType) throws IncorrectOperationException {
|
||||
return createMethod(name, returnType, null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public GrMethod createMethod(@NotNull @NonNls String name, PsiType returnType, PsiElement context) throws IncorrectOperationException {
|
||||
StringBuilder builder = StringBuilderSpinAllocator.alloc();
|
||||
try {
|
||||
builder.append("def <T>");
|
||||
@@ -1032,7 +1038,7 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
|
||||
builder.append('"');
|
||||
}
|
||||
builder.append("(){}");
|
||||
GrMethod method = createMethodFromText(builder);
|
||||
GrMethod method = createMethodFromText(builder.toString(), context);
|
||||
if (returnType != null) {
|
||||
method.getModifierList().setModifierProperty(GrModifier.DEF, false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user