public static void getWrongPackageDeclNameProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) throws CoreException { ICompilationUnit cu= context.getCompilationUnit(); boolean isLinked= cu.getResource().isLinked(); // correct package declaration int relevance= cu.getPackageDeclarations().length == 0 ? IProposalRelevance.MISSING_PACKAGE_DECLARATION : IProposalRelevance.CORRECT_PACKAGE_DECLARATION; // bug 38357 proposals.add(new CorrectPackageDeclarationProposal(cu, problem, relevance)); // move to package IPackageDeclaration[] packDecls= cu.getPackageDeclarations(); String newPackName= packDecls.length > 0 ? packDecls[0].getElementName() : ""; //$NON-NLS-1$ IPackageFragmentRoot root= JavaModelUtil.getPackageFragmentRoot(cu); IPackageFragment newPack= root.getPackageFragment(newPackName); ICompilationUnit newCU= newPack.getCompilationUnit(cu.getElementName()); if (!newCU.exists() && !isLinked) { String label; if (newPack.isDefaultPackage()) { label= Messages.format(CorrectionMessages.ReorgCorrectionsSubProcessor_movecu_default_description, BasicElementLabels.getFileName(cu)); } else { String packageLabel= JavaElementLabels.getElementLabel(newPack, JavaElementLabels.ALL_DEFAULT); label= Messages.format(CorrectionMessages.ReorgCorrectionsSubProcessor_movecu_description, new Object[] { BasicElementLabels.getFileName(cu), packageLabel }); } CompositeChange composite= new CompositeChange(label); composite.add(new CreatePackageChange(newPack)); composite.add(new MoveCompilationUnitChange(cu, newPack)); proposals.add(new ChangeCorrectionProposal(label, composite, IProposalRelevance.MOVE_CU_TO_PACKAGE, JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_MOVE))); } }
public static void getWrongPackageDeclNameProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) throws CoreException { ICompilationUnit cu= context.getCompilationUnit(); boolean isLinked= cu.getResource().isLinked(); // correct package declaration int relevance= cu.getPackageDeclarations().length == 0 ? IProposalRelevance.MISSING_PACKAGE_DECLARATION : IProposalRelevance.CORRECT_PACKAGE_DECLARATION; // bug 38357 if (CorrectPackageDeclarationProposal.isValidProposal(cu)) { proposals.add(new CorrectPackageDeclarationProposal(cu, problem, relevance)); } // move to package IPackageDeclaration[] packDecls= cu.getPackageDeclarations(); String newPackName= packDecls.length > 0 ? packDecls[0].getElementName() : ""; //$NON-NLS-1$ IPackageFragmentRoot root= JavaModelUtil.getPackageFragmentRoot(cu); IPackageFragment newPack= root.getPackageFragment(newPackName); ICompilationUnit newCU= newPack.getCompilationUnit(cu.getElementName()); if (!newCU.exists() && !isLinked) { String label; if (newPack.isDefaultPackage()) { label= Messages.format(CorrectionMessages.ReorgCorrectionsSubProcessor_movecu_default_description, BasicElementLabels.getFileName(cu)); } else { String packageLabel= JavaElementLabels.getElementLabel(newPack, JavaElementLabels.ALL_DEFAULT); label= Messages.format(CorrectionMessages.ReorgCorrectionsSubProcessor_movecu_description, new Object[] { BasicElementLabels.getFileName(cu), packageLabel }); } CompositeChange composite= new CompositeChange(label); composite.add(new CreatePackageChange(newPack)); composite.add(new MoveCompilationUnitChange(cu, newPack)); proposals.add(new ChangeCorrectionProposal(label, composite, IProposalRelevance.MOVE_CU_TO_PACKAGE, JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_MOVE))); } }