/** * {@inheritDoc} */ public int maximalNumberOfFixes(CompilationUnit compilationUnit) { 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; } }
@Override public CleanUpRequirements getRequirements() { boolean requireAST= requireAST(); Map<String, String> requiredOptions= requireAST ? getRequiredOptions() : null; return new CleanUpRequirements(requireAST, false, false, requiredOptions); }
protected ICleanUp[] createPreviewCleanUps(Map values) { return new ICleanUp[] { new UnusedCodeCleanUp(values), new UnnecessaryCodeCleanUp(values), new StringCleanUp(values) }; }
public static void getUnnecessaryNLSTagProposals(IInvocationContext context, IProblemLocation problem, Collection proposals) throws CoreException { IFix fix= StringFix.createFix(context.getASTRoot(), problem, true, false); if (fix != null) { Image image= JavaPlugin.getDefault().getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE); Map options= new Hashtable(); options.put(CleanUpConstants.REMOVE_UNNECESSARY_NLS_TAGS, CleanUpConstants.TRUE); FixCorrectionProposal proposal= new FixCorrectionProposal(fix, new StringCleanUp(options), 6, image, context); proposal.setCommandId(REMOVE_UNNECESSARY_NLS_TAG_ID); proposals.add(proposal); } }
@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; } }
public static void getUnnecessaryNLSTagProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) throws CoreException { IProposableFix fix= StringFix.createFix(context.getASTRoot(), problem, true, false); if (fix != null) { Image image= JavaPlugin.getDefault().getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE); Map<String, String> options= new Hashtable<>(); options.put(CleanUpConstants.REMOVE_UNNECESSARY_NLS_TAGS, CleanUpOptions.TRUE); FixCorrectionProposal proposal= new FixCorrectionProposal(fix, new StringCleanUp(options), IProposalRelevance.UNNECESSARY_NLS_TAG, image, context); proposal.setCommandId(REMOVE_UNNECESSARY_NLS_TAG_ID); proposals.add(proposal); } }
@Override public CleanUpRequirements getRequirements() { boolean requireAST= requireAST(); Map<String, String> requiredOptions= requireAST ? getRequiredOptions() : null; return new CleanUpRequirements(requireAST, false, false, requiredOptions); }
private Map<String, String> getRequiredOptions() { Map<String, String> result= new Hashtable<>(); if (isEnabled(CleanUpConstants.ADD_MISSING_NLS_TAGS) || isEnabled(CleanUpConstants.REMOVE_UNNECESSARY_NLS_TAGS)) result.put(JavaCore.COMPILER_PB_NON_NLS_STRING_LITERAL, JavaCore.WARNING); return result; }
@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; } }
public static void getUnnecessaryNLSTagProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) throws CoreException { IProposableFix fix= StringFix.createFix(context.getASTRoot(), problem, true, false); if (fix != null) { Image image= JavaPlugin.getDefault().getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE); Map<String, String> options= new Hashtable<>(); options.put(CleanUpConstants.REMOVE_UNNECESSARY_NLS_TAGS, CleanUpOptions.TRUE); FixCorrectionProposal proposal= new FixCorrectionProposal(fix, new StringCleanUp(options), IProposalRelevance.UNNECESSARY_NLS_TAG, image, context); proposal.setCommandId(REMOVE_UNNECESSARY_NLS_TAG_ID); proposals.add(proposal); } }
@Override protected AbstractCleanUp[] createPreviewCleanUps(Map<String, String> values) { return new AbstractCleanUp[] { new UnusedCodeCleanUp(values), new UnnecessaryCodeCleanUp(values), new StringCleanUp(values), new TypeParametersCleanUp(values) }; }
private Map<String, String> getRequiredOptions() { Map<String, String> result= new Hashtable<>(); if (isEnabled(CleanUpConstants.ADD_MISSING_NLS_TAGS) || isEnabled(CleanUpConstants.REMOVE_UNNECESSARY_NLS_TAGS)) result.put(JavaCore.COMPILER_PB_NON_NLS_STRING_LITERAL, JavaCore.WARNING); return result; }
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<>(); 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); } }
@Override protected ICleanUpFix createFix(CompilationUnit compilationUnit, IProblemLocation[] problems) throws CoreException { if (compilationUnit == null) return null; return StringFix.createCleanUp(compilationUnit, problems, isEnabled(CleanUpConstants.ADD_MISSING_NLS_TAGS), isEnabled(CleanUpConstants.REMOVE_UNNECESSARY_NLS_TAGS)); }
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<>(); 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); } }