1 /******************************************************************************* 2 * Copyright (c) 2008, 2019 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 * Red Hat Inc. - refactored to jdt.core.manipulation 14 *******************************************************************************/ 15 package org.eclipse.jdt.core.manipulation; 16 17 import java.util.Map; 18 19 import org.eclipse.core.runtime.Assert; 20 21 import org.eclipse.jdt.core.JavaCore; 22 23 24 /** 25 * Specifies the requirements of a clean up. 26 * 27 * @since 1.12 28 */ 29 final public class CleanUpRequirementsCore { 30 31 protected final boolean fRequiresAST; 32 33 protected final Map<String, String> fCompilerOptions; 34 35 protected final boolean fRequiresFreshAST; 36 37 protected final boolean fRequiresChangedRegions; 38 39 40 /** 41 * Create a new instance 42 * 43 * @param requiresAST <code>true</code> if an AST is required 44 * @param requiresFreshAST <code>true</code> if a fresh AST is required 45 * @param requiresChangedRegions <code>true</code> if changed regions are required 46 * @param compilerOptions map of compiler options or <code>null</code> if no requirements 47 */ CleanUpRequirementsCore(boolean requiresAST, boolean requiresFreshAST, boolean requiresChangedRegions, Map<String, String> compilerOptions)48 public CleanUpRequirementsCore(boolean requiresAST, boolean requiresFreshAST, boolean requiresChangedRegions, Map<String, String> compilerOptions) { 49 Assert.isLegal(!requiresFreshAST || requiresAST, "Must not request fresh AST if no AST is required"); //$NON-NLS-1$ 50 Assert.isLegal(compilerOptions == null || requiresAST, "Must not provide options if no AST is required"); //$NON-NLS-1$ 51 fRequiresAST= requiresAST; 52 fRequiresFreshAST= requiresFreshAST; 53 fRequiresChangedRegions= requiresChangedRegions; 54 55 fCompilerOptions= compilerOptions; 56 // Make sure that compile warnings are not suppressed since some clean ups work on reported warnings 57 if (fCompilerOptions != null) 58 fCompilerOptions.put(JavaCore.COMPILER_PB_SUPPRESS_WARNINGS, JavaCore.DISABLED); 59 } 60 61 /** 62 * Tells whether the clean up requires an AST. 63 * <p> 64 * <strong>Note:</strong> This should return <code>false</code> whenever possible because 65 * creating an AST is expensive. 66 * </p> 67 * 68 * @return <code>true</code> if the CleanUpContext context must provide an AST 69 */ requiresAST()70 public boolean requiresAST() { 71 return fRequiresAST; 72 } 73 74 /** 75 * Tells whether a fresh AST, containing all the changes from previous clean ups, will be 76 * needed. 77 * 78 * @return <code>true</code> if the caller needs an up to date AST 79 */ requiresFreshAST()80 public boolean requiresFreshAST() { 81 return fRequiresFreshAST; 82 } 83 84 /** 85 * Required compiler options. 86 * 87 * @return the compiler options map or <code>null</code> if none 88 * @see JavaCore 89 */ getCompilerOptions()90 public Map<String, String> getCompilerOptions() { 91 return fCompilerOptions; 92 } 93 94 /** 95 * Tells whether this clean up requires to be informed about changed regions. The changed regions are the 96 * regions which have been changed between the last save state of the compilation unit and its 97 * current state. 98 * <p> 99 * Has only an effect if the clean up is used as save action. 100 * </p> 101 * <p> 102 * <strong>Note:</strong>: This should return <code>false</code> whenever possible because 103 * calculating the changed regions is expensive. 104 * </p> 105 * 106 * @return <code>true</code> if the CleanUpContext context must provide changed 107 * regions 108 */ requiresChangedRegions()109 public boolean requiresChangedRegions() { 110 return fRequiresChangedRegions; 111 } 112 113 }