1 /******************************************************************************* 2 * Copyright (c) 2000, 2010 IBM Corporation and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * IBM Corporation - initial API and implementation 13 *******************************************************************************/ 14 package org.eclipse.jdt.internal.corext.refactoring.reorg; 15 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.core.runtime.IProgressMonitor; 18 19 import org.eclipse.core.resources.IResource; 20 21 import org.eclipse.ltk.core.refactoring.Change; 22 import org.eclipse.ltk.core.refactoring.ChangeDescriptor; 23 import org.eclipse.ltk.core.refactoring.RefactoringStatus; 24 import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext; 25 import org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant; 26 import org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor; 27 import org.eclipse.ltk.core.refactoring.participants.ReorgExecutionLog; 28 import org.eclipse.ltk.core.refactoring.participants.SharableParticipants; 29 30 import org.eclipse.jdt.core.IJavaElement; 31 import org.eclipse.jdt.core.JavaModelException; 32 33 import org.eclipse.jdt.internal.corext.refactoring.JavaRefactoringArguments; 34 import org.eclipse.jdt.internal.corext.refactoring.tagging.IQualifiedNameUpdating; 35 import org.eclipse.jdt.internal.corext.refactoring.tagging.IReferenceUpdating; 36 37 38 public interface IReorgPolicy extends IReorgDestinationValidator { 39 40 /** 41 * @return the unique id of this policy 42 */ getPolicyId()43 public String getPolicyId(); 44 45 /** 46 * @return the source resources to reorg 47 */ getResources()48 public IResource[] getResources(); 49 50 /** 51 * @return the source java elements to reorg 52 */ getJavaElements()53 public IJavaElement[] getJavaElements(); 54 55 /** 56 * @return true if this policy can handle the source elements 57 * @throws JavaModelException in unexpected cases 58 */ canEnable()59 public boolean canEnable() throws JavaModelException; 60 61 /** 62 * @return the save mode required for this reorg policy 63 * 64 * see RefactoringSaveHelper 65 */ getSaveMode()66 public int getSaveMode(); 67 68 /** 69 * Can destination be a target for the given source elements? 70 * 71 * @param destination the destination to verify 72 * @return OK status if valid destination 73 * @throws JavaModelException in unexpected cases 74 */ verifyDestination(IReorgDestination destination)75 public RefactoringStatus verifyDestination(IReorgDestination destination) throws JavaModelException; 76 77 /** 78 * @param destination the destination for this reorg 79 */ setDestination(IReorgDestination destination)80 public void setDestination(IReorgDestination destination); 81 82 /** 83 * @return the destination of this reorg or null if not a resource 84 */ getResourceDestination()85 public IResource getResourceDestination(); 86 87 /** 88 * @return the destination of this reorg or null if not a java element 89 */ getJavaElementDestination()90 public IJavaElement getJavaElementDestination(); 91 92 /** 93 * @return a descriptor describing a reorg from source to target 94 */ getDescriptor()95 public ChangeDescriptor getDescriptor(); 96 97 98 /** 99 * Initializes the reorg policy with arguments from a script. 100 * 101 * @param arguments 102 * the arguments 103 * @return an object describing the status of the initialization. If the 104 * status has severity <code>FATAL_ERROR</code>, the refactoring 105 * will not be executed. 106 */ initialize(JavaRefactoringArguments arguments)107 public RefactoringStatus initialize(JavaRefactoringArguments arguments); 108 checkFinalConditions(IProgressMonitor monitor, CheckConditionsContext context, IReorgQueries queries)109 public RefactoringStatus checkFinalConditions(IProgressMonitor monitor, CheckConditionsContext context, IReorgQueries queries) throws CoreException; 110 loadParticipants(RefactoringStatus status, RefactoringProcessor processor, String[] natures, SharableParticipants shared)111 public RefactoringParticipant[] loadParticipants(RefactoringStatus status, RefactoringProcessor processor, String[] natures, SharableParticipants shared) throws CoreException; 112 113 public static interface ICopyPolicy extends IReorgPolicy{ createChange(IProgressMonitor monitor, INewNameQueries queries)114 public Change createChange(IProgressMonitor monitor, INewNameQueries queries) throws JavaModelException; getReorgExecutionLog()115 public ReorgExecutionLog getReorgExecutionLog(); 116 } 117 118 public static interface IMovePolicy extends IReferenceUpdating, IQualifiedNameUpdating, IReorgPolicy{ createChange(IProgressMonitor monitor)119 public Change createChange(IProgressMonitor monitor) throws JavaModelException; postCreateChange(Change[] participantChanges, IProgressMonitor monitor)120 public Change postCreateChange(Change[] participantChanges, IProgressMonitor monitor) throws CoreException; getCreateTargetQuery(ICreateTargetQueries createQueries)121 public ICreateTargetQuery getCreateTargetQuery(ICreateTargetQueries createQueries); isTextualMove()122 public boolean isTextualMove(); getCreateTargetExecutionLog()123 public CreateTargetExecutionLog getCreateTargetExecutionLog(); setDestinationCheck(boolean check)124 public void setDestinationCheck(boolean check); hasAllInputSet()125 public boolean hasAllInputSet(); 126 /** 127 * Checks if <b>Java</b> references to the selected element(s) can be updated if moved to 128 * the selected destination. Even if <code>false</code>, participants could still update 129 * non-Java references. 130 * 131 * @return <code>true</code> iff <b>Java</b> references to the moved element can be updated 132 * @since 3.5 133 */ canUpdateJavaReferences()134 public boolean canUpdateJavaReferences(); canUpdateQualifiedNames()135 public boolean canUpdateQualifiedNames(); 136 } 137 } 138