diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/GroovyPsiElementFactory.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/GroovyPsiElementFactory.java index 0f0b209d4511..74ce1e824592 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/GroovyPsiElementFactory.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/GroovyPsiElementFactory.java @@ -98,13 +98,13 @@ public abstract class GroovyPsiElementFactory { return createReferenceElementFromText(refName, null); } - public abstract GrCodeReferenceElement createReferenceElementFromText(String refName, PsiElement context); + public abstract GrCodeReferenceElement createReferenceElementFromText(String refName, @Nullable PsiElement context); public GrExpression createExpressionFromText(String exprText) { return createExpressionFromText(exprText, null); } - public abstract GrExpression createExpressionFromText(String exprText, PsiElement context); + public abstract GrExpression createExpressionFromText(String exprText, @Nullable PsiElement context); public abstract GrVariableDeclaration createFieldDeclaration(String[] modifiers, String identifier, GrExpression initializer, PsiType type); public abstract GrVariableDeclaration createFieldDeclarationFromText(String text); @@ -126,13 +126,13 @@ public abstract class GroovyPsiElementFactory { public abstract GrClosableBlock createClosureFromText(String s) throws IncorrectOperationException; - public GrParameter createParameter(String name, @Nullable String typeText, GroovyPsiElement context) throws IncorrectOperationException { + public GrParameter createParameter(String name, @Nullable String typeText, @Nullable GroovyPsiElement context) throws IncorrectOperationException { return createParameter(name, typeText, null, context); } public abstract GrParameter createParameter(String name, @Nullable String typeText, - String initializer, + @Nullable String initializer, GroovyPsiElement context) throws IncorrectOperationException; public abstract GrCodeReferenceElement createTypeOrPackageReference(String qName); @@ -146,7 +146,7 @@ public abstract class GroovyPsiElementFactory { return createTypeElement(typeText, null); } - public abstract GrTypeElement createTypeElement(String typeText, PsiElement context); + public abstract GrTypeElement createTypeElement(String typeText, @Nullable PsiElement context); public abstract GrParenthesizedExpression createParenthesizedExpr(GrExpression newExpr); @@ -162,7 +162,7 @@ public abstract class GroovyPsiElementFactory { public abstract PsiElement createDotToken(String newDot); - public abstract GrMethod createMethodFromText(String methodText, PsiElement context); + public abstract GrMethod createMethodFromText(String methodText, @Nullable PsiElement context); public GrMethod createMethodFromText(String methodText) { return createMethodFromText(methodText, null); @@ -170,7 +170,7 @@ public abstract class GroovyPsiElementFactory { public abstract GrAnnotation createAnnotationFromText(String annoText); - public abstract GroovyFile createGroovyFile(String text, boolean isPhisical, PsiElement context); + public abstract GroovyFile createGroovyFile(String text, boolean isPhysical, PsiElement context); public abstract GrMethod createMethodFromText(String modifier, String name, String type, String[] paramTypes, PsiElement context); @@ -178,7 +178,7 @@ public abstract class GroovyPsiElementFactory { String[] paramTypes, String[] paramNames, String body, - PsiElement context); + @Nullable PsiElement context); public GrMethod createConstructorFromText(@NotNull String constructorName, String[] paramTypes, String[] paramNames, String body) { return createConstructorFromText(constructorName, paramTypes, paramNames, body, null); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyPsiElementFactoryImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyPsiElementFactoryImpl.java index 84e48f951fc8..fced0e02fd4e 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyPsiElementFactoryImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyPsiElementFactoryImpl.java @@ -147,7 +147,7 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory { public GrExpression createExpressionFromText(String text, PsiElement context) { GroovyFileImpl file = (GroovyFileImpl)createGroovyFile(text, false, context); assert file.getTopStatements()[0] instanceof GrExpression; - return (GrExpression) ((GroovyFileBase) file).getTopStatements()[0]; + return (GrExpression) file.getTopStatements()[0]; } public GrVariableDeclaration createVariableDeclaration(@Nullable String[] modifiers, @@ -182,6 +182,7 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory { !GroovyConfigUtils.getInstance().isVersionAtLeast(initializer, GroovyConfigUtils.GROOVY1_8)) { initializer = createMethodCallByAppCall((GrApplicationStatement)initializer); } + assert initializer != null; text.append(" = ").append(initializer.getText()); } @@ -399,7 +400,7 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory { return ((GrLabeledStatement)definition).getLabel(); } - public GrMethod createMethodFromText(@NotNull String methodText, PsiElement context) { + public GrMethod createMethodFromText(@NotNull String methodText, @Nullable PsiElement context) { GroovyFileImpl file = createDummyFile(methodText); if (context != null) { file.setContext(context); @@ -424,7 +425,7 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory { return createGroovyFile(idText, false, null); } - public GroovyFile createGroovyFile(String idText, boolean isPhysical, PsiElement context) { + public GroovyFile createGroovyFile(String idText, boolean isPhysical, @Nullable PsiElement context) { GroovyFileImpl file = createDummyFile(idText, isPhysical); file.setContext(context); return file; @@ -519,12 +520,12 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory { } - private static String generateMethodText(String modifier, + private static String generateMethodText(@Nullable String modifier, String name, - String type, + @Nullable String type, String[] paramTypes, String[] paramNames, - String body, + @Nullable String body, boolean isConstructor) { StringBuilder builder = new StringBuilder(); @@ -590,8 +591,6 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory { } public GrDocComment createDocCommentFromText(String text) { - StringBuilder builder = new StringBuilder(); - builder.append(text); return (GrDocComment)createGroovyFile(text).getFirstChild(); }