create parameter be name and type in context: now also for java

This commit is contained in:
Anna Kozlova
2012-11-01 14:43:04 +01:00
parent 813034ec6f
commit f8fe88154c
4 changed files with 15 additions and 1 deletions
@@ -111,6 +111,7 @@ public interface JVMElementFactory {
*/
@NotNull
PsiParameter createParameter(@NotNull @NonNls String name, PsiType type) throws IncorrectOperationException;
PsiParameter createParameter(@NotNull @NonNls String name, PsiType type, PsiElement context) throws IncorrectOperationException;
/**
* Creates a parameter list from the specified parameter names and types.
@@ -282,6 +282,13 @@ public class PsiElementFactoryImpl extends PsiJavaParserFacadeImpl implements Ps
return (PsiParameter)codeStyleManager.reformat(parameter);
}
@Override
public PsiParameter createParameter(@NotNull @NonNls String name, PsiType type, PsiElement context) throws IncorrectOperationException {
final PsiMethod psiMethod = createMethodFromText("void f(" + type.getCanonicalText() + " " + name + ") {}", context);
final PsiParameter[] parameters = psiMethod.getParameterList().getParameters();
return parameters[0];
}
@NotNull
@Override
public PsiCodeBlock createCodeBlock() {
@@ -978,6 +978,12 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
return createParameter(name, type == null ? null : type.getCanonicalText(), null, null);
}
@NotNull
@Override
public GrParameter createParameter(@NotNull @NonNls String name, @Nullable PsiType type, PsiElement context) throws IncorrectOperationException {
return createParameter(name, type == null ? null : type.getCanonicalText(), null, context instanceof GroovyPsiElement ? (GroovyPsiElement)context : null);
}
@NotNull
@Override
public PsiParameterList createParameterList(@NotNull @NonNls String[] names, @NotNull PsiType[] types) throws IncorrectOperationException {
@@ -44,7 +44,7 @@ public class ClosureSyntheticParameter extends GrLightParameter implements Navig
public PsiElement setName(@NotNull String newName) throws IncorrectOperationException {
if (!newName.equals(getName())) {
GrParameter parameter = GroovyPsiElementFactory.getInstance(getProject()).createParameter(newName, null, null);
GrParameter parameter = GroovyPsiElementFactory.getInstance(getProject()).createParameter(newName, (String)null, null);
myClosure.addParameter(parameter);
}
return this;