Java Code Examples for org.eclipse.jdt.internal.corext.fix.CleanUpConstants

The following examples show how to use org.eclipse.jdt.internal.corext.fix.CleanUpConstants. These examples are extracted from open source projects. 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
/**
 * {@inheritDoc}
 */
public boolean canFix(ICompilationUnit compilationUnit, IProblemLocation problem) {
	int id= problem.getProblemId();
	
	if (Java50Fix.isMissingOverrideAnnotationProblem(id)) {
		if (isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS) && isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE)) {
			return ! Java50Fix.isMissingOverrideAnnotationInterfaceProblem(id) || isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE_FOR_INTERFACE_METHOD_IMPLEMENTATION);
		}
		
	} else if (Java50Fix.isMissingDeprecationProblem(id)) {
		return isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS) && isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_DEPRECATED);
		
	} else if (Java50Fix.isRawTypeReferenceProblem(id)) {
		return isEnabled(CleanUpConstants.VARIABLE_DECLARATION_USE_TYPE_ARGUMENTS_FOR_RAW_TYPE_REFERENCES);
	}

	return false;
}
 
Example 2
private static boolean getRemoveBlockProposals(IInvocationContext context, ASTNode coveringNode, Collection<ICommandAccess> resultingCollections) {
	IProposableFix[] fixes= ControlStatementsFix.createRemoveBlockFix(context.getASTRoot(), coveringNode);
	if (fixes != null) {
		if (resultingCollections == null) {
			return true;
		}
		Map<String, String> options= new Hashtable<String, String>();
		options.put(CleanUpConstants.CONTROL_STATEMENTS_USE_BLOCKS, CleanUpOptions.TRUE);
		options.put(CleanUpConstants.CONTROL_STATMENTS_USE_BLOCKS_NEVER, CleanUpOptions.TRUE);
		ICleanUp cleanUp= new ControlStatementsCleanUp(options);
		for (int i= 0; i < fixes.length; i++) {
			IProposableFix fix= fixes[i];
			Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
			FixCorrectionProposal proposal= new FixCorrectionProposal(fix, cleanUp, IProposalRelevance.REMOVE_BLOCK_FIX, image, context);
			resultingCollections.add(proposal);
		}
		return true;
	}
	return false;
}
 
Example 3
private static boolean getConvertIterableLoopProposal(IInvocationContext context, ASTNode node, Collection<ICommandAccess> resultingCollections) {
	ForStatement forStatement= getEnclosingForStatementHeader(node);
	if (forStatement == null)
		return false;

	if (resultingCollections == null)
		return true;

	IProposableFix fix= ConvertLoopFix.createConvertIterableLoopToEnhancedFix(context.getASTRoot(), forStatement);
	if (fix == null)
		return false;

	Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
	Map<String, String> options= new HashMap<String, String>();
	options.put(CleanUpConstants.CONTROL_STATMENTS_CONVERT_FOR_LOOP_TO_ENHANCED, CleanUpOptions.TRUE);
	ICleanUp cleanUp= new ConvertLoopCleanUp(options);
	FixCorrectionProposal proposal= new FixCorrectionProposal(fix, cleanUp, IProposalRelevance.CONVERT_ITERABLE_LOOP_TO_ENHANCED, image, context);
	proposal.setCommandId(CONVERT_FOR_LOOP_ID);

	resultingCollections.add(proposal);
	return true;
}
 
Example 4
/**
 * {@inheritDoc}
 */
@Override
public String[] getStepDescriptions() {
	ArrayList<String> result= new ArrayList<String>();
	if (isEnabled(CleanUpConstants.FORMAT_SOURCE_CODE))
		result.add(MultiFixMessages.CodeFormatCleanUp_description);

	if (isEnabled(CleanUpConstants.FORMAT_REMOVE_TRAILING_WHITESPACES)) {
		if (isEnabled(CleanUpConstants.FORMAT_REMOVE_TRAILING_WHITESPACES_ALL)) {
			result.add(MultiFixMessages.CodeFormatCleanUp_RemoveTrailingAll_description);
		} else if (isEnabled(CleanUpConstants.FORMAT_REMOVE_TRAILING_WHITESPACES_IGNORE_EMPTY)) {
			result.add(MultiFixMessages.CodeFormatCleanUp_RemoveTrailingNoEmpty_description);
		}
	}

	if (isEnabled(CleanUpConstants.FORMAT_CORRECT_INDENTATION))
		result.add(MultiFixMessages.CodeFormatCleanUp_correctIndentation_description);

	return result.toArray(new String[result.size()]);
}
 
