1 4 package org.terracotta.dso.refactoring; 5 6 import org.eclipse.core.runtime.IProgressMonitor; 7 import org.eclipse.core.runtime.OperationCanceledException; 8 import org.eclipse.jdt.core.IJavaElement; 9 import org.eclipse.jdt.core.IJavaProject; 10 import org.eclipse.jdt.core.IPackageFragment; 11 import org.eclipse.jdt.core.IType; 12 import org.eclipse.ltk.core.refactoring.Change; 13 import org.eclipse.ltk.core.refactoring.RefactoringStatus; 14 import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext; 15 import org.eclipse.ltk.core.refactoring.participants.MoveParticipant; 16 17 public class MoveTypeParticipant extends MoveParticipant { 18 private IType fType; 19 private IJavaElement fDestination; 20 21 public RefactoringStatus checkConditions(IProgressMonitor pm, CheckConditionsContext context) 22 throws OperationCanceledException 23 { 24 return new RefactoringStatus(); 25 } 26 27 public Change createChange(IProgressMonitor pm) 28 throws OperationCanceledException 29 { 30 return createChangesForTypeMove(fType, fDestination); 31 } 32 33 public String getName() { 34 return "TCTypeChange"; 35 } 36 37 protected boolean initialize(Object element) { 38 fType = (IType)element; 39 40 Object destination = getArguments().getDestination(); 41 if(destination instanceof IPackageFragment || destination instanceof IType) { 42 fDestination = (IJavaElement)destination; 43 return true; 44 } 45 return false; 46 } 47 48 public static Change createChangesForTypeMove(IType type, IJavaElement destination) { 49 IJavaProject pdestination = destination.getJavaProject(); 50 String newpname = null; 51 if (!type.getJavaProject().equals(pdestination)) { 52 newpname = pdestination.getElementName(); 53 } 54 String newfqname = type.getElementName(); 55 if (destination instanceof IType) { 56 newfqname = ((IType)destination).getFullyQualifiedName() + '$' + type.getElementName(); 57 } 58 else if (destination instanceof IPackageFragment) { 59 if (!((IPackageFragment) destination).isDefaultPackage()) { 60 newfqname = destination.getElementName() + '.' + type.getElementName(); 61 } 62 } 63 return new MoveTypeChange(type, newfqname, newpname); 64 } 65 } 66 | Popular Tags |