public class ExtractClassDescriptor extends JavaRefactoringDescriptor
An instance of this refactoring descriptor may be obtained by calling
RefactoringContribution.createDescriptor()
on a refactoring
contribution requested by invoking
RefactoringCore.getRefactoringContribution(String)
with the
appropriate refactoring id.
Modifier and Type | Class and Description |
---|---|
static class |
ExtractClassDescriptor.Field
Instances of
ExtractClassDescriptor.Field describe which fields will be moved to
the extracted class and their new name there. |
ATTRIBUTE_ELEMENT, ATTRIBUTE_INPUT, ATTRIBUTE_NAME, ATTRIBUTE_REFERENCES, ATTRIBUTE_SELECTION, ATTRIBUTE_VERSION, fArguments, JAR_MIGRATION, JAR_REFACTORING, JAR_SOURCE_ATTACHMENT, VALUE_VERSION_1_0
BREAKING_CHANGE, ID_UNKNOWN, MULTI_CHANGE, NONE, STRUCTURAL_CHANGE, USER_CHANGE
Constructor and Description |
---|
ExtractClassDescriptor()
Creates a new refactoring descriptor.
|
ExtractClassDescriptor(String project,
String description,
String comment,
Map<String,String> arguments,
int flags)
Creates a new refactoring descriptor.
|
Modifier and Type | Method and Description |
---|---|
String |
getClassName()
Returns the class name for the extracted class or
null if the refactoring should choose a name |
String |
getFieldName()
Returns the field name for the generated field or
null if the refactoring should choose a name |
ExtractClassDescriptor.Field[] |
getFields()
Returns the fields.
|
static ExtractClassDescriptor.Field[] |
getFields(IType type)
Creates
ExtractClassDescriptor.Field objects for all instance fields of the type |
String |
getPackage()
Returns the package where the extracted class will be created in if {
isCreateTopLevel() returns true . |
IType |
getType()
Returns the type from which the fields are moved
|
boolean |
isCreateGetterSetter()
Returns
true if getters and setters are generated for fields. |
boolean |
isCreateTopLevel()
Returns whether the extracted class will be created as top level class or as nested class.
|
protected void |
populateArgumentMap()
Populates the refactoring descriptor argument map based on the specified
arguments.
|
void |
setClassName(String className)
Sets the class name for the extracted class or
null if the refactoring should choose a name |
void |
setCreateGetterSetter(boolean createGetterSetter)
Sets whether getters and setters will be created for all fields.
|
void |
setCreateTopLevel(boolean createTopLevel)
Sets whether the extracted class will be created as top level class or as nested class.
|
void |
setFieldName(String fieldName)
Sets the field name for the generated field or
null if the refactoring should choose a name |
void |
setFields(ExtractClassDescriptor.Field[] fields)
Sets the fields.
|
void |
setPackage(String packageName)
Sets the package in which the top level class will be created.
|
void |
setType(IType type)
Sets the type to extract class from
|
RefactoringStatus |
validateDescriptor()
Validates the refactoring descriptor with respect to the constraints
imposed by the represented refactoring.
|
createRefactoring, elementToHandle, getArguments, handleToElement, handleToElement, handleToElement, handleToResource, resourceToHandle, setComment, setDescription, setFlags, setProject
compareTo, createRefactoringContext, equals, getComment, getDescription, getFlags, getID, getProject, getTimeStamp, hashCode, setTimeStamp, toString
public ExtractClassDescriptor()
public ExtractClassDescriptor(String project, String description, String comment, Map<String,String> arguments, int flags) throws IllegalArgumentException
project
- the non-empty name of the project associated with this
refactoring, or null
for a workspace
refactoringdescription
- a non-empty human-readable description of the particular
refactoring instancecomment
- the human-readable comment of the particular refactoring
instance, or null
for no commentarguments
- a map of arguments that will be persisted and describes
all settings for this refactoringflags
- the flags of the refactoring descriptorIllegalArgumentException
- if the argument map contains invalid keys/valuespublic static ExtractClassDescriptor.Field[] getFields(IType type) throws JavaModelException
ExtractClassDescriptor.Field
objects for all instance fields of the typetype
- the type declaring the field that will be moved to the extracted classExtractClassDescriptor.Field
for every field declared in type that is not staticJavaModelException
- if the type does not exist or if an exception occurs while accessing its corresponding resource.public void setFields(ExtractClassDescriptor.Field[] fields) throws IllegalArgumentException
getFields(IType)
. Changing the order can have side effects because of different initialization order.
Only fields which return true
for ExtractClassDescriptor.Field.isCreateField()
are created in the extracted class. Can be
null
to indicate that all instance fields should be movedfields
- the fields to move to the extracted class. Can be null
to indicate that all instance fields should
be movedIllegalArgumentException
- if one of the fields is null
public ExtractClassDescriptor.Field[] getFields()
ExtractClassDescriptor.Field.isCreateField()
returns true
.null
. If null
all instance fields from the selected type will be movedpublic IType getType()
public void setType(IType type)
type
- the type to extract class frompublic String getPackage()
isCreateTopLevel()
returns true
.
Can return null
to indicate that the package will be the same as the typenull
. If null
the package will be the same
as the typepublic void setPackage(String packageName)
null
to indicate that the
package will be the same as the typepackageName
- the package in which the top level class will be created. Can be null
to indicate that the
package will be the same as the typepublic String getClassName()
null
if the refactoring should choose a namenull
if the refactoring should choose a namepublic void setClassName(String className)
null
if the refactoring should choose a nameclassName
- the class name for the extracted class or null
if the refactoring should choose a namepublic String getFieldName()
null
if the refactoring should choose a namenull
if the refactoring should choose a namepublic void setFieldName(String fieldName)
null
if the refactoring should choose a namefieldName
- the field name for the generated field or null
if the refactoring should choose a namepublic boolean isCreateTopLevel()
true
the
extracted class will be generated as top level class. The default is true
true
the extracted class will be generated as top level class. The default is true
public void setCreateTopLevel(boolean createTopLevel)
true
the
extracted class will be generated as top level class. Else the class will be created as nested class in the type.
The default is true
createTopLevel
- true
to generated as top level class. The default is true
public void setCreateGetterSetter(boolean createGetterSetter)
createGetterSetter
- true
to create getters and setters. Default is false
.public boolean isCreateGetterSetter()
true
if getters and setters are generated for fields. Default is false
.true
if getters and setters are generated for fields. Default is false
protected void populateArgumentMap()
JavaRefactoringDescriptor
JavaRefactoringDescriptor.fArguments
.populateArgumentMap
in class JavaRefactoringDescriptor
public RefactoringStatus validateDescriptor()
JavaRefactoringDescriptor
Clients must call this method to verify that all arguments have been
correctly set and that they satisfy the constraints imposed by specific
refactorings. Returning a refactoring status of severity
RefactoringStatus.FATAL
indicates that the refactoring descriptor
cannot be used to create a refactoring instance.
validateDescriptor
in class JavaRefactoringDescriptor
Copyright (c) 2000, 2018 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.