Search in sources :

Example 6 with RefactoringCorrectionProposal

use of org.eclipse.jdt.internal.ui.text.correction.proposals.RefactoringCorrectionProposal in project che by eclipse.

the class QuickAssistProcessor method getInlineLocalProposal.

private static boolean getInlineLocalProposal(IInvocationContext context, final ASTNode node, Collection<ICommandAccess> proposals) throws CoreException {
    if (!(node instanceof SimpleName))
        return false;
    SimpleName name = (SimpleName) node;
    IBinding binding = name.resolveBinding();
    if (!(binding instanceof IVariableBinding))
        return false;
    IVariableBinding varBinding = (IVariableBinding) binding;
    if (varBinding.isField() || varBinding.isParameter())
        return false;
    ASTNode decl = context.getASTRoot().findDeclaringNode(varBinding);
    if (!(decl instanceof VariableDeclarationFragment) || decl.getLocationInParent() != VariableDeclarationStatement.FRAGMENTS_PROPERTY)
        return false;
    if (proposals == null) {
        return true;
    }
    InlineTempRefactoring refactoring = new InlineTempRefactoring((VariableDeclaration) decl);
    if (refactoring.checkInitialConditions(new NullProgressMonitor()).isOK()) {
        String label = CorrectionMessages.QuickAssistProcessor_inline_local_description;
        Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
        RefactoringCorrectionProposal proposal = new RefactoringCorrectionProposal(label, context.getCompilationUnit(), refactoring, IProposalRelevance.INLINE_LOCAL, image);
        proposal.setCommandId(INLINE_LOCAL_ID);
        proposals.add(proposal);
    }
    return true;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) InlineTempRefactoring(org.eclipse.jdt.internal.corext.refactoring.code.InlineTempRefactoring) Image(org.eclipse.swt.graphics.Image) RefactoringCorrectionProposal(org.eclipse.jdt.internal.ui.text.correction.proposals.RefactoringCorrectionProposal)

Aggregations

RefactoringCorrectionProposal (org.eclipse.jdt.internal.ui.text.correction.proposals.RefactoringCorrectionProposal)6 Image (org.eclipse.swt.graphics.Image)6 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)5 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)4 LinkedProposalModel (org.eclipse.jdt.internal.corext.fix.LinkedProposalModel)4 IType (org.eclipse.jdt.core.IType)2 ConvertAnonymousToNestedRefactoring (org.eclipse.jdt.internal.corext.refactoring.code.ConvertAnonymousToNestedRefactoring)2 ExtractMethodRefactoring (org.eclipse.jdt.internal.corext.refactoring.code.ExtractMethodRefactoring)2 InlineTempRefactoring (org.eclipse.jdt.internal.corext.refactoring.code.InlineTempRefactoring)2 PromoteTempToFieldRefactoring (org.eclipse.jdt.internal.corext.refactoring.code.PromoteTempToFieldRefactoring)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ASTRewrite (org.eclipse.jdt.core.dom.rewrite.ASTRewrite)1 ImportRewrite (org.eclipse.jdt.core.dom.rewrite.ImportRewrite)1 ImportRewriteContext (org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext)1 ListRewrite (org.eclipse.jdt.core.dom.rewrite.ListRewrite)1 ContextSensitiveImportRewriteContext (org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext)1 ExtractConstantRefactoring (org.eclipse.jdt.internal.corext.refactoring.code.ExtractConstantRefactoring)1 ExtractTempRefactoring (org.eclipse.jdt.internal.corext.refactoring.code.ExtractTempRefactoring)1 SurroundWithTryCatchRefactoring (org.eclipse.jdt.internal.corext.refactoring.surround.SurroundWithTryCatchRefactoring)1