public interface PsiElementFactory extends PsiJavaParserFacade, JVMElementFactory
JavaPsiFacade.getElementFactory()
,
PsiFileFactory
Modifier and Type | Interface and Description |
---|---|
static class |
PsiElementFactory.SERVICE
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
PsiClass |
createAnnotationType(java.lang.String name)
Creates an empty annotation type with the specified name.
|
PsiCatchSection |
createCatchSection(PsiType exceptionType,
java.lang.String exceptionName,
PsiElement context)
Creates a
catch section for catching an exception of the specified
type and name. |
PsiClass |
createClass(java.lang.String name)
Creates an empty class with the specified name.
|
PsiClassInitializer |
createClassInitializer()
Creates an empty class initializer block.
|
PsiJavaCodeReferenceElement |
createClassReferenceElement(PsiClass aClass)
Creates a reference element resolving to the specified class.
|
PsiCodeBlock |
createCodeBlock()
Creates an empty Java code block.
|
PsiMethod |
createConstructor()
Creates an empty constructor.
|
PsiMethod |
createConstructor(java.lang.String name)
Creates an empty constructor with a given name.
|
PsiElement |
createDummyHolder(java.lang.String text,
IElementType type,
PsiElement context)
Create a lightweight PsiElement of given element type in a lightweight non-physical PsiFile (aka DummyHolder) in a given context.
|
PsiClass |
createEnum(java.lang.String name)
Creates an empty enum with the specified name.
|
PsiExpression |
createExpressionFromText(java.lang.String text,
PsiElement context)
Creates a Java expression from the specified text.
|
PsiField |
createField(java.lang.String name,
PsiType type)
Creates a field with the specified name and type.
|
PsiJavaCodeReferenceElement |
createFQClassNameReferenceElement(java.lang.String qName,
GlobalSearchScope resolveScope)
Creates a reference element resolving to the class with the specified name
in the specified search scope.
|
PsiIdentifier |
createIdentifier(java.lang.String text)
Creates a Java identifier with the specified text.
|
PsiImportStatement |
createImportStatement(PsiClass aClass)
Creates an import statement for importing the specified class.
|
PsiImportStatement |
createImportStatementOnDemand(java.lang.String packageName)
Creates an on-demand import statement for importing classes from the package with the specified name.
|
PsiImportStaticStatement |
createImportStaticStatement(PsiClass aClass,
java.lang.String memberName)
Creates an
import static statement for importing the specified member
from the specified class. |
PsiClass |
createInterface(java.lang.String name)
Creates an empty interface with the specified name.
|
PsiKeyword |
createKeyword(java.lang.String keyword)
Creates a Java keyword with the specified text.
|
PsiKeyword |
createKeyword(java.lang.String keyword,
PsiElement context) |
PsiMethod |
createMethod(java.lang.String name,
PsiType returnType)
Creates an empty method with the specified name and return type.
|
PsiJavaCodeReferenceElement |
createPackageReferenceElement(PsiPackage aPackage)
Creates a reference element resolving to the specified package.
|
PsiJavaCodeReferenceElement |
createPackageReferenceElement(java.lang.String packageName)
Creates a reference element resolving to the package with the specified name.
|
PsiPackageStatement |
createPackageStatement(java.lang.String name)
Creates a package statement for the specified package name.
|
PsiParameter |
createParameter(java.lang.String name,
PsiType type)
Creates a parameter with the specified name and type.
|
PsiParameterList |
createParameterList(java.lang.String [] names,
PsiType [] types)
Creates a parameter list from the specified parameter names and types.
|
PsiDocTag |
createParamTag(java.lang.String parameterName,
java.lang.String description)
Creates a PSI element for the "@param" JavaDoc tag.
|
PsiPrimitiveType |
createPrimitiveType(java.lang.String text)
Returns the primitive type instance for the specified type name.
|
PsiSubstitutor |
createRawSubstitutor(PsiSubstitutor baseSubstitutor,
PsiTypeParameter [] typeParameters) |
PsiSubstitutor |
createRawSubstitutor(PsiTypeParameterListOwner owner)
Creates a substitutor for the specified class which replaces all type parameters
with their corresponding raw types.
|
PsiClass |
createRecord(java.lang.String name)
Creates a record with no components with the specified name.
|
PsiJavaCodeReferenceElement |
createReferenceElementByFQClassName(java.lang.String qName,
GlobalSearchScope resolveScope)
Creates a reference element resolving to the class with the specified name
in the specified search scope.
|
PsiJavaCodeReferenceElement |
createReferenceElementByType(PsiClassType type)
Creates a reference element resolving to the specified class type.
|
PsiReferenceExpression |
createReferenceExpression(PsiClass aClass)
Creates a reference expression resolving to the specified class.
|
PsiReferenceExpression |
createReferenceExpression(PsiPackage aPackage)
Creates a reference expression resolving to the specified package.
|
PsiReferenceList |
createReferenceList(PsiJavaCodeReferenceElement [] references)
Creates a reference list element from the specified array of references.
|
PsiResourceVariable |
createResourceVariable(java.lang.String name,
PsiType type,
PsiExpression initializer,
PsiElement context)
Creates a resource variable (which can be inserted into the resource list of try-with-resources statement)
with the specified name, type and initializer
|
PsiSubstitutor |
createSubstitutor(java.util.Map<PsiTypeParameter,PsiType> map)
Creates a substitutor which uses the specified mapping between type parameters and types.
|
PsiClassType |
createType(PsiClass resolve,
PsiSubstitutor substitutor)
Creates a class type for the specified class, using the specified substitutor
to replace generic type parameters on the class.
|
PsiClassType |
createType(PsiClass resolve,
PsiSubstitutor substitutor,
LanguageLevel languageLevel)
Creates a class type for the specified class, using the specified substitutor
to replace generic type parameters on the class.
|
PsiClassType |
createType(PsiClass aClass,
PsiType... parameters) |
PsiClassType |
createType(PsiClass aClass,
PsiType parameters) |
PsiClassType |
createType(PsiJavaCodeReferenceElement classReference)
Creates a class type for the specified reference pointing to a class.
|
PsiClassType |
createTypeByFQClassName(java.lang.String qName)
|
PsiClassType |
createTypeByFQClassName(java.lang.String qName,
GlobalSearchScope resolveScope)
Creates a class type referencing a class with the specified class name in the specified
search scope.
|
PsiTypeElement |
createTypeElement(PsiType psiType)
Creates a type element referencing the specified type.
|
PsiDeclarationStatement |
createVariableDeclarationStatement(java.lang.String name,
PsiType type,
PsiExpression initializer)
Creates a local variable declaration statement with the specified name, type and initializer,
optionally without reformatting the declaration.
|
PsiDeclarationStatement |
createVariableDeclarationStatement(java.lang.String name,
PsiType type,
PsiExpression initializer,
PsiElement context)
Creates a local variable declaration statement with the specified name, type and initializer,
optionally without reformatting the declaration.
|
PsiClass |
getArrayClass(LanguageLevel languageLevel)
Returns a synthetic Java class containing methods which are defined on Java arrays.
|
PsiClassType |
getArrayClassType(PsiType componentType,
LanguageLevel languageLevel)
Returns the class type for a synthetic Java class containing methods which
are defined on Java arrays with the specified element type.
|
static PsiElementFactory |
getInstance(Project project) |
createAnnotationFromText, createClassFromText, createCodeBlockFromText, createCommentFromText, createDocCommentFromText, createDocCommentFromText, createDocTagFromText, createEnumConstantFromText, createFieldFromText, createMethodFromText, createMethodFromText, createModuleFromText, createModuleFromText, createModuleReferenceFromText, createModuleStatementFromText, createParameterFromText, createPrimitiveTypeFromText, createRecordHeaderFromText, createReferenceFromText, createResourceFromText, createStatementFromText, createTypeElementFromText, createTypeFromText, createTypeParameterFromText
createAnnotationFromText, createConstructor, createDocCommentFromText, createMethod, createMethodFromText, createParameter, createType, createTypeParameter, createTypeParameterList, isValidClassName, isValidFieldName, isValidLocalVariableName, isValidMethodName, isValidParameterName
static PsiElementFactory getInstance(Project project)
PsiClass createClass(java.lang.String name) throws IncorrectOperationException
createClass
in interface JVMElementFactory
IncorrectOperationException
- if name
is not a valid Java identifier.PsiClass createInterface(java.lang.String name) throws IncorrectOperationException
createInterface
in interface JVMElementFactory
IncorrectOperationException
- if name
is not a valid Java identifier.PsiClass createEnum(java.lang.String name) throws IncorrectOperationException
createEnum
in interface JVMElementFactory
IncorrectOperationException
- if name
is not a valid Java identifier.PsiClass createRecord(java.lang.String name) throws IncorrectOperationException
IncorrectOperationException
- if name
is not a valid Java identifier.PsiClass createAnnotationType(java.lang.String name) throws IncorrectOperationException
createAnnotationType
in interface JVMElementFactory
IncorrectOperationException
- if name
is not a valid Java identifier.PsiField createField(java.lang.String name, PsiType type) throws IncorrectOperationException
createField
in interface JVMElementFactory
IncorrectOperationException
- name
is not a valid Java identifier
or type
represents an invalid type.PsiMethod createMethod(java.lang.String name, PsiType returnType) throws IncorrectOperationException
createMethod
in interface JVMElementFactory
IncorrectOperationException
- name
is not a valid Java identifier
or type
represents an invalid type.PsiMethod createConstructor()
createConstructor
in interface JVMElementFactory
PsiMethod createConstructor(java.lang.String name)
createConstructor
in interface JVMElementFactory
PsiClassInitializer createClassInitializer() throws IncorrectOperationException
createClassInitializer
in interface JVMElementFactory
IncorrectOperationException
- in case of an internal error.PsiParameter createParameter(java.lang.String name, PsiType type) throws IncorrectOperationException
createParameter
in interface JVMElementFactory
IncorrectOperationException
- name
is not a valid Java identifier
or type
represents an invalid type.PsiCodeBlock createCodeBlock()
PsiClassType createType(PsiClass resolve, PsiSubstitutor substitutor)
createType
in interface JVMElementFactory
PsiClassType createType(PsiClass resolve, PsiSubstitutor substitutor, LanguageLevel languageLevel)
createType
in interface JVMElementFactory
languageLevel
- to memorize language level for allowing/prohibiting boxing/unboxing.resolve
- the class for which the class type is created.substitutor
- the substitutor to use.PsiClassType createType(PsiJavaCodeReferenceElement classReference)
PsiClassType createType(PsiClass aClass, PsiType parameters)
createType
in interface JVMElementFactory
PsiClassType createType(PsiClass aClass, PsiType... parameters)
createType
in interface JVMElementFactory
PsiSubstitutor createRawSubstitutor(PsiTypeParameterListOwner owner)
createRawSubstitutor
in interface JVMElementFactory
PsiSubstitutor createSubstitutor(java.util.Map<PsiTypeParameter,PsiType> map)
createSubstitutor
in interface JVMElementFactory
PsiPrimitiveType createPrimitiveType(java.lang.String text)
createPrimitiveType
in interface JVMElementFactory
text
- the name of a Java primitive type (for example, int
)null
if name
is not a valid
primitive type name.PsiClassType createTypeByFQClassName(java.lang.String qName)
createTypeByFQClassName(String, GlobalSearchScope)
with GlobalSearchScope.allScope(Project)
.createTypeByFQClassName
in interface JVMElementFactory
PsiClassType createTypeByFQClassName(java.lang.String qName, GlobalSearchScope resolveScope)
createTypeByFQClassName
in interface JVMElementFactory
PsiTypeElement createTypeElement(PsiType psiType)
PsiJavaCodeReferenceElement createReferenceElementByType(PsiClassType type)
createReferenceElementByType
in interface JVMElementFactory
type
- the class type to create the reference to.PsiJavaCodeReferenceElement createClassReferenceElement(PsiClass aClass)
PsiJavaCodeReferenceElement createReferenceElementByFQClassName(java.lang.String qName, GlobalSearchScope resolveScope)
PsiJavaCodeReferenceElement createFQClassNameReferenceElement(java.lang.String qName, GlobalSearchScope resolveScope)
PsiJavaCodeReferenceElement createPackageReferenceElement(PsiPackage aPackage) throws IncorrectOperationException
IncorrectOperationException
- if aPackage
is the default (root) package.PsiJavaCodeReferenceElement createPackageReferenceElement(java.lang.String packageName) throws IncorrectOperationException
IncorrectOperationException
- if packageName
is an empty string.PsiReferenceExpression createReferenceExpression(PsiClass aClass) throws IncorrectOperationException
IncorrectOperationException
- never (the exception is kept for compatibility purposes).PsiReferenceExpression createReferenceExpression(PsiPackage aPackage) throws IncorrectOperationException
IncorrectOperationException
- if aPackage
is the default (root) package.PsiIdentifier createIdentifier(java.lang.String text) throws IncorrectOperationException
IncorrectOperationException
- if text
is not a valid Java identifier.PsiKeyword createKeyword(java.lang.String keyword) throws IncorrectOperationException
IncorrectOperationException
- if text
is not a valid Java keyword.PsiKeyword createKeyword(java.lang.String keyword, PsiElement context) throws IncorrectOperationException
IncorrectOperationException
PsiImportStatement createImportStatement(PsiClass aClass) throws IncorrectOperationException
IncorrectOperationException
- if aClass
is an anonymous or local class.PsiImportStatement createImportStatementOnDemand(java.lang.String packageName) throws IncorrectOperationException
IncorrectOperationException
- if packageName
is not a valid qualified package name.PsiDeclarationStatement createVariableDeclarationStatement(java.lang.String name, PsiType type, PsiExpression initializer) throws IncorrectOperationException
Note that depending on code style settings the resulting variable may be declared as final
.
IncorrectOperationException
- if name
is not a valid identifier or
type
is not a valid type.PsiDeclarationStatement createVariableDeclarationStatement(java.lang.String name, PsiType type, PsiExpression initializer, PsiElement context) throws IncorrectOperationException
Note that depending on code style settings the resulting variable may be declared as final
.
context
- the context used to resolve symbols in the resulting declaration.IncorrectOperationException
- if name
is not a valid identifier or
type
is not a valid type.PsiResourceVariable createResourceVariable(java.lang.String name, PsiType type, PsiExpression initializer, PsiElement context)
context
- the context for dummy holderPsiDocTag createParamTag(java.lang.String parameterName, java.lang.String description) throws IncorrectOperationException
IncorrectOperationException
- if the name or description are invalid.PsiClass getArrayClass(LanguageLevel languageLevel)
languageLevel
- language level used to construct array class.PsiClassType getArrayClassType(PsiType componentType, LanguageLevel languageLevel)
languageLevel
- language level used to construct array class.PsiPackageStatement createPackageStatement(java.lang.String name) throws IncorrectOperationException
IncorrectOperationException
- if name
is not a valid package name.PsiImportStaticStatement createImportStaticStatement(PsiClass aClass, java.lang.String memberName) throws IncorrectOperationException
import static
statement for importing the specified member
from the specified class.IncorrectOperationException
- if the class is inner or local, or
memberName
is not a valid identifier.PsiParameterList createParameterList(java.lang.String [] names, PsiType [] types) throws IncorrectOperationException
createParameterList
in interface JVMElementFactory
IncorrectOperationException
- if any of the parameter names or types are invalid.PsiReferenceList createReferenceList(PsiJavaCodeReferenceElement [] references) throws IncorrectOperationException
IncorrectOperationException
- if some of the references are invalid.PsiSubstitutor createRawSubstitutor(PsiSubstitutor baseSubstitutor, PsiTypeParameter [] typeParameters)
PsiElement createDummyHolder(java.lang.String text, IElementType type, PsiElement context)
PsiParser.parse(IElementType, com.intellij.lang.PsiBuilder)
.text
- text to parsetype
- node typecontext
- contextPsiCatchSection createCatchSection(PsiType exceptionType, java.lang.String exceptionName, PsiElement context) throws IncorrectOperationException
catch
section for catching an exception of the specified
type and name.exceptionType
- the type of the exception to catch (either PsiClassType or PsiDisjunctionType).exceptionName
- the name of the variable in which the caught exception is stored (may be an empty string).context
- the context for resolving references.IncorrectOperationException
- if any of the parameters are not valid.PsiExpression createExpressionFromText(java.lang.String text, PsiElement context) throws IncorrectOperationException
PsiJavaParserFacade
createExpressionFromText
in interface JVMElementFactory
createExpressionFromText
in interface PsiJavaParserFacade
text
- the text of the expression to create.context
- the PSI element used as context for resolving references from the expression.IncorrectOperationException
- if the text does not specify a valid expression.