/** * {@inheritDoc} */ public final Refactoring createRefactoring(final RefactoringDescriptor descriptor) throws CoreException { return new ExtractSupertypeRefactoring(new ExtractSupertypeProcessor(null, null)); } }
@Override public IType getDestinationType() { return getProcessor().computeExtractedType(fNameField.getText()); }
public final void acceptAST(final ICompilationUnit unit, final CompilationUnit node) { try { final Collection types= (Collection) unitToTypes.get(unit); if (types != null) { for (final Iterator innerIterator= types.iterator(); innerIterator.hasNext();) { final IType currentType= (IType) innerIterator.next(); final AbstractTypeDeclaration currentDeclaration= ASTNodeSearchUtil.getAbstractTypeDeclarationNode(currentType, node); if (currentDeclaration != null) createModifiedSubType(unit, node, extractedType, extractBindings[0], currentDeclaration, status); } } } catch (CoreException exception) { JavaPlugin.log(exception); status.merge(RefactoringStatus.createFatalErrorStatus(exception.getLocalizedMessage())); } finally { subsubMonitor.worked(1); } }
monitor.beginTask(RefactoringCoreMessages.ExtractSupertypeProcessor_preparing, 70); status.merge(super.createWorkingCopyLayer(new SubProgressMonitor(monitor, 10))); final IType declaring= getDeclaringType(); status.merge(createExtractedSuperType(getDeclaringSuperTypeHierarchy(new SubProgressMonitor(monitor, 10)).getSuperclass(declaring), new SubProgressMonitor(monitor, 10))); if (status.hasFatalError()) return status; final IType extractedType= computeExtractedType(fTypeName); setDestinationType(extractedType); final List subTypes= new ArrayList(Arrays.asList(fTypesToExtract)); if (!subTypes.contains(declaring))
final Map<String, String> arguments= new HashMap<>(); String project= null; final IType declaring= getDeclaringType(); final IJavaProject javaProject= declaring.getJavaProject(); if (javaProject != null) 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(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()); } finally { monitor.done(); clearCaches();
monitor.beginTask("", 2); //$NON-NLS-1$ monitor.setTaskName(RefactoringCoreMessages.ExtractSupertypeProcessor_preparing); final IType declaring= getDeclaringType(); final String delimiter= StubUtility.getLineDelimiterUsed(extractedWorkingCopy.getJavaProject()); String typeComment= null; final String imports= createTypeImports(extractedWorkingCopy, monitor); if (imports != null && !"".equals(imports)) { //$NON-NLS-1$ buffer.append(imports); createTypeDeclaration(extractedWorkingCopy, superType, declaringDeclaration, typeComment, buffer, status, new SubProgressMonitor(monitor, 1)); source= createTypeTemplate(extractedWorkingCopy, "", fileComment, "", buffer.toString()); //$NON-NLS-1$ //$NON-NLS-2$ if (source == null) { if (!declaring.getPackageFragment().isDefaultPackage()) {
try { monitor.beginTask(RefactoringCoreMessages.ExtractSupertypeProcessor_preparing, 20); final IType declaring= getDeclaringType(); final CompilationUnitRewrite declaringRewrite= new CompilationUnitRewrite(fOwner, declaring.getCompilationUnit()); final AbstractTypeDeclaration declaringDeclaration= ASTNodeSearchUtil.getAbstractTypeDeclarationNode(declaring, declaringRewrite.getRoot()); final String name= JavaModelUtil.getRenamedCUName(declaring.getCompilationUnit(), fTypeName); final ICompilationUnit original= declaring.getPackageFragment().getCompilationUnit(name); final ICompilationUnit copy= getSharedWorkingCopy(original.getPrimary(), new SubProgressMonitor(monitor, 10)); fSuperSource= createSuperTypeSource(copy, superType, declaringDeclaration, status, new SubProgressMonitor(monitor, 10)); if (fSuperSource != null) { copy.getBuffer().setContents(fSuperSource);
final CompilationUnitRewrite targetRewrite= new CompilationUnitRewrite(fOwner, extractedWorkingCopy); final AbstractTypeDeclaration targetDeclaration= (AbstractTypeDeclaration) targetRewrite.getRoot().types().get(0); createTypeParameters(targetRewrite, superType, declaringDeclaration, targetDeclaration); createTypeSignature(targetRewrite, superType, declaringDeclaration, targetDeclaration); createNecessaryConstructors(targetRewrite, superType, targetDeclaration, status); final TextEdit edit= targetRewrite.createChange().getEdit(); try {
@Override public RefactoringStatus checkFinalConditions(final IProgressMonitor monitor, final CheckConditionsContext context) throws CoreException, OperationCanceledException { final RefactoringStatus status= new RefactoringStatus(); try { monitor.beginTask("", 1); //$NON-NLS-1$ monitor.setTaskName(RefactoringCoreMessages.ExtractSupertypeProcessor_checking); status.merge(checkExtractedCompilationUnit()); if (status.hasFatalError()) return status; return super.checkFinalConditions(new SubProgressMonitor(monitor, 1), context); } finally { monitor.done(); } }
monitor.beginTask(RefactoringCoreMessages.ExtractSupertypeProcessor_preparing, 70); status.merge(super.createWorkingCopyLayer(new SubProgressMonitor(monitor, 10))); final IType declaring= getDeclaringType(); status.merge(createExtractedSuperType(getDeclaringSuperTypeHierarchy(new SubProgressMonitor(monitor, 10)).getSuperclass(declaring), new SubProgressMonitor(monitor, 10))); if (status.hasFatalError()) return status; final IType extractedType= computeExtractedType(fTypeName); setDestinationType(extractedType); final List<IType> subTypes= new ArrayList<>(Arrays.asList(fTypesToExtract)); if (!subTypes.contains(declaring))
final Map arguments= new HashMap(); String project= null; final IType declaring= getDeclaringType(); final IJavaProject javaProject= declaring.getJavaProject(); if (javaProject != null) 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(fMembersToMove[index], JavaElementLabels.ALL_FULLY_QUALIFIED); comment.addSetting(JDTRefactoringDescriptorComment.createCompositeSetting(RefactoringCoreMessages.ExtractInterfaceProcessor_extracted_members_pattern, settings)); addSuperTypeSettings(comment, true); final JDTRefactoringDescriptor descriptor= new JDTRefactoringDescriptor(IJavaRefactorings.EXTRACT_SUPERCLASS, project, description, comment.asString(), arguments, flags); arguments.put(JDTRefactoringDescriptor.ATTRIBUTE_NAME, fTypeName); arguments.put(JDTRefactoringDescriptor.ATTRIBUTE_INPUT, descriptor.elementToHandle(getDeclaringType())); arguments.put(ATTRIBUTE_REPLACE, Boolean.valueOf(fReplace).toString()); arguments.put(ATTRIBUTE_INSTANCEOF, Boolean.valueOf(fInstanceOf).toString()); } finally { monitor.done(); clearCaches();
monitor.beginTask("", 2); //$NON-NLS-1$ monitor.setTaskName(RefactoringCoreMessages.ExtractSupertypeProcessor_preparing); final IType declaring= getDeclaringType(); final String delimiter= StubUtility.getLineDelimiterUsed(extractedWorkingCopy.getJavaProject()); String typeComment= null; final String imports= createTypeImports(extractedWorkingCopy, monitor); if (imports != null && !"".equals(imports)) { //$NON-NLS-1$ buffer.append(imports); createTypeDeclaration(extractedWorkingCopy, superType, declaringDeclaration, typeComment, buffer, status, new SubProgressMonitor(monitor, 1)); source= createTypeTemplate(extractedWorkingCopy, "", fileComment, "", buffer.toString()); //$NON-NLS-1$ //$NON-NLS-2$ if (source == null) { if (!declaring.getPackageFragment().isDefaultPackage()) {
try { monitor.beginTask(RefactoringCoreMessages.ExtractSupertypeProcessor_preparing, 20); final IType declaring= getDeclaringType(); final CompilationUnitRewrite declaringRewrite= new CompilationUnitRewrite(fOwner, declaring.getCompilationUnit()); final AbstractTypeDeclaration declaringDeclaration= ASTNodeSearchUtil.getAbstractTypeDeclarationNode(declaring, declaringRewrite.getRoot()); final String name= JavaModelUtil.getRenamedCUName(declaring.getCompilationUnit(), fTypeName); final ICompilationUnit original= declaring.getPackageFragment().getCompilationUnit(name); final ICompilationUnit copy= getSharedWorkingCopy(original.getPrimary(), new SubProgressMonitor(monitor, 10)); fSuperSource= createSuperTypeSource(copy, superType, declaringDeclaration, status, new SubProgressMonitor(monitor, 10)); if (fSuperSource != null) { copy.getBuffer().setContents(fSuperSource);
final CompilationUnitRewrite targetRewrite= new CompilationUnitRewrite(fOwner, extractedWorkingCopy); final AbstractTypeDeclaration targetDeclaration= (AbstractTypeDeclaration) targetRewrite.getRoot().types().get(0); createTypeParameters(targetRewrite, superType, declaringDeclaration, targetDeclaration); createTypeSignature(targetRewrite, superType, declaringDeclaration, targetDeclaration); createNecessaryConstructors(targetRewrite, superType, targetDeclaration, status); final TextEdit edit= targetRewrite.createChange(true).getEdit(); try {
/** * {@inheritDoc} */ public RefactoringStatus checkFinalConditions(final IProgressMonitor monitor, final CheckConditionsContext context) throws CoreException, OperationCanceledException { final RefactoringStatus status= new RefactoringStatus(); try { monitor.beginTask("", 1); //$NON-NLS-1$ monitor.setTaskName(RefactoringCoreMessages.ExtractSupertypeProcessor_checking); status.merge(checkExtractedCompilationUnit()); if (status.hasFatalError()) return status; return super.checkFinalConditions(new SubProgressMonitor(monitor, 1), context); } finally { monitor.done(); } }
monitor.beginTask(RefactoringCoreMessages.ExtractSupertypeProcessor_preparing, 70); status.merge(super.createWorkingCopyLayer(new SubProgressMonitor(monitor, 10))); final IType declaring= getDeclaringType(); status.merge(createExtractedSuperType(getDeclaringSuperTypeHierarchy(new SubProgressMonitor(monitor, 10)).getSuperclass(declaring), new SubProgressMonitor(monitor, 10))); if (status.hasFatalError()) return status; final IType extractedType= computeExtractedType(fTypeName); setDestinationType(extractedType); final List<IType> subTypes= new ArrayList<>(Arrays.asList(fTypesToExtract)); if (!subTypes.contains(declaring))
final Map<String, String> arguments= new HashMap<>(); String project= null; final IType declaring= getDeclaringType(); final IJavaProject javaProject= declaring.getJavaProject(); if (javaProject != null) 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(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()); } finally { monitor.done(); clearCaches();
monitor.beginTask("", 2); //$NON-NLS-1$ monitor.setTaskName(RefactoringCoreMessages.ExtractSupertypeProcessor_preparing); final IType declaring= getDeclaringType(); final String delimiter= StubUtility.getLineDelimiterUsed(extractedWorkingCopy.getJavaProject()); String typeComment= null; final String imports= createTypeImports(extractedWorkingCopy, monitor); if (imports != null && !"".equals(imports)) { //$NON-NLS-1$ buffer.append(imports); createTypeDeclaration(extractedWorkingCopy, superType, declaringDeclaration, typeComment, buffer, status, new SubProgressMonitor(monitor, 1)); source= createTypeTemplate(extractedWorkingCopy, "", fileComment, "", buffer.toString()); //$NON-NLS-1$ //$NON-NLS-2$ if (source == null) { if (!declaring.getPackageFragment().isDefaultPackage()) {
try { monitor.beginTask(RefactoringCoreMessages.ExtractSupertypeProcessor_preparing, 20); final IType declaring= getDeclaringType(); final CompilationUnitRewrite declaringRewrite= new CompilationUnitRewrite(fOwner, declaring.getCompilationUnit()); final AbstractTypeDeclaration declaringDeclaration= ASTNodeSearchUtil.getAbstractTypeDeclarationNode(declaring, declaringRewrite.getRoot()); final String name= JavaModelUtil.getRenamedCUName(declaring.getCompilationUnit(), fTypeName); final ICompilationUnit original= declaring.getPackageFragment().getCompilationUnit(name); final ICompilationUnit copy= getSharedWorkingCopy(original.getPrimary(), new SubProgressMonitor(monitor, 10)); fSuperSource= createSuperTypeSource(copy, superType, declaringDeclaration, status, new SubProgressMonitor(monitor, 10)); if (fSuperSource != null) { copy.getBuffer().setContents(fSuperSource);
final CompilationUnitRewrite targetRewrite= new CompilationUnitRewrite(fOwner, extractedWorkingCopy); final AbstractTypeDeclaration targetDeclaration= (AbstractTypeDeclaration) targetRewrite.getRoot().types().get(0); createTypeParameters(targetRewrite, superType, declaringDeclaration, targetDeclaration); createTypeSignature(targetRewrite, superType, declaringDeclaration, targetDeclaration); createNecessaryConstructors(targetRewrite, superType, targetDeclaration, status); final TextEdit edit= targetRewrite.createChange(true).getEdit(); try {