Java Code Examples for org.eclipse.jdt.core.IJavaProject#getElementName()
The following examples show how to use
org.eclipse.jdt.core.IJavaProject#getElementName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RenameLocalVariableProcessor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private RenameJavaElementDescriptor createRefactoringDescriptor() { String project= null; IJavaProject javaProject= fCu.getJavaProject(); if (javaProject != null) { project= javaProject.getElementName(); } final String header= Messages.format(RefactoringCoreMessages.RenameLocalVariableProcessor_descriptor_description, new String[] { BasicElementLabels.getJavaElementName(fCurrentName), JavaElementLabels.getElementLabel(fLocalVariable.getParent(), JavaElementLabels.ALL_FULLY_QUALIFIED), BasicElementLabels.getJavaElementName(fNewName)}); final String description= Messages.format(RefactoringCoreMessages.RenameLocalVariableProcessor_descriptor_description_short, BasicElementLabels.getJavaElementName(fCurrentName)); final String comment= new JDTRefactoringDescriptorComment(project, this, header).asString(); final RenameJavaElementDescriptor descriptor= RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_LOCAL_VARIABLE); descriptor.setProject(project); descriptor.setDescription(description); descriptor.setComment(comment); descriptor.setFlags(RefactoringDescriptor.NONE); descriptor.setJavaElement(fLocalVariable); descriptor.setNewName(getNewElementName()); descriptor.setUpdateReferences(fUpdateReferences); return descriptor; }
Example 2
Source File: ReplaceInvocationsRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override public Change createChange(IProgressMonitor pm) throws CoreException { // TODO: update for fSelectionStart == -1 final Map<String, String> arguments= new HashMap<String, String>(); String project= null; IJavaProject javaProject= fSelectionTypeRoot.getJavaProject(); if (javaProject != null) project= javaProject.getElementName(); final IMethodBinding binding= fSourceProvider.getDeclaration().resolveBinding(); int flags= RefactoringDescriptor.STRUCTURAL_CHANGE | JavaRefactoringDescriptor.JAR_REFACTORING | JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT; if (!Modifier.isPrivate(binding.getModifiers())) flags|= RefactoringDescriptor.MULTI_CHANGE; final String description= Messages.format(RefactoringCoreMessages.ReplaceInvocationsRefactoring_descriptor_description_short, BasicElementLabels.getJavaElementName(binding.getName())); final String header= Messages.format(RefactoringCoreMessages.ReplaceInvocationsRefactoring_descriptor_description, new String[] { BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_FULLY_QUALIFIED), BindingLabelProvider.getBindingLabel(binding.getDeclaringClass(), JavaElementLabels.ALL_FULLY_QUALIFIED)}); final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(project, this, header); comment.addSetting(Messages.format(RefactoringCoreMessages.ReplaceInvocationsRefactoring_original_pattern, BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_FULLY_QUALIFIED))); if (!fTargetProvider.isSingle()) comment.addSetting(RefactoringCoreMessages.ReplaceInvocationsRefactoring_replace_references); final JavaRefactoringDescriptor descriptor= new JavaRefactoringDescriptor(ID_REPLACE_INVOCATIONS, project, description, comment.asString(), arguments, flags){}; //REVIEW Unregistered ID! arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fSelectionTypeRoot)); arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION, new Integer(fSelectionStart).toString() + " " + new Integer(fSelectionLength).toString()); //$NON-NLS-1$ arguments.put(ATTRIBUTE_MODE, new Integer(fTargetProvider.isSingle() ? 0 : 1).toString()); return new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.ReplaceInvocationsRefactoring_change_name, fChangeManager.getAllChanges()); }
Example 3
Source File: ChangeTypeRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public Change createChange(IProgressMonitor pm) throws CoreException { pm.beginTask(RefactoringCoreMessages.ChangeTypeMessages_CreateChangesForChangeType, 1); try { Map<ICompilationUnit, Set<ConstraintVariable>> relevantVarsByUnit= new HashMap<ICompilationUnit, Set<ConstraintVariable>>(); groupChangesByCompilationUnit(relevantVarsByUnit); final Map<String, String> arguments= new HashMap<String, String>(); String project= null; IJavaProject javaProject= fCu.getJavaProject(); if (javaProject != null) project= javaProject.getElementName(); final String description= RefactoringCoreMessages.ChangeTypeRefactoring_descriptor_description_short; final String header= Messages.format(RefactoringCoreMessages.ChangeTypeRefactoring_descriptor_description, new String[] { BindingLabelProvider.getBindingLabel(fSelectionBinding, JavaElementLabels.ALL_FULLY_QUALIFIED), BindingLabelProvider.getBindingLabel(fSelectedType, JavaElementLabels.ALL_FULLY_QUALIFIED)}); final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(project, this, header); comment.addSetting(Messages.format(RefactoringCoreMessages.ChangeTypeRefactoring_original_element_pattern, BindingLabelProvider.getBindingLabel(fSelectionBinding, JavaElementLabels.ALL_FULLY_QUALIFIED))); comment.addSetting(Messages.format(RefactoringCoreMessages.ChangeTypeRefactoring_original_type_pattern, BindingLabelProvider.getBindingLabel(getOriginalType(), JavaElementLabels.ALL_FULLY_QUALIFIED))); comment.addSetting(Messages.format(RefactoringCoreMessages.ChangeTypeRefactoring_refactored_type_pattern, BindingLabelProvider.getBindingLabel(fSelectedType, JavaElementLabels.ALL_FULLY_QUALIFIED))); final GeneralizeTypeDescriptor descriptor= RefactoringSignatureDescriptorFactory.createGeneralizeTypeDescriptor(project, description, comment.asString(), arguments, (RefactoringDescriptor.STRUCTURAL_CHANGE | JavaRefactoringDescriptor.JAR_REFACTORING | JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT)); arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fCu)); arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION, new Integer(fSelectionStart).toString() + " " + new Integer(fSelectionLength).toString()); //$NON-NLS-1$ arguments.put(ATTRIBUTE_TYPE, fSelectedType.getQualifiedName()); final DynamicValidationRefactoringChange result= new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.ChangeTypeRefactoring_allChanges); for (Iterator<ICompilationUnit>it= relevantVarsByUnit.keySet().iterator(); it.hasNext();) { ICompilationUnit icu= it.next(); Set<ConstraintVariable> cVars= relevantVarsByUnit.get(icu); CompilationUnitChange cuChange= new CompilationUnitChange(getName(), icu); addAllChangesFor(icu, cVars, cuChange); result.add(cuChange); pm.worked(1); if (pm.isCanceled()) throw new OperationCanceledException(); } return result; } finally { pm.done(); } }
Example 4
Source File: ProjectCommand.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
/** * Gets the classpaths and modulepaths. * * @param uri * Uri of the source/class file that needs to be queried. * @param options * Query options. * @return <code>ClasspathResult</code> containing both classpaths and * modulepaths. * @throws CoreException * @throws URISyntaxException */ public static ClasspathResult getClasspaths(String uri, ClasspathOptions options) throws CoreException, URISyntaxException { IJavaProject javaProject = getJavaProjectFromUri(uri); Optional<IBuildSupport> bs = JavaLanguageServerPlugin.getProjectsManager().getBuildSupport(javaProject.getProject()); if (!bs.isPresent()) { throw new CoreException(new Status(IStatus.ERROR, IConstants.PLUGIN_ID, "No BuildSupport for the project: " + javaProject.getElementName())); } ILaunchConfiguration launchConfig = bs.get().getLaunchConfiguration(javaProject, options.scope); JavaLaunchDelegate delegate = new JavaLaunchDelegate(); ClasspathResult[] result = new ClasspathResult[1]; IWorkspace workspace = ResourcesPlugin.getWorkspace(); ISchedulingRule currentRule = Job.getJobManager().currentRule(); ISchedulingRule schedulingRule; if (currentRule != null && currentRule.contains(javaProject.getSchedulingRule())) { schedulingRule = null; } else { schedulingRule = javaProject.getSchedulingRule(); } workspace.run(new IWorkspaceRunnable() { @Override public void run(IProgressMonitor monitor) throws CoreException { String[][] paths = delegate.getClasspathAndModulepath(launchConfig); result[0] = new ClasspathResult(javaProject.getProject().getLocationURI(), paths[0], paths[1]); } }, schedulingRule, IWorkspace.AVOID_UPDATE, new NullProgressMonitor()); if (result[0] != null) { return result[0]; } throw new CoreException(new Status(IStatus.ERROR, IConstants.PLUGIN_ID, "Failed to get the classpaths.")); }
Example 5
Source File: RenameTypeParameterProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public Change createChange(IProgressMonitor monitor) throws CoreException, OperationCanceledException { Assert.isNotNull(monitor); try { Change change= fChange; if (change != null) { String project= null; IJavaProject javaProject= fTypeParameter.getJavaProject(); if (javaProject != null) project= javaProject.getElementName(); String description= Messages.format(RefactoringCoreMessages.RenameTypeParameterProcessor_descriptor_description_short, BasicElementLabels.getJavaElementName(fTypeParameter.getElementName())); String header= Messages.format(RefactoringCoreMessages.RenameTypeParameterProcessor_descriptor_description, new String[] { BasicElementLabels.getJavaElementName(fTypeParameter.getElementName()), JavaElementLabels.getElementLabel(fTypeParameter.getDeclaringMember(), JavaElementLabels.ALL_FULLY_QUALIFIED), BasicElementLabels.getJavaElementName(getNewElementName())}); String comment= new JDTRefactoringDescriptorComment(project, this, header).asString(); RenameJavaElementDescriptor descriptor= RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_TYPE_PARAMETER); descriptor.setProject(project); descriptor.setDescription(description); descriptor.setComment(comment); descriptor.setFlags(RefactoringDescriptor.NONE); descriptor.setJavaElement(fTypeParameter); descriptor.setNewName(getNewElementName()); descriptor.setUpdateReferences(fUpdateReferences); change= new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.RenameTypeParameterProcessor_change_name, new Change[] { change}); } return change; } finally { fChange= null; monitor.done(); } }
Example 6
Source File: InferTypeArgumentsRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException { pm.beginTask("", 1); //$NON-NLS-1$ try { DynamicValidationStateChange result= new DynamicValidationStateChange(RefactoringCoreMessages.InferTypeArgumentsRefactoring_name, fChangeManager.getAllChanges()) { @Override public final ChangeDescriptor getDescriptor() { final Map<String, String> arguments= new HashMap<String, String>(); final IJavaProject project= getSingleProject(); final String description= RefactoringCoreMessages.InferTypeArgumentsRefactoring_descriptor_description; final String header= project != null ? Messages.format(RefactoringCoreMessages.InferTypeArgumentsRefactoring_descriptor_description_project, BasicElementLabels.getJavaElementName(project.getElementName())) : RefactoringCoreMessages.InferTypeArgumentsRefactoring_descriptor_description; final String name= project != null ? project.getElementName() : null; final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(name, this, header); final String[] settings= new String[fElements.length]; for (int index= 0; index < settings.length; index++) settings[index]= JavaElementLabels.getTextLabel(fElements[index], JavaElementLabels.ALL_FULLY_QUALIFIED); comment.addSetting(JDTRefactoringDescriptorComment.createCompositeSetting(RefactoringCoreMessages.InferTypeArgumentsRefactoring_original_elements, settings)); if (fAssumeCloneReturnsSameType) comment.addSetting(RefactoringCoreMessages.InferTypeArgumentsRefactoring_assume_clone); if (fLeaveUnconstrainedRaw) comment.addSetting(RefactoringCoreMessages.InferTypeArgumentsRefactoring_leave_unconstrained); final InferTypeArgumentsDescriptor descriptor= RefactoringSignatureDescriptorFactory.createInferTypeArgumentsDescriptor(name, description, comment.asString(), arguments, RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE); for (int index= 0; index < fElements.length; index++) arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + (index + 1), JavaRefactoringDescriptorUtil.elementToHandle(name, fElements[index])); arguments.put(ATTRIBUTE_CLONE, Boolean.valueOf(fAssumeCloneReturnsSameType).toString()); arguments.put(ATTRIBUTE_LEAVE, Boolean.valueOf(fLeaveUnconstrainedRaw).toString()); return new RefactoringChangeDescriptor(descriptor); } }; return result; } finally { pm.done(); } }
Example 7
Source File: RenameTypeParameterProcessor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Override public Change createChange(IProgressMonitor monitor) throws CoreException, OperationCanceledException { Assert.isNotNull(monitor); try { Change change= fChange; if (change != null) { String project= null; IJavaProject javaProject= fTypeParameter.getJavaProject(); if (javaProject != null) { project= javaProject.getElementName(); } String description= Messages.format(RefactoringCoreMessages.RenameTypeParameterProcessor_descriptor_description_short, BasicElementLabels.getJavaElementName(fTypeParameter.getElementName())); String header= Messages.format(RefactoringCoreMessages.RenameTypeParameterProcessor_descriptor_description, new String[] { BasicElementLabels.getJavaElementName(fTypeParameter.getElementName()), JavaElementLabels.getElementLabel(fTypeParameter.getDeclaringMember(), JavaElementLabels.ALL_FULLY_QUALIFIED), BasicElementLabels.getJavaElementName(getNewElementName())}); String comment= new JDTRefactoringDescriptorComment(project, this, header).asString(); RenameJavaElementDescriptor descriptor= RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_TYPE_PARAMETER); descriptor.setProject(project); descriptor.setDescription(description); descriptor.setComment(comment); descriptor.setFlags(RefactoringDescriptor.NONE); descriptor.setJavaElement(fTypeParameter); descriptor.setNewName(getNewElementName()); descriptor.setUpdateReferences(fUpdateReferences); change= new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.RenameTypeParameterProcessor_change_name, new Change[] { change}); } return change; } finally { fChange= null; monitor.done(); } }
Example 8
Source File: RenamePackageProcessor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private RenameJavaElementDescriptor createRefactoringDescriptor() { String project= null; IJavaProject javaProject= fPackage.getJavaProject(); if (javaProject != null) { project= javaProject.getElementName(); } final int flags= JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE; final String description= Messages.format(RefactoringCoreMessages.RenamePackageProcessor_descriptor_description_short, getElementLabel(fPackage)); final String header= Messages.format(RefactoringCoreMessages.RenamePackageProcessor_descriptor_description, new String[] { getElementLabel(fPackage), getNewElementName()}); final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(project, this, header); if (fRenameSubpackages) { comment.addSetting(RefactoringCoreMessages.RenamePackageProcessor_rename_subpackages); } final RenameJavaElementDescriptor descriptor= RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_PACKAGE); descriptor.setProject(project); descriptor.setDescription(description); descriptor.setComment(comment.asString()); descriptor.setFlags(flags); descriptor.setJavaElement(fPackage); descriptor.setNewName(getNewElementName()); descriptor.setUpdateReferences(fUpdateReferences); descriptor.setUpdateTextualOccurrences(fUpdateTextualMatches); descriptor.setUpdateQualifiedNames(fUpdateQualifiedNames); if (fUpdateQualifiedNames && fFilePatterns != null && !"".equals(fFilePatterns)) { descriptor.setFileNamePatterns(fFilePatterns); } descriptor.setUpdateHierarchy(fRenameSubpackages); return descriptor; }
Example 9
Source File: RenameEnumConstProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override protected RenameJavaElementDescriptor createRefactoringDescriptor() { final IField field= getField(); String project= null; IJavaProject javaProject= field.getJavaProject(); if (javaProject != null) project= javaProject.getElementName(); int flags= JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE; final IType declaring= field.getDeclaringType(); try { if (!Flags.isPrivate(declaring.getFlags())) flags|= RefactoringDescriptor.MULTI_CHANGE; if (declaring.isAnonymous() || declaring.isLocal()) flags|= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT; } catch (JavaModelException exception) { JavaPlugin.log(exception); } final String description= Messages.format(RefactoringCoreMessages.RenameEnumConstProcessor_descriptor_description_short, BasicElementLabels.getJavaElementName(fField.getElementName())); final String header= Messages.format(RefactoringCoreMessages.RenameEnumConstProcessor_descriptor_description, new String[] { BasicElementLabels.getJavaElementName(field.getElementName()), JavaElementLabels.getElementLabel(field.getParent(), JavaElementLabels.ALL_FULLY_QUALIFIED), BasicElementLabels.getJavaElementName(getNewElementName())}); final String comment= new JDTRefactoringDescriptorComment(project, this, header).asString(); final RenameJavaElementDescriptor descriptor= RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_ENUM_CONSTANT); descriptor.setProject(project); descriptor.setDescription(description); descriptor.setComment(comment); descriptor.setFlags(flags); descriptor.setJavaElement(field); descriptor.setNewName(getNewElementName()); descriptor.setUpdateReferences(fUpdateReferences); descriptor.setUpdateTextualOccurrences(fUpdateTextualMatches); return descriptor; }
Example 10
Source File: IntroduceIndirectionRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException { final Map<String, String> arguments= new HashMap<String, String>(); String project= null; IJavaProject javaProject= fTargetMethod.getJavaProject(); if (javaProject != null) project= javaProject.getElementName(); int flags= JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE; final IType declaring= fTargetMethod.getDeclaringType(); try { if (declaring.isLocal() || declaring.isAnonymous()) flags|= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT; } catch (JavaModelException exception) { JavaPlugin.log(exception); } final String description= Messages.format(RefactoringCoreMessages.IntroduceIndirectionRefactoring_descriptor_description_short, BasicElementLabels.getJavaElementName(fTargetMethod.getElementName())); final String header= Messages.format(RefactoringCoreMessages.IntroduceIndirectionRefactoring_descriptor_description, new String[] { JavaElementLabels.getTextLabel(fTargetMethod, JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getTextLabel(declaring, JavaElementLabels.ALL_FULLY_QUALIFIED)}); final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(project, this, header); comment.addSetting(Messages.format(RefactoringCoreMessages.IntroduceIndirectionRefactoring_original_pattern, JavaElementLabels.getTextLabel(fTargetMethod, JavaElementLabels.ALL_FULLY_QUALIFIED))); comment.addSetting(Messages.format(RefactoringCoreMessages.IntroduceIndirectionRefactoring_method_pattern, BasicElementLabels.getJavaElementName(fIntermediaryMethodName))); comment.addSetting(Messages.format(RefactoringCoreMessages.IntroduceIndirectionRefactoring_declaring_pattern, JavaElementLabels.getTextLabel(fIntermediaryType, JavaElementLabels.ALL_FULLY_QUALIFIED))); if (fUpdateReferences) comment.addSetting(RefactoringCoreMessages.JavaRefactoringDescriptor_update_references); final IntroduceIndirectionDescriptor descriptor= RefactoringSignatureDescriptorFactory.createIntroduceIndirectionDescriptor(project, description, comment.asString(), arguments, flags); arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fTargetMethod)); arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME, fIntermediaryMethodName); arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + 1, JavaRefactoringDescriptorUtil.elementToHandle(project, fIntermediaryType)); arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_REFERENCES, Boolean.valueOf(fUpdateReferences).toString()); return new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.IntroduceIndirectionRefactoring_introduce_indirection, fTextChangeManager.getAllChanges()); }
Example 11
Source File: ProcessUtilities.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
/** * Computes the fully qualified path to the java executable for the JRE/JDK used by this project. * * @param javaProject * @return the path to the JRE/JDK java (executable) used on this project * @throws CoreException */ public static String computeJavaExecutableFullyQualifiedPath(IJavaProject javaProject) throws CoreException { IVMInstall projectVMInstall = JavaRuntime.getVMInstall(javaProject); if (projectVMInstall == null) { throw new CoreException(new Status(Status.ERROR, CorePlugin.PLUGIN_ID, "Unable to locate the JVM for project " + javaProject.getElementName() + ". Please verify that you have a project-level JVM installed by inspecting your project's build path.")); } return getJavaExecutableForVMInstall(projectVMInstall); }
Example 12
Source File: ExtractConstantRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private ExtractConstantDescriptor createRefactoringDescriptor() { final Map<String, String> arguments= new HashMap<String, String>(); String project= null; IJavaProject javaProject= fCu.getJavaProject(); if (javaProject != null) project= javaProject.getElementName(); int flags= JavaRefactoringDescriptor.JAR_REFACTORING | JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT; if (JdtFlags.getVisibilityCode(fVisibility) != Modifier.PRIVATE) flags|= RefactoringDescriptor.STRUCTURAL_CHANGE; final String expression= ASTNodes.asString(fSelectedExpression.getAssociatedExpression()); final String description= Messages.format(RefactoringCoreMessages.ExtractConstantRefactoring_descriptor_description_short, BasicElementLabels.getJavaElementName(fConstantName)); final String header= Messages.format(RefactoringCoreMessages.ExtractConstantRefactoring_descriptor_description, new String[] { BasicElementLabels.getJavaElementName(fConstantName), BasicElementLabels.getJavaCodeString(expression)}); final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(project, this, header); comment.addSetting(Messages.format(RefactoringCoreMessages.ExtractConstantRefactoring_constant_name_pattern, BasicElementLabels.getJavaElementName(fConstantName))); comment.addSetting(Messages.format(RefactoringCoreMessages.ExtractConstantRefactoring_constant_expression_pattern, BasicElementLabels.getJavaCodeString(expression))); String visibility= fVisibility; if ("".equals(visibility)) //$NON-NLS-1$ visibility= RefactoringCoreMessages.ExtractConstantRefactoring_default_visibility; comment.addSetting(Messages.format(RefactoringCoreMessages.ExtractConstantRefactoring_visibility_pattern, visibility)); if (fReplaceAllOccurrences) comment.addSetting(RefactoringCoreMessages.ExtractConstantRefactoring_replace_occurrences); if (fQualifyReferencesWithDeclaringClassName) comment.addSetting(RefactoringCoreMessages.ExtractConstantRefactoring_qualify_references); arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fCu)); arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME, fConstantName); arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION, new Integer(fSelectionStart).toString() + " " + new Integer(fSelectionLength).toString()); //$NON-NLS-1$ arguments.put(ATTRIBUTE_REPLACE, Boolean.valueOf(fReplaceAllOccurrences).toString()); arguments.put(ATTRIBUTE_QUALIFY, Boolean.valueOf(fQualifyReferencesWithDeclaringClassName).toString()); arguments.put(ATTRIBUTE_VISIBILITY, new Integer(JdtFlags.getVisibilityCode(fVisibility)).toString()); ExtractConstantDescriptor descriptor= RefactoringSignatureDescriptorFactory.createExtractConstantDescriptor(project, description, comment.asString(), arguments, flags); return descriptor; }
Example 13
Source File: MoveInnerToTopRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public Change createChange(final IProgressMonitor monitor) throws CoreException { monitor.beginTask(RefactoringCoreMessages.MoveInnerToTopRefactoring_creating_change, 1); final Map<String, String> arguments= new HashMap<String, String>(); String project= null; IJavaProject javaProject= fType.getJavaProject(); if (javaProject != null) project= javaProject.getElementName(); final String description= Messages.format(RefactoringCoreMessages.MoveInnerToTopRefactoring_descriptor_description_short, BasicElementLabels.getJavaElementName(fType.getElementName())); final String header= Messages.format(RefactoringCoreMessages.MoveInnerToTopRefactoring_descriptor_description, new String[] { JavaElementLabels.getElementLabel(fType, JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getElementLabel(fType.getParent(), JavaElementLabels.ALL_FULLY_QUALIFIED)}); final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(project, this, header); comment.addSetting(Messages.format(RefactoringCoreMessages.MoveInnerToTopRefactoring_original_pattern, JavaElementLabels.getElementLabel(fType, JavaElementLabels.ALL_FULLY_QUALIFIED))); final boolean enclosing= fEnclosingInstanceFieldName != null && !"".equals(fEnclosingInstanceFieldName); //$NON-NLS-1$ if (enclosing) comment.addSetting(Messages.format(RefactoringCoreMessages.MoveInnerToTopRefactoring_field_pattern, BasicElementLabels.getJavaElementName(fEnclosingInstanceFieldName))); if (fNameForEnclosingInstanceConstructorParameter != null && !"".equals(fNameForEnclosingInstanceConstructorParameter)) //$NON-NLS-1$ comment.addSetting(Messages.format(RefactoringCoreMessages.MoveInnerToTopRefactoring_parameter_pattern, BasicElementLabels.getJavaElementName(fNameForEnclosingInstanceConstructorParameter))); if (enclosing && fMarkInstanceFieldAsFinal) comment.addSetting(RefactoringCoreMessages.MoveInnerToTopRefactoring_declare_final); final ConvertMemberTypeDescriptor descriptor= RefactoringSignatureDescriptorFactory.createConvertMemberTypeDescriptor(project, description, comment.asString(), arguments, RefactoringDescriptor.MULTI_CHANGE | RefactoringDescriptor.STRUCTURAL_CHANGE | JavaRefactoringDescriptor.JAR_REFACTORING | JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT); arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fType)); if (enclosing) arguments.put(ATTRIBUTE_FIELD_NAME, fEnclosingInstanceFieldName); if (fNameForEnclosingInstanceConstructorParameter != null && !"".equals(fNameForEnclosingInstanceConstructorParameter)) //$NON-NLS-1$ arguments.put(ATTRIBUTE_PARAMETER_NAME, fNameForEnclosingInstanceConstructorParameter); arguments.put(ATTRIBUTE_FIELD, Boolean.valueOf(fCreateInstanceField).toString()); arguments.put(ATTRIBUTE_FINAL, Boolean.valueOf(fMarkInstanceFieldAsFinal).toString()); arguments.put(ATTRIBUTE_POSSIBLE, Boolean.valueOf(fIsInstanceFieldCreationPossible).toString()); arguments.put(ATTRIBUTE_MANDATORY, Boolean.valueOf(fIsInstanceFieldCreationMandatory).toString()); final DynamicValidationRefactoringChange result= new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.MoveInnerToTopRefactoring_move_to_Top); result.addAll(fChangeManager.getAllChanges()); result.add(createCompilationUnitForMovedType(new SubProgressMonitor(monitor, 1))); return result; }
Example 14
Source File: RenameJavaProjectChange.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public RenameJavaProjectChange(IJavaProject project, String newName, boolean updateReferences) { this(project.getPath(), project.getElementName(), newName, IResource.NULL_STAMP, updateReferences); Assert.isTrue(!project.isReadOnly(), "should not be read only"); //$NON-NLS-1$ }
Example 15
Source File: PullUpRefactoringProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * {@inheritDoc} */ @Override public Change createChange(final IProgressMonitor monitor) throws CoreException, OperationCanceledException { try { final Map<String, String> arguments= new HashMap<String, String>(); String project= null; final IType declaring= getDeclaringType(); final IJavaProject javaProject= declaring.getJavaProject(); if (javaProject != null) project= javaProject.getElementName(); int flags= JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE; try { if (declaring.isLocal() || declaring.isAnonymous()) flags|= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT; } catch (JavaModelException exception) { JavaPlugin.log(exception); } final String description= fMembersToMove.length == 1 ? Messages.format(RefactoringCoreMessages.PullUpRefactoring_descriptor_description_short, new String[] { JavaElementLabels.getElementLabel(fMembersToMove[0], JavaElementLabels.ALL_DEFAULT), JavaElementLabels.getElementLabel(fDestinationType, JavaElementLabels.ALL_DEFAULT)}) : Messages.format(RefactoringCoreMessages.PullUpRefactoring_descriptor_description_short_multiple, BasicElementLabels.getJavaElementName(fDestinationType.getElementName())); final String header= fMembersToMove.length == 1 ? Messages.format(RefactoringCoreMessages.PullUpRefactoring_descriptor_description_full, new String[] { JavaElementLabels.getElementLabel(fMembersToMove[0], JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getElementLabel(declaring, JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getElementLabel(fDestinationType, JavaElementLabels.ALL_FULLY_QUALIFIED)}) : Messages.format(RefactoringCoreMessages.PullUpRefactoring_descriptor_description, new String[] { JavaElementLabels.getElementLabel(declaring, JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getElementLabel(fDestinationType, JavaElementLabels.ALL_FULLY_QUALIFIED)}); final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(project, this, header); comment.addSetting(Messages.format(RefactoringCoreMessages.MoveStaticMembersProcessor_target_element_pattern, JavaElementLabels.getElementLabel(fDestinationType, JavaElementLabels.ALL_FULLY_QUALIFIED))); addSuperTypeSettings(comment, true); final PullUpDescriptor descriptor= RefactoringSignatureDescriptorFactory.createPullUpDescriptor(project, description, comment.asString(), arguments, flags); arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fDestinationType)); arguments.put(ATTRIBUTE_REPLACE, Boolean.valueOf(fReplace).toString()); arguments.put(ATTRIBUTE_INSTANCEOF, Boolean.valueOf(fInstanceOf).toString()); arguments.put(ATTRIBUTE_STUBS, Boolean.valueOf(fCreateMethodStubs).toString()); arguments.put(ATTRIBUTE_PULL, new Integer(fMembersToMove.length).toString()); for (int offset= 0; offset < fMembersToMove.length; offset++) arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + (offset + 1), JavaRefactoringDescriptorUtil.elementToHandle(project, fMembersToMove[offset])); arguments.put(ATTRIBUTE_DELETE, new Integer(fDeletedMethods.length).toString()); for (int offset= 0; offset < fDeletedMethods.length; offset++) arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + (offset + fMembersToMove.length + 1), JavaRefactoringDescriptorUtil.elementToHandle(project, fDeletedMethods[offset])); arguments.put(ATTRIBUTE_ABSTRACT, new Integer(fAbstractMethods.length).toString()); for (int offset= 0; offset < fAbstractMethods.length; offset++) arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + (offset + fMembersToMove.length + fDeletedMethods.length + 1), JavaRefactoringDescriptorUtil.elementToHandle(project, fAbstractMethods[offset])); return new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.PullUpRefactoring_Pull_Up, fChangeManager.getAllChanges()); } finally { monitor.done(); clearCaches(); } }
Example 16
Source File: ImportClonesWizardPage.java From JDeodorant with MIT License | 4 votes |
public ImportClonesWizardPage(IJavaProject javaProject) { super("Import clones for project " + javaProject.getElementName(), "Import clones for project " + javaProject.getElementName(), null); }
Example 17
Source File: ExtractSupertypeProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * {@inheritDoc} */ @Override public Change createChange(final IProgressMonitor monitor) throws CoreException, OperationCanceledException { try { final Map<String, String> arguments= new HashMap<String, String>(); String project= null; final IType declaring= getDeclaringType(); final IJavaProject javaProject= declaring.getJavaProject(); if (javaProject != null) project= javaProject.getElementName(); int flags= JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE; try { if (declaring.isLocal() || declaring.isAnonymous()) flags|= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT; } catch (JavaModelException exception) { JavaPlugin.log(exception); } final String description= Messages.format(RefactoringCoreMessages.ExtractSupertypeProcessor_descriptor_description_short, BasicElementLabels.getJavaElementName(fTypeName)); final String header= Messages.format(RefactoringCoreMessages.ExtractSupertypeProcessor_descriptor_description, new String[] { JavaElementLabels.getElementLabel(fDestinationType, JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getElementLabel(fCachedDeclaringType, JavaElementLabels.ALL_FULLY_QUALIFIED)}); final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(project, this, header); final IType[] types= getTypesToExtract(); String[] settings= new String[types.length]; for (int index= 0; index < settings.length; index++) settings[index]= JavaElementLabels.getElementLabel(types[index], JavaElementLabels.ALL_FULLY_QUALIFIED); comment.addSetting(JDTRefactoringDescriptorComment.createCompositeSetting(RefactoringCoreMessages.ExtractSupertypeProcessor_subtypes_pattern, settings)); comment.addSetting(Messages.format(RefactoringCoreMessages.ExtractSupertypeProcessor_refactored_element_pattern, JavaElementLabels.getElementLabel(fDestinationType, JavaElementLabels.ALL_FULLY_QUALIFIED))); settings= new String[fMembersToMove.length]; for (int index= 0; index < settings.length; index++) settings[index]= JavaElementLabels.getElementLabel(fMembersToMove[index], JavaElementLabels.ALL_FULLY_QUALIFIED); comment.addSetting(JDTRefactoringDescriptorComment.createCompositeSetting(RefactoringCoreMessages.ExtractInterfaceProcessor_extracted_members_pattern, settings)); addSuperTypeSettings(comment, true); final ExtractSuperclassDescriptor descriptor= RefactoringSignatureDescriptorFactory.createExtractSuperclassDescriptor(project, description, comment.asString(), arguments, flags); arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME, fTypeName); arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, getDeclaringType())); arguments.put(ATTRIBUTE_REPLACE, Boolean.valueOf(fReplace).toString()); arguments.put(ATTRIBUTE_INSTANCEOF, Boolean.valueOf(fInstanceOf).toString()); arguments.put(ATTRIBUTE_STUBS, Boolean.valueOf(fCreateMethodStubs).toString()); arguments.put(ATTRIBUTE_EXTRACT, new Integer(fMembersToMove.length).toString()); for (int offset= 0; offset < fMembersToMove.length; offset++) arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + (offset + 1), JavaRefactoringDescriptorUtil.elementToHandle(project, fMembersToMove[offset])); arguments.put(ATTRIBUTE_DELETE, new Integer(fDeletedMethods.length).toString()); for (int offset= 0; offset < fDeletedMethods.length; offset++) arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + (offset + fMembersToMove.length + 1), JavaRefactoringDescriptorUtil.elementToHandle(project, fDeletedMethods[offset])); arguments.put(ATTRIBUTE_ABSTRACT, new Integer(fAbstractMethods.length).toString()); for (int offset= 0; offset < fAbstractMethods.length; offset++) arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + (offset + fMembersToMove.length + fDeletedMethods.length + 1), JavaRefactoringDescriptorUtil.elementToHandle(project, fAbstractMethods[offset])); arguments.put(ATTRIBUTE_TYPES, new Integer(fTypesToExtract.length).toString()); for (int offset= 0; offset < fTypesToExtract.length; offset++) arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + (offset + fMembersToMove.length + fDeletedMethods.length + fAbstractMethods.length + 1), JavaRefactoringDescriptorUtil.elementToHandle(project, fTypesToExtract[offset])); final DynamicValidationRefactoringChange change= new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.ExtractSupertypeProcessor_extract_supertype, fChangeManager.getAllChanges()); final IFile file= ResourceUtil.getFile(declaring.getCompilationUnit()); if (fSuperSource != null && fSuperSource.length() > 0) change.add(new CreateCompilationUnitChange(declaring.getPackageFragment().getCompilationUnit(JavaModelUtil.getRenamedCUName(declaring.getCompilationUnit(), fTypeName)), fSuperSource, file.getCharset(false))); return change; } finally { monitor.done(); clearCaches(); } }
Example 18
Source File: PushDownRefactoringProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * {@inheritDoc} */ @Override public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException { try { final Map<String, String> arguments= new HashMap<String, String>(); String project= null; final IType declaring= getDeclaringType(); final IJavaProject javaProject= declaring.getJavaProject(); if (javaProject != null) project= javaProject.getElementName(); int flags= JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE; try { if (declaring.isLocal() || declaring.isAnonymous()) flags|= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT; } catch (JavaModelException exception) { JavaPlugin.log(exception); } final String description= fMembersToMove.length == 1 ? Messages.format(RefactoringCoreMessages.PushDownRefactoring_descriptor_description_short_multi, BasicElementLabels.getJavaElementName(fMembersToMove[0].getElementName())) : RefactoringCoreMessages.PushDownRefactoring_descriptor_description_short; final String header= fMembersToMove.length == 1 ? Messages.format(RefactoringCoreMessages.PushDownRefactoring_descriptor_description_full, new String[] { JavaElementLabels.getElementLabel(fMembersToMove[0], JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getElementLabel(declaring, JavaElementLabels.ALL_FULLY_QUALIFIED) }) : Messages.format(RefactoringCoreMessages.PushDownRefactoring_descriptor_description, new String[] { JavaElementLabels.getElementLabel(declaring, JavaElementLabels.ALL_FULLY_QUALIFIED) }); final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(project, this, header); final String[] settings= new String[fMembersToMove.length]; for (int index= 0; index < settings.length; index++) settings[index]= JavaElementLabels.getElementLabel(fMembersToMove[index], JavaElementLabels.ALL_FULLY_QUALIFIED); comment.addSetting(JDTRefactoringDescriptorComment.createCompositeSetting(RefactoringCoreMessages.PushDownRefactoring_pushed_members_pattern, settings)); addSuperTypeSettings(comment, true); final PushDownDescriptor descriptor= RefactoringSignatureDescriptorFactory.createPushDownDescriptor(project, description, comment.asString(), arguments, flags); if (fCachedDeclaringType != null) arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fCachedDeclaringType)); for (int index= 0; index < fMembersToMove.length; index++) { arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + (index + 1), JavaRefactoringDescriptorUtil.elementToHandle(project, fMembersToMove[index])); for (int offset= 0; offset < fMemberInfos.length; offset++) { if (fMemberInfos[offset].getMember().equals(fMembersToMove[index])) { switch (fMemberInfos[offset].getAction()) { case MemberActionInfo.PUSH_ABSTRACT_ACTION: arguments.put(ATTRIBUTE_ABSTRACT + (index + 1), Boolean.valueOf(true).toString()); break; case MemberActionInfo.PUSH_DOWN_ACTION: arguments.put(ATTRIBUTE_PUSH + (index + 1), Boolean.valueOf(true).toString()); break; } } } } return new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.PushDownRefactoring_change_name, fChangeManager.getAllChanges()); } finally { pm.done(); clearCaches(); } }
Example 19
Source File: RenameTypeProcessor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
@Override public Change createChange(IProgressMonitor monitor) throws CoreException { try { monitor.beginTask(RefactoringCoreMessages.RenameTypeRefactoring_creating_change, 4); String project = null; IJavaProject javaProject = fType.getJavaProject(); if (javaProject != null) { project = javaProject.getElementName(); } int flags = JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE; try { if (!Flags.isPrivate(fType.getFlags())) { flags |= RefactoringDescriptor.MULTI_CHANGE; } if (fType.isAnonymous() || fType.isLocal()) { flags |= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT; } } catch (JavaModelException exception) { JavaLanguageServerPlugin.log(exception); } final String description = Messages.format(RefactoringCoreMessages.RenameTypeProcessor_descriptor_description_short, BasicElementLabels.getJavaElementName(fType.getElementName())); final String header = Messages.format(RefactoringCoreMessages.RenameTypeProcessor_descriptor_description, new String[] { JavaElementLabels.getElementLabel(fType, JavaElementLabels.ALL_FULLY_QUALIFIED), getNewElementLabel() }); final String comment = new JDTRefactoringDescriptorComment(project, this, header).asString(); final RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_TYPE); descriptor.setProject(project); descriptor.setDescription(description); descriptor.setComment(comment); descriptor.setFlags(flags); descriptor.setJavaElement(fType); descriptor.setNewName(getNewElementName()); descriptor.setUpdateQualifiedNames(fUpdateQualifiedNames); descriptor.setUpdateTextualOccurrences(fUpdateTextualMatches); descriptor.setUpdateReferences(fUpdateReferences); if (fUpdateQualifiedNames && fFilePatterns != null && !"".equals(fFilePatterns)) { descriptor.setFileNamePatterns(fFilePatterns); } descriptor.setUpdateSimilarDeclarations(fUpdateSimilarElements); descriptor.setMatchStrategy(fRenamingStrategy); final DynamicValidationRefactoringChange result = new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.RenameTypeProcessor_change_name); if (fChangeManager.containsChangesIn(fType.getCompilationUnit())) { TextChange textChange = fChangeManager.get(fType.getCompilationUnit()); if (textChange instanceof TextFileChange) { ((TextFileChange) textChange).setSaveMode(TextFileChange.FORCE_SAVE); } } if (willRenameCU()) { IResource resource = fType.getCompilationUnit().getResource(); if (resource != null && resource.isLinked()) { result.addAll(fChangeManager.getAllChanges()); String ext = resource.getFileExtension(); String renamedResourceName; if (ext == null) { renamedResourceName = getNewElementName(); } else { renamedResourceName = getNewElementName() + '.' + ext; } result.add(new RenameResourceChange(fType.getCompilationUnit().getPath(), renamedResourceName)); } else { addTypeDeclarationUpdate(fChangeManager); addConstructorRenames(fChangeManager); result.addAll(fChangeManager.getAllChanges()); String renamedCUName = JavaModelUtil.getRenamedCUName(fType.getCompilationUnit(), getNewElementName()); result.add(new RenameCompilationUnitChange(fType.getCompilationUnit(), renamedCUName)); } } else { result.addAll(fChangeManager.getAllChanges()); } monitor.worked(1); return result; } finally { fChangeManager = null; } }
Example 20
Source File: PromoteTempToFieldRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private ConvertLocalVariableDescriptor getRefactoringDescriptor() { final Map<String, String> arguments= new HashMap<String, String>(); String project= null; IJavaProject javaProject= fCu.getJavaProject(); if (javaProject != null) project= javaProject.getElementName(); final IVariableBinding binding= fTempDeclarationNode.resolveBinding(); final String description= Messages.format(RefactoringCoreMessages.PromoteTempToFieldRefactoring_descriptor_description_short, BasicElementLabels.getJavaElementName(binding.getName())); final String header= Messages.format(RefactoringCoreMessages.PromoteTempToFieldRefactoring_descriptor_description, new String[] { BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_FULLY_QUALIFIED), BindingLabelProvider.getBindingLabel(binding.getDeclaringMethod(), JavaElementLabels.ALL_FULLY_QUALIFIED)}); final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(project, this, header); comment.addSetting(Messages.format(RefactoringCoreMessages.PromoteTempToFieldRefactoring_original_pattern, BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_FULLY_QUALIFIED))); comment.addSetting(Messages.format(RefactoringCoreMessages.PromoteTempToFieldRefactoring_field_pattern, BasicElementLabels.getJavaElementName(fFieldName))); switch (fInitializeIn) { case INITIALIZE_IN_CONSTRUCTOR: comment.addSetting(RefactoringCoreMessages.PromoteTempToFieldRefactoring_initialize_constructor); break; case INITIALIZE_IN_FIELD: comment.addSetting(RefactoringCoreMessages.PromoteTempToFieldRefactoring_initialize_declaration); break; case INITIALIZE_IN_METHOD: comment.addSetting(RefactoringCoreMessages.PromoteTempToFieldRefactoring_initialize_method); break; } String visibility= JdtFlags.getVisibilityString(fVisibility); if ("".equals(visibility)) //$NON-NLS-1$ visibility= RefactoringCoreMessages.PromoteTempToFieldRefactoring_default_visibility; comment.addSetting(Messages.format(RefactoringCoreMessages.PromoteTempToFieldRefactoring_visibility_pattern, visibility)); if (fDeclareFinal && fDeclareStatic) comment.addSetting(RefactoringCoreMessages.PromoteTempToFieldRefactoring_declare_final_static); else if (fDeclareFinal) comment.addSetting(RefactoringCoreMessages.PromoteTempToFieldRefactoring_declare_final); else if (fDeclareStatic) comment.addSetting(RefactoringCoreMessages.PromoteTempToFieldRefactoring_declare_static); final ConvertLocalVariableDescriptor descriptor= RefactoringSignatureDescriptorFactory.createConvertLocalVariableDescriptor(project, description, comment.asString(), arguments, RefactoringDescriptor.STRUCTURAL_CHANGE); arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fCu)); arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME, fFieldName); arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION, new Integer(fSelectionStart).toString() + " " + new Integer(fSelectionLength).toString()); //$NON-NLS-1$ arguments.put(ATTRIBUTE_STATIC, Boolean.valueOf(fDeclareStatic).toString()); arguments.put(ATTRIBUTE_FINAL, Boolean.valueOf(fDeclareFinal).toString()); arguments.put(ATTRIBUTE_VISIBILITY, new Integer(fVisibility).toString()); arguments.put(ATTRIBUTE_INITIALIZE, new Integer(fInitializeIn).toString()); return descriptor; }