Example 5
private static boolean getRemoveExtraParenthesesProposals(IInvocationContext context, ASTNode covering, ArrayList<ASTNode> coveredNodes, Collection<ICommandAccess> resultingCollections) {
	ArrayList<ASTNode> nodes;
	if (context.getSelectionLength() == 0 && covering instanceof ParenthesizedExpression) {
		nodes= new ArrayList<ASTNode>();
		nodes.add(covering);
	} else {
		nodes= coveredNodes;
	}
	if (nodes.isEmpty())
		return false;

	IProposableFix fix= ExpressionsFix.createRemoveUnnecessaryParenthesisFix(context.getASTRoot(), nodes.toArray(new ASTNode[nodes.size()]));
	if (fix == null)
		return false;

	if (resultingCollections == null)
		return true;

	Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_REMOVE);
	Map<String, String> options= new Hashtable<String, String>();
	options.put(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES, CleanUpOptions.TRUE);
	options.put(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER, CleanUpOptions.TRUE);
	FixCorrectionProposal proposal= new FixCorrectionProposal(fix, new ExpressionsCleanUp(options), IProposalRelevance.REMOVE_EXTRA_PARENTHESES, image, context);
	resultingCollections.add(proposal);
	return true;
}
 
Example 6
private static boolean getAddParanoidalParenthesesProposals(IInvocationContext context, ArrayList<ASTNode> coveredNodes, Collection<ICommandAccess> resultingCollections) {

		IProposableFix fix= ExpressionsFix.createAddParanoidalParenthesisFix(context.getASTRoot(), coveredNodes.toArray(new ASTNode[coveredNodes.size()]));
		if (fix == null)
			return false;

		if (resultingCollections == null)
			return true;

		// add correction proposal
		Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CAST);
		Map<String, String> options= new Hashtable<String, String>();
		options.put(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES, CleanUpOptions.TRUE);
		options.put(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_ALWAYS, CleanUpOptions.TRUE);
		FixCorrectionProposal proposal= new FixCorrectionProposal(fix, new ExpressionsCleanUp(options), IProposalRelevance.ADD_PARANOIDAL_PARENTHESES, image, context);
		resultingCollections.add(proposal);
		return true;
	}
 
Example 7
/**
 * {@inheritDoc}
 */
@Override
protected ICleanUpFix createFix(CompilationUnit compilationUnit) throws CoreException {
	if (compilationUnit == null)
		return null;

	boolean nonStaticFields= isEnabled(CleanUpConstants.MEMBER_ACCESSES_NON_STATIC_FIELD_USE_THIS);
	boolean nonStaticMethods= isEnabled(CleanUpConstants.MEMBER_ACCESSES_NON_STATIC_METHOD_USE_THIS);
	boolean qualifyStatic= isEnabled(CleanUpConstants.MEMBER_ACCESSES_STATIC_QUALIFY_WITH_DECLARING_CLASS);

	return CodeStyleFix.createCleanUp(compilationUnit,
			nonStaticFields && isEnabled(CleanUpConstants.MEMBER_ACCESSES_NON_STATIC_FIELD_USE_THIS_ALWAYS),
			qualifyStatic && isEnabled(CleanUpConstants.MEMBER_ACCESSES_STATIC_QUALIFY_WITH_DECLARING_CLASS_INSTANCE_ACCESS),
			qualifyStatic && isEnabled(CleanUpConstants.MEMBER_ACCESSES_STATIC_QUALIFY_WITH_DECLARING_CLASS_FIELD),
			qualifyStatic && isEnabled(CleanUpConstants.MEMBER_ACCESSES_STATIC_QUALIFY_WITH_DECLARING_CLASS_SUBTYPE_ACCESS),
			nonStaticMethods && isEnabled(CleanUpConstants.MEMBER_ACCESSES_NON_STATIC_METHOD_USE_THIS_ALWAYS),
			qualifyStatic && isEnabled(CleanUpConstants.MEMBER_ACCESSES_STATIC_QUALIFY_WITH_DECLARING_CLASS_METHOD),
			nonStaticFields && isEnabled(CleanUpConstants.MEMBER_ACCESSES_NON_STATIC_FIELD_USE_THIS_IF_NECESSARY),
			nonStaticMethods && isEnabled(CleanUpConstants.MEMBER_ACCESSES_NON_STATIC_METHOD_USE_THIS_IF_NECESSARY)
			);
}
 
