Class ExtractClassDescriptor
- java.lang.Object
-
- org.eclipse.ltk.core.refactoring.RefactoringDescriptor
-
- org.eclipse.jdt.core.refactoring.descriptors.JavaRefactoringDescriptor
-
- org.eclipse.jdt.core.refactoring.descriptors.ExtractClassDescriptor
-
- All Implemented Interfaces:
Comparable<RefactoringDescriptor>
public class ExtractClassDescriptor extends JavaRefactoringDescriptor
Refactoring descriptor for the extract class refactoring.An instance of this refactoring descriptor may be obtained by calling
RefactoringContribution.createDescriptor()on a refactoring contribution requested by invokingRefactoringCore.getRefactoringContribution(String)with the appropriate refactoring id.- Since:
- 1.2
- Restriction:
- This class is not intended to be subclassed by clients.
- Restriction:
- This class is not intended to be instantiated by clients.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classExtractClassDescriptor.FieldInstances ofExtractClassDescriptor.Fielddescribe which fields will be moved to the extracted class and their new name there.
-
Field Summary
-
Fields inherited from class org.eclipse.jdt.core.refactoring.descriptors.JavaRefactoringDescriptor
ATTRIBUTE_ELEMENT, ATTRIBUTE_INPUT, ATTRIBUTE_NAME, ATTRIBUTE_REFERENCES, ATTRIBUTE_SELECTION, ATTRIBUTE_VERSION, fArguments, JAR_MIGRATION, JAR_REFACTORING, JAR_SOURCE_ATTACHMENT, VALUE_VERSION_1_0
-
Fields inherited from class org.eclipse.ltk.core.refactoring.RefactoringDescriptor
BREAKING_CHANGE, ID_UNKNOWN, MULTI_CHANGE, NONE, STRUCTURAL_CHANGE, USER_CHANGE
-
-
Constructor Summary
Constructors Constructor 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.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetClassName()Returns the class name for the extracted class ornullif the refactoring should choose a nameStringgetFieldName()Returns the field name for the generated field ornullif the refactoring should choose a nameExtractClassDescriptor.Field[]getFields()Returns the fields.static ExtractClassDescriptor.Field[]getFields(IType type)CreatesExtractClassDescriptor.Fieldobjects for all instance fields of the typeStringgetPackage()Returns the package where the extracted class will be created in if {isCreateTopLevel()returnstrue.ITypegetType()Returns the type from which the fields are movedbooleanisCreateGetterSetter()Returnstrueif getters and setters are generated for fields.booleanisCreateTopLevel()Returns whether the extracted class will be created as top level class or as nested class.protected voidpopulateArgumentMap()Populates the refactoring descriptor argument map based on the specified arguments.voidsetClassName(String className)Sets the class name for the extracted class ornullif the refactoring should choose a namevoidsetCreateGetterSetter(boolean createGetterSetter)Sets whether getters and setters will be created for all fields.voidsetCreateTopLevel(boolean createTopLevel)Sets whether the extracted class will be created as top level class or as nested class.voidsetFieldName(String fieldName)Sets the field name for the generated field ornullif the refactoring should choose a namevoidsetFields(ExtractClassDescriptor.Field[] fields)Sets the fields.voidsetPackage(String packageName)Sets the package in which the top level class will be created.voidsetType(IType type)Sets the type to extract class fromRefactoringStatusvalidateDescriptor()Validates the refactoring descriptor with respect to the constraints imposed by the represented refactoring.-
Methods inherited from class org.eclipse.jdt.core.refactoring.descriptors.JavaRefactoringDescriptor
createRefactoring, elementToHandle, getArguments, handleToElement, handleToElement, handleToElement, handleToResource, resourceToHandle, setComment, setDescription, setFlags, setProject
-
Methods inherited from class org.eclipse.ltk.core.refactoring.RefactoringDescriptor
compareTo, createRefactoringContext, equals, getComment, getDescription, getFlags, getID, getProject, getTimeStamp, hashCode, setTimeStamp, toString
-
-
-
-
Constructor Detail
-
ExtractClassDescriptor
public ExtractClassDescriptor()
Creates a new refactoring descriptor.
-
ExtractClassDescriptor
public ExtractClassDescriptor(String project, String description, String comment, Map<String,String> arguments, int flags) throws IllegalArgumentException
Creates a new refactoring descriptor.- Parameters:
project- the non-empty name of the project associated with this refactoring, ornullfor a workspace refactoringdescription- a non-empty human-readable description of the particular refactoring instancecomment- the human-readable comment of the particular refactoring instance, ornullfor no commentarguments- a map of arguments that will be persisted and describes all settings for this refactoringflags- the flags of the refactoring descriptor- Throws:
IllegalArgumentException- if the argument map contains invalid keys/values
-
-
Method Detail
-
getFields
public static ExtractClassDescriptor.Field[] getFields(IType type) throws JavaModelException
CreatesExtractClassDescriptor.Fieldobjects for all instance fields of the type- Parameters:
type- the type declaring the field that will be moved to the extracted class- Returns:
- an instance of
ExtractClassDescriptor.Fieldfor every field declared in type that is not static - Throws:
JavaModelException- if the type does not exist or if an exception occurs while accessing its corresponding resource.
-
setFields
public void setFields(ExtractClassDescriptor.Field[] fields) throws IllegalArgumentException
Sets the fields. The order is important and should be the same as the order returned fromgetFields(IType). Changing the order can have side effects because of different initialization order. Only fields which returntrueforExtractClassDescriptor.Field.isCreateField()are created in the extracted class. Can benullto indicate that all instance fields should be moved- Parameters:
fields- the fields to move to the extracted class. Can benullto indicate that all instance fields should be moved- Throws:
IllegalArgumentException- if one of the fields isnull
-
getFields
public ExtractClassDescriptor.Field[] getFields()
Returns the fields. The order of the fields is the same as they will appear in the extracted class ifExtractClassDescriptor.Field.isCreateField()returnstrue.- Returns:
- the fields or
null. Ifnullall instance fields from the selected type will be moved
-
getType
public IType getType()
Returns the type from which the fields are moved- Returns:
- the type
-
setType
public void setType(IType type)
Sets the type to extract class from- Parameters:
type- the type to extract class from
-
getPackage
public String getPackage()
Returns the package where the extracted class will be created in if {isCreateTopLevel()returnstrue. Can returnnullto indicate that the package will be the same as the type- Returns:
- the package for the toplevel extracted class or
null. Ifnullthe package will be the same as the type
-
setPackage
public void setPackage(String packageName)
Sets the package in which the top level class will be created. Can benullto indicate that the package will be the same as the type- Parameters:
packageName- the package in which the top level class will be created. Can benullto indicate that the package will be the same as the type
-
getClassName
public String getClassName()
Returns the class name for the extracted class ornullif the refactoring should choose a name- Returns:
- the class name for the extracted class or
nullif the refactoring should choose a name
-
setClassName
public void setClassName(String className)
Sets the class name for the extracted class ornullif the refactoring should choose a name- Parameters:
className- the class name for the extracted class ornullif the refactoring should choose a name
-
getFieldName
public String getFieldName()
Returns the field name for the generated field ornullif the refactoring should choose a name- Returns:
- the field name for the generated field or
nullif the refactoring should choose a name
-
setFieldName
public void setFieldName(String fieldName)
Sets the field name for the generated field ornullif the refactoring should choose a name- Parameters:
fieldName- the field name for the generated field ornullif the refactoring should choose a name
-
isCreateTopLevel
public boolean isCreateTopLevel()
Returns whether the extracted class will be created as top level class or as nested class. Iftruethe extracted class will be generated as top level class. The default istrue- Returns:
- if
truethe extracted class will be generated as top level class. The default istrue
-
setCreateTopLevel
public void setCreateTopLevel(boolean createTopLevel)
Sets whether the extracted class will be created as top level class or as nested class. Iftruethe extracted class will be generated as top level class. Else the class will be created as nested class in the type. The default istrue- Parameters:
createTopLevel-trueto generated as top level class. The default istrue
-
setCreateGetterSetter
public void setCreateGetterSetter(boolean createGetterSetter)
Sets whether getters and setters will be created for all fields.- Parameters:
createGetterSetter-trueto create getters and setters. Default isfalse.
-
isCreateGetterSetter
public boolean isCreateGetterSetter()
Returnstrueif getters and setters are generated for fields. Default isfalse.- Returns:
trueif getters and setters are generated for fields. Default isfalse
-
populateArgumentMap
protected void populateArgumentMap()
Description copied from class:JavaRefactoringDescriptorPopulates the refactoring descriptor argument map based on the specified arguments. Subclasses should extend and add their arguments toJavaRefactoringDescriptor.fArguments.- Overrides:
populateArgumentMapin classJavaRefactoringDescriptor
-
validateDescriptor
public RefactoringStatus validateDescriptor()
Description copied from class:JavaRefactoringDescriptorValidates the refactoring descriptor with respect to the constraints imposed by the represented refactoring.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.FATALindicates that the refactoring descriptor cannot be used to create a refactoring instance.- Overrides:
validateDescriptorin classJavaRefactoringDescriptor- Returns:
- a refactoring status describing the outcome of the validation
-
-