JVMElementFactory methods

This commit is contained in:
Maxim.Medvedev
2012-05-21 12:26:10 +04:00
parent 617cc47aef
commit 65af46598a
3 changed files with 196 additions and 3 deletions
@@ -15,11 +15,15 @@
*/
package com.intellij.psi;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Map;
/**
* @author Medvedev Max
*/
@@ -128,12 +132,27 @@ public interface JVMElementFactory {
@NotNull
PsiElement createExpressionFromText(@NotNull @NonNls String text, @Nullable PsiElement context) throws IncorrectOperationException;
/**
* Creates new reference element by type
* @param type the type for which reference element should be creted
* @return the reference element
*/
@NotNull
PsiElement createReferenceElementByType(PsiClassType type);
/**
* Creates empty type parameter list
* @return the empty type parameter list
*/
@NotNull
PsiTypeParameterList createTypeParameterList();
/**
* Creates new type parameter with the specified name and super types
* @param name the name which the type parameter should have
* @param superTypes the super types of the type parameter
* @return the new type parameter
*/
@NotNull
PsiTypeParameter createTypeParameter(String name, PsiClassType[] superTypes);
@@ -145,4 +164,102 @@ public interface JVMElementFactory {
*/
@NotNull
PsiClassType createType(@NotNull PsiClass aClass);
/**
* Creates an empty annotation type with the specified name.
*
* @param name the name of the annotation type to create.
* @return the created annotation type instance.
* @throws com.intellij.util.IncorrectOperationException if <code>name</code> is not a valid Java identifier.
*/
@NotNull
PsiClass createAnnotationType(@NotNull @NonNls String name) throws IncorrectOperationException;
/**
* Creates an empty constructor with a given name.
*
* @param name the name of the constructor to create.
* @return the created constructor instance.
*/
@NotNull
PsiMethod createConstructor(@NotNull @NonNls String name);
/**
* Creates a class type for the specified class, using the specified substitutor
* to replace generic type parameters on the class.
*
* @param resolve the class for which the class type is created.
* @param substitutor the substitutor to use.
* @return the class type instance.
*/
@NotNull
PsiClassType createType(@NotNull PsiClass resolve, @NotNull PsiSubstitutor substitutor);
/*
additional languageLevel parameter to memorize language level for allowing/prohibiting boxing/unboxing
*/
@NotNull
PsiClassType createType(@NotNull PsiClass resolve, @NotNull PsiSubstitutor substitutor, @NotNull LanguageLevel languageLevel);
@NotNull
PsiClassType createType(@NotNull PsiClass resolve,
@NotNull PsiSubstitutor substitutor,
@NotNull LanguageLevel languageLevel,
@NotNull PsiAnnotation[] annotations);
@NotNull
PsiClassType createType(@NotNull PsiClass aClass, PsiType parameters);
@NotNull
PsiClassType createType(@NotNull PsiClass aClass, PsiType... parameters);
/**
* Creates a substitutor for the specified class which replaces all type parameters
* with their corresponding raw types.
*
* @param owner the class or method for which the substitutor is created.
* @return the substitutor instance.
*/
@NotNull
PsiSubstitutor createRawSubstitutor(@NotNull PsiTypeParameterListOwner owner);
/**
* Creates a substitutor which uses the specified mapping between type parameters and types.
*
* @param map the type parameter to type map used by the substitutor.
* @return the substitutor instance.
*/
@NotNull
PsiSubstitutor createSubstitutor(@NotNull Map<PsiTypeParameter, PsiType> map);
/**
* Returns the primitive type instance for the specified type name.
*
* @param text the name of a Java primitive type (for example, <code>int</code>)
* @return the primitive type instance, or null if <code>name</code> is not a valid
* primitive type name.
*/
@Nullable
PsiPrimitiveType createPrimitiveType(@NotNull String text);
/**
* The same as {@link #createTypeByFQClassName(String, com.intellij.psi.search.GlobalSearchScope)}
* with {@link com.intellij.psi.search.GlobalSearchScope#allScope(com.intellij.openapi.project.Project)}.
*
* @param qName the full-qualified name of the class to create the reference to.
* @return the class type instance.
*/
@NotNull
PsiClassType createTypeByFQClassName(@NotNull @NonNls String qName);
/**
* Creates a class type referencing a class with the specified class name in the specified
* search scope.
*
* @param qName the full-qualified name of the class to create the reference to.
* @param resolveScope the scope in which the class is searched.
* @return the class type instance.
*/
@NotNull
PsiClassType createTypeByFQClassName(@NotNull @NonNls String qName, @NotNull GlobalSearchScope resolveScope);
}
@@ -172,7 +172,7 @@ public abstract class GroovyPsiElementFactory implements JVMElementFactory {
public abstract GrTypeElement createTypeElement(String typeText, @Nullable PsiElement context);
public abstract GrParenthesizedExpression createParenthesizedExpr(GrExpression newExpr);
public abstract GrParenthesizedExpression createParenthesizedExpr(GrExpression expression);
public abstract PsiElement createStringLiteralForReference(String text);
@@ -20,8 +20,10 @@ import com.intellij.lang.ASTNode;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.codeStyle.CodeEditUtil;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.ProjectScope;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.IncorrectOperationException;
@@ -64,6 +66,7 @@ import org.jetbrains.plugins.groovy.lang.psi.util.GrStringUtil;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* @author ven
@@ -407,8 +410,8 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
return JavaPsiFacade.getElementFactory(myProject).createType(aClass);
}
public GrParenthesizedExpression createParenthesizedExpr(GrExpression newExpr) {
return ((GrParenthesizedExpression) getInstance(myProject).createExpressionFromText("(" + newExpr.getText() + ")"));
public GrParenthesizedExpression createParenthesizedExpr(GrExpression expression) {
return ((GrParenthesizedExpression) createExpressionFromText("(" + expression.getText() + ")"));
}
public PsiElement createStringLiteralForReference(String text) {
@@ -957,4 +960,77 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory {
return method.getParameterList();
}
@NotNull
@Override
public PsiClass createAnnotationType(@NotNull @NonNls String name) throws IncorrectOperationException {
return createTypeDefinition("@interface " + name + "{}");
}
@NotNull
@Override
public PsiMethod createConstructor(@NotNull @NonNls String name) {
return createConstructorFromText(name, name + "(){}", null);
}
@NotNull
@Override
public PsiClassType createType(@NotNull PsiClass resolve, @NotNull PsiSubstitutor substitutor) {
return JavaPsiFacade.getElementFactory(myProject).createType(resolve, substitutor);
}
@NotNull
@Override
public PsiClassType createType(@NotNull PsiClass resolve, @NotNull PsiSubstitutor substitutor, @NotNull LanguageLevel languageLevel) {
return JavaPsiFacade.getElementFactory(myProject).createType(resolve, substitutor, languageLevel);
}
@NotNull
@Override
public PsiClassType createType(@NotNull PsiClass resolve,
@NotNull PsiSubstitutor substitutor,
@NotNull LanguageLevel languageLevel,
@NotNull PsiAnnotation[] annotations) {
return JavaPsiFacade.getElementFactory(myProject).createType(resolve, substitutor, languageLevel, annotations);
}
@NotNull
@Override
public PsiClassType createType(@NotNull PsiClass aClass, PsiType parameters) {
return JavaPsiFacade.getElementFactory(myProject).createType(aClass, parameters);
}
@NotNull
@Override
public PsiClassType createType(@NotNull PsiClass aClass, PsiType... parameters) {
return JavaPsiFacade.getElementFactory(myProject).createType(aClass, parameters);
}
@NotNull
@Override
public PsiSubstitutor createRawSubstitutor(@NotNull PsiTypeParameterListOwner owner) {
return JavaPsiFacade.getElementFactory(myProject).createRawSubstitutor(owner);
}
@NotNull
@Override
public PsiSubstitutor createSubstitutor(@NotNull Map<PsiTypeParameter, PsiType> map) {
return JavaPsiFacade.getElementFactory(myProject).createSubstitutor(map);
}
@Override
public PsiPrimitiveType createPrimitiveType(@NotNull String text) {
return JavaPsiFacade.getElementFactory(myProject).createPrimitiveType(text);
}
@NotNull
@Override
public PsiClassType createTypeByFQClassName(@NotNull @NonNls String qName) {
return JavaPsiFacade.getElementFactory(myProject).createTypeByFQClassName(qName);
}
@NotNull
@Override
public PsiClassType createTypeByFQClassName(@NotNull @NonNls String qName, @NotNull GlobalSearchScope resolveScope) {
return JavaPsiFacade.getElementFactory(myProject).createTypeByFQClassName(qName, resolveScope);
}
}