Example 8
/**
 * {@inheritDoc}
 */
@Override
public String[] getStepDescriptions() {
	List<String> result= new ArrayList<String>();
	if (isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS) && isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE)) {
		result.add(MultiFixMessages.Java50MultiFix_AddMissingOverride_description);
		if (isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE_FOR_INTERFACE_METHOD_IMPLEMENTATION)) {
			result.add(MultiFixMessages.Java50MultiFix_AddMissingOverride_description2);
		}
	}
	if (isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS) && isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_DEPRECATED))
		result.add(MultiFixMessages.Java50MultiFix_AddMissingDeprecated_description);
	if (isEnabled(CleanUpConstants.VARIABLE_DECLARATION_USE_TYPE_ARGUMENTS_FOR_RAW_TYPE_REFERENCES))
		result.add(MultiFixMessages.Java50CleanUp_AddTypeParameters_description);
	return result.toArray(new String[result.size()]);
}
 
Example 9
/**
 * {@inheritDoc}
 */
@Override
public void performDefaults() {
	super.performDefaults();
	if (fCurrContext == null)
		return;

	fCurrContext.getNode(JavaUI.ID_PLUGIN).remove(CleanUpConstants.SHOW_CLEAN_UP_WIZARD);
	boolean showWizard= DefaultScope.INSTANCE.getNode(JavaUI.ID_PLUGIN).getBoolean(CleanUpConstants.SHOW_CLEAN_UP_WIZARD, true);
	fShowCleanUpWizardDialogField.setDialogFieldListener(null);
	fShowCleanUpWizardDialogField.setSelection(showWizard);
	fShowCleanUpWizardDialogField.setDialogFieldListener(new IDialogFieldListener() {
		public void dialogFieldChanged(DialogField field) {
			doShowCleanUpWizard(fShowCleanUpWizardDialogField.isSelected());
           }
    });
}
 
Example 10
/**
 * {@inheritDoc}
 */
@Override
public int computeNumberOfFixes(CompilationUnit compilationUnit) {
	try {
		ICompilationUnit cu= (ICompilationUnit)compilationUnit.getJavaElement();
		if (!cu.isStructureKnown())
			return 0; //[clean up] 'Remove unnecessary $NLS-TAGS$' removes necessary ones in case of syntax errors: https://bugs.eclipse.org/bugs/show_bug.cgi?id=285814 : 
	} catch (JavaModelException e) {
		return 0;
	}
	
	int result= 0;
	IProblem[] problems= compilationUnit.getProblems();
	if (isEnabled(CleanUpConstants.ADD_MISSING_NLS_TAGS))
		result+= getNumberOfProblems(problems, IProblem.NonExternalizedStringLiteral);

	if (isEnabled(CleanUpConstants.REMOVE_UNNECESSARY_NLS_TAGS))
		result+= getNumberOfProblems(problems, IProblem.UnnecessaryNLSTag);

	return result;
}
 
Example 11
/**
 * {@inheritDoc}
 */
@Override
public String getPreview() {
	StringBuffer buf= new StringBuffer();
	buf.append("/**\n"); //$NON-NLS-1$
	buf.append(" *A Javadoc comment\n"); //$NON-NLS-1$
	buf.append("* @since 2007\n"); //$NON-NLS-1$
	buf.append(" */\n"); //$NON-NLS-1$
	buf.append("public class Engine {\n"); //$NON-NLS-1$
	buf.append("  public void start() {}\n"); //$NON-NLS-1$
	if (isEnabled(CleanUpConstants.FORMAT_REMOVE_TRAILING_WHITESPACES) && isEnabled(CleanUpConstants.FORMAT_REMOVE_TRAILING_WHITESPACES_ALL)) {
		buf.append("\n"); //$NON-NLS-1$
	} else {
		buf.append("    \n"); //$NON-NLS-1$
	}
	if (isEnabled(CleanUpConstants.FORMAT_REMOVE_TRAILING_WHITESPACES)) {
		buf.append("    public\n"); //$NON-NLS-1$
	} else {
		buf.append("    public \n"); //$NON-NLS-1$
	}
	buf.append("        void stop() {\n"); //$NON-NLS-1$
	buf.append("    }\n"); //$NON-NLS-1$
	buf.append("}\n"); //$NON-NLS-1$

	return buf.toString();
}
 
Example 12
/**
 * {@inheritDoc}
 */
@Override
public String[] getStepDescriptions() {
	List<String> result= new ArrayList<String>();
	if (isEnabled(CleanUpConstants.MEMBER_ACCESSES_NON_STATIC_FIELD_USE_THIS) && isEnabled(CleanUpConstants.MEMBER_ACCESSES_NON_STATIC_FIELD_USE_THIS_ALWAYS))
		result.add(MultiFixMessages.CodeStyleMultiFix_AddThisQualifier_description);
	if (isEnabled(CleanUpConstants.MEMBER_ACCESSES_NON_STATIC_METHOD_USE_THIS) && isEnabled(CleanUpConstants.MEMBER_ACCESSES_NON_STATIC_METHOD_USE_THIS_ALWAYS))
		result.add(MultiFixMessages.CodeStyleCleanUp_QualifyNonStaticMethod_description);
	if (isEnabled(CleanUpConstants.MEMBER_ACCESSES_NON_STATIC_FIELD_USE_THIS) && isEnabled(CleanUpConstants.MEMBER_ACCESSES_NON_STATIC_FIELD_USE_THIS_IF_NECESSARY))
		result.add(MultiFixMessages.CodeStyleCleanUp_removeFieldThis_description);
	if (isEnabled(CleanUpConstants.MEMBER_ACCESSES_NON_STATIC_METHOD_USE_THIS) && isEnabled(CleanUpConstants.MEMBER_ACCESSES_NON_STATIC_METHOD_USE_THIS_IF_NECESSARY))
		result.add(MultiFixMessages.CodeStyleCleanUp_removeMethodThis_description);
	if (isEnabled(CleanUpConstants.MEMBER_ACCESSES_STATIC_QUALIFY_WITH_DECLARING_CLASS) && isEnabled(CleanUpConstants.MEMBER_ACCESSES_STATIC_QUALIFY_WITH_DECLARING_CLASS_FIELD))
		result.add(MultiFixMessages.CodeStyleMultiFix_QualifyAccessToStaticField);
	if (isEnabled(CleanUpConstants.MEMBER_ACCESSES_STATIC_QUALIFY_WITH_DECLARING_CLASS) && isEnabled(CleanUpConstants.MEMBER_ACCESSES_STATIC_QUALIFY_WITH_DECLARING_CLASS_METHOD))
		result.add(MultiFixMessages.CodeStyleCleanUp_QualifyStaticMethod_description);
	if (isEnabled(CleanUpConstants.MEMBER_ACCESSES_STATIC_QUALIFY_WITH_DECLARING_CLASS) && isEnabled(CleanUpConstants.MEMBER_ACCESSES_STATIC_QUALIFY_WITH_DECLARING_CLASS_INSTANCE_ACCESS))
		result.add(MultiFixMessages.CodeStyleMultiFix_ChangeNonStaticAccess_description);
	if (isEnabled(CleanUpConstants.MEMBER_ACCESSES_STATIC_QUALIFY_WITH_DECLARING_CLASS) && isEnabled(CleanUpConstants.MEMBER_ACCESSES_STATIC_QUALIFY_WITH_DECLARING_CLASS_SUBTYPE_ACCESS))
		result.add(MultiFixMessages.CodeStyleMultiFix_ChangeIndirectAccessToStaticToDirect);
	return result.toArray(new String[result.size()]);
}
 
Example 13
/**
 * {@inheritDoc}
 */
@Override
public ICleanUpFix createFix(CleanUpContext context) throws CoreException {
	CompilationUnit compilationUnit= context.getAST();
	if (compilationUnit == null)
		return null;

	boolean useBlocks= isEnabled(CleanUpConstants.CONTROL_STATEMENTS_USE_BLOCKS);
	if (!useBlocks)
		return null;

	return ControlStatementsFix.createCleanUp(compilationUnit,
			isEnabled(CleanUpConstants.CONTROL_STATMENTS_USE_BLOCKS_ALWAYS),
			isEnabled(CleanUpConstants.CONTROL_STATMENTS_USE_BLOCKS_NEVER),
			isEnabled(CleanUpConstants.CONTROL_STATMENTS_USE_BLOCKS_NO_FOR_RETURN_AND_THROW));
}
 
Example 14
/**
 * {@inheritDoc}
 */
public String getColumnText(Object element, int columnIndex) {
	if (columnIndex == 0) {
		return ((IJavaProject)element).getProject().getName();
	} else if (columnIndex == 1) {

		if (fProfileIdsTable == null)
    		fProfileIdsTable= loadProfiles();

		IEclipsePreferences instancePreferences= InstanceScope.INSTANCE.getNode(JavaUI.ID_PLUGIN);

   		final String workbenchProfileId;
   		if (instancePreferences.get(CleanUpConstants.CLEANUP_PROFILE, null) != null) {
   			workbenchProfileId= instancePreferences.get(CleanUpConstants.CLEANUP_PROFILE, null);
   		} else {
   			workbenchProfileId= CleanUpConstants.DEFAULT_PROFILE;
   		}

		return getProjectProfileName((IJavaProject)element, fProfileIdsTable, workbenchProfileId);
	}
	return null;
}
 
Example 15
/**
 * {@inheritDoc}
 */
@Override
public int computeNumberOfFixes(CompilationUnit compilationUnit) {
	if (!isEnabled(CleanUpConstants.ADD_MISSING_METHODES) && !isEnabled(MAKE_TYPE_ABSTRACT))
		return 0;

	IProblemLocation[] locations= filter(convertProblems(compilationUnit.getProblems()), new int[] { IProblem.AbstractMethodMustBeImplemented, IProblem.EnumConstantMustImplementAbstractMethod });

	HashSet<ASTNode> types= new HashSet<ASTNode>();
	for (int i= 0; i < locations.length; i++) {
		ASTNode type= UnimplementedCodeFix.getSelectedTypeNode(compilationUnit, locations[i]);
		if (type != null) {
			types.add(type);
		}
	}

	return types.size();
}
 
Example 16
/**
 * {@inheritDoc}
 */
@Override
public ICleanUpFix createFix(CleanUpContext context) throws CoreException {
	CompilationUnit compilationUnit= context.getAST();
	if (compilationUnit == null)
		return null;

	boolean sortMembers= isEnabled(CleanUpConstants.SORT_MEMBERS);
	ICleanUpFix fix= SortMembersFix.createCleanUp(compilationUnit, sortMembers, sortMembers && isEnabled(CleanUpConstants.SORT_MEMBERS_ALL));
	if (fix != null) {
		if (fTouchedFiles == null) {
			fTouchedFiles= new HashSet<IResource>();
		}
		fTouchedFiles.add(((ICompilationUnit)compilationUnit.getJavaElement()).getResource());
	}
	return fix;
}
 
Example 17
/**
 * {@inheritDoc}
 */
@Override
public String getPreview() {
	StringBuffer buf= new StringBuffer();

	if (isEnabled(CleanUpConstants.CONTROL_STATMENTS_CONVERT_FOR_LOOP_TO_ENHANCED)) {
		buf.append("for (int element : ids) {\n"); //$NON-NLS-1$
		buf.append("    double value= element / 2; \n"); //$NON-NLS-1$
		buf.append("    System.out.println(value);\n"); //$NON-NLS-1$
		buf.append("}\n"); //$NON-NLS-1$
	} else {
		buf.append("for (int i = 0; i < ids.length; i++) {\n"); //$NON-NLS-1$
		buf.append("    double value= ids[i] / 2; \n"); //$NON-NLS-1$
		buf.append("    System.out.println(value);\n"); //$NON-NLS-1$
		buf.append("}\n"); //$NON-NLS-1$
	}

	return buf.toString();
}
 
Example 18
/**
 * {@inheritDoc}
 */
@Override
public void performDefaults() {
	if (ProjectScope.SCOPE.equals(fContext.getName()) && !hasSettingsInScope(fContext))
		return;

	enabled(true);

	if (ProjectScope.SCOPE.equals(fContext.getName())) {
		fSettings= CleanUpPreferenceUtil.loadSaveParticipantOptions(InstanceScope.INSTANCE);
	} else {
		fSettings= JavaPlugin.getDefault().getCleanUpRegistry().getDefaultOptions(CleanUpConstants.DEFAULT_SAVE_ACTION_OPTIONS).getMap();
	}
	settingsChanged();

	super.performDefaults();
}
 
Example 19
/**
 * {@inheritDoc}
 */
@Override
public String getPreview() {
	StringBuffer buf= new StringBuffer();

	if (isEnabled(MAKE_TYPE_ABSTRACT)) {
		buf.append("public abstract class Face implements IFace {\n"); //$NON-NLS-1$
	} else {
		buf.append("public class Face implements IFace {\n"); //$NON-NLS-1$
	}
	if (isEnabled(CleanUpConstants.ADD_MISSING_METHODES)) {
		boolean createComments= Boolean.valueOf(PreferenceConstants.getPreference(PreferenceConstants.CODEGEN_ADD_COMMENTS, null)).booleanValue();
		if (createComments)
			buf.append(indent(getOverridingMethodComment(), "    ")); //$NON-NLS-1$

		buf.append("    @Override\n"); //$NON-NLS-1$
		buf.append("    public void method() {\n"); //$NON-NLS-1$
		buf.append(indent(getMethodBody(), "        ")); //$NON-NLS-1$
		buf.append("    }\n"); //$NON-NLS-1$
	}
	buf.append("}\n"); //$NON-NLS-1$

	return buf.toString();
}
 
Example 20
private static ICleanUpCore createCleanUp(boolean isDefault) {
	Map<String, String> options = new Hashtable<>();
	options.put(CleanUpConstants.ADD_MISSING_SERIAL_VERSION_ID, CleanUpOptionsCore.TRUE);
	if (isDefault) {
		options.put(CleanUpConstants.ADD_MISSING_SERIAL_VERSION_ID_DEFAULT, CleanUpOptionsCore.TRUE);
	} else {
		options.put(CleanUpConstants.ADD_MISSING_SERIAL_VERSION_ID_GENERATED, CleanUpOptionsCore.TRUE);
	}
	return new PotentialProgrammingProblemsCleanUpCore(options);
}
 
Example 21
public static void addUnnecessaryCastProposal(IInvocationContext context, IProblemLocationCore problem, Collection<ChangeCorrectionProposal> proposals) {
	IProposableFix fix = UnusedCodeFixCore.createRemoveUnusedCastFix(context.getASTRoot(), problem);
	if (fix != null) {
		Map<String, String> options = new Hashtable<>();
		options.put(CleanUpConstants.REMOVE_UNNECESSARY_CASTS, CleanUpOptionsCore.TRUE);
		FixCorrectionProposal proposal = new FixCorrectionProposal(fix, new UnnecessaryCodeCleanUpCore(options), IProposalRelevance.REMOVE_UNUSED_CAST, context);
		proposals.add(proposal);
	}
}
 
Example 22
boolean useBlocks(IJavaProject project) {
	if (CleanUpOptions.TRUE.equals(PreferenceConstants.getPreference(CleanUpConstants.CONTROL_STATEMENTS_USE_BLOCKS, project))) {
		return CleanUpOptions.TRUE.equals(PreferenceConstants.getPreference(CleanUpConstants.CONTROL_STATMENTS_USE_BLOCKS_ALWAYS, project))
				|| CleanUpOptions.TRUE.equals(PreferenceConstants.getPreference(CleanUpConstants.CONTROL_STATMENTS_USE_BLOCKS_NO_FOR_RETURN_AND_THROW, project));
	}
	return false;
}
 
Example 23
/**
    * {@inheritDoc}
    */
   @Override
public RefactoringStatus checkPreConditions(IJavaProject project, ICompilationUnit[] compilationUnits, IProgressMonitor monitor) throws CoreException {

	if (isEnabled(CleanUpConstants.ORGANIZE_IMPORTS)) {
   		fCodeGeneratorSettings= JavaPreferencesSettings.getCodeGenerationSettings(project);
   		fStatus= new RefactoringStatus();
	}

	return super.checkPreConditions(project, compilationUnits, monitor);
   }
 
Example 24
private boolean showWizard() {
	IEclipsePreferences instanceNode= InstanceScope.INSTANCE.getNode(JavaUI.ID_PLUGIN);
	if (instanceNode.get(CleanUpConstants.SHOW_CLEAN_UP_WIZARD, null) != null)
		return instanceNode.getBoolean(CleanUpConstants.SHOW_CLEAN_UP_WIZARD, true);

	IEclipsePreferences defaultNode= DefaultScope.INSTANCE.getNode(JavaUI.ID_PLUGIN);
	return defaultNode.getBoolean(CleanUpConstants.SHOW_CLEAN_UP_WIZARD, true);
}
 
Example 25
private void installPreferenceListener() {
   fPreferenceChangeListener= new IPreferenceChangeListener() {
	public void preferenceChange(PreferenceChangeEvent event) {
		if (event.getKey().equals(CleanUpConstants.SHOW_CLEAN_UP_WIZARD)) {
			updateActionLabel();
		}
	}
};
InstanceScope.INSTANCE.getNode(JavaUI.ID_PLUGIN).addPreferenceChangeListener(fPreferenceChangeListener);
  }
 
Example 26
@Override
protected ICleanUp[] getCleanUps(ICompilationUnit[] units) {
	Map<String, String> settings= new Hashtable<String, String>();
	settings.put(CleanUpConstants.FORMAT_SOURCE_CODE, CleanUpOptions.TRUE);

	return new ICleanUp[] {
			new CodeFormatCleanUp(settings)
	};
}
 
Example 27
/**
    * {@inheritDoc}
    */
   @Override
public ICleanUpFix createFix(CleanUpContext context) throws CoreException {
   	CompilationUnit compilationUnit= context.getAST();
   	if (compilationUnit == null)
   		return null;

	return ImportsFix.createCleanUp(compilationUnit, fCodeGeneratorSettings,
			isEnabled(CleanUpConstants.ORGANIZE_IMPORTS), fStatus);
}
 
Example 28
public static void addNLSProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) throws CoreException {
	final ICompilationUnit cu= context.getCompilationUnit();
	if (cu == null || !cu.exists()){
		return;
	}
	String name= CorrectionMessages.LocalCorrectionsSubProcessor_externalizestrings_description;

	ChangeCorrectionProposal proposal= new ChangeCorrectionProposal(name, null, IProposalRelevance.EXTERNALIZE_STRINGS, JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE)) {
		@Override
		public void apply(IDocument document) {
			ExternalizeWizard.open(cu, JavaPlugin.getActiveWorkbenchShell());
		}
		@Override
		public Object getAdditionalProposalInfo(IProgressMonitor monitor) {
			return CorrectionMessages.LocalCorrectionsSubProcessor_externalizestrings_additional_info;
		}

	};
	proposals.add(proposal);

	IProposableFix fix= StringFix.createFix(context.getASTRoot(), problem, false, true);
	if (fix != null) {
		Image image= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_NLS_NEVER_TRANSLATE);
		Map<String, String> options= new Hashtable<String, String>();
		options.put(CleanUpConstants.ADD_MISSING_NLS_TAGS, CleanUpOptions.TRUE);
		FixCorrectionProposal addNLS= new FixCorrectionProposal(fix, new StringCleanUp(options), IProposalRelevance.ADD_MISSING_NLS_TAGS, image, context);
		addNLS.setCommandId(ADD_NON_NLS_ID);
		proposals.add(addNLS);
	}
}
 
Example 29
private boolean requireAST() {
	boolean useBlocks= isEnabled(CleanUpConstants.CONTROL_STATEMENTS_USE_BLOCKS);

	if (!useBlocks)
		return false;

	return isEnabled(CleanUpConstants.CONTROL_STATMENTS_USE_BLOCKS_ALWAYS) ||
	       isEnabled(CleanUpConstants.CONTROL_STATMENTS_USE_BLOCKS_NEVER) ||
	       isEnabled(CleanUpConstants.CONTROL_STATMENTS_USE_BLOCKS_NO_FOR_RETURN_AND_THROW);
}
 
Example 30
public static void addUnnecessaryCastProposal(IInvocationContext context, IProblemLocation problem,  Collection<ICommandAccess> proposals) {
	IProposableFix fix= UnusedCodeFix.createRemoveUnusedCastFix(context.getASTRoot(), problem);
	if (fix != null) {
		Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
		Map<String, String> options= new Hashtable<String, String>();
		options.put(CleanUpConstants.REMOVE_UNNECESSARY_CASTS, CleanUpOptions.TRUE);
		FixCorrectionProposal proposal= new FixCorrectionProposal(fix, new UnnecessaryCodeCleanUp(options), IProposalRelevance.REMOVE_UNUSED_CAST, image, context);
		proposals.add(proposal);
	}
}