Search in sources :

Example 1 with InlineTempRefactoring

use of org.eclipse.jdt.internal.corext.refactoring.code.InlineTempRefactoring 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

NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 InlineTempRefactoring (org.eclipse.jdt.internal.corext.refactoring.code.InlineTempRefactoring)1 RefactoringCorrectionProposal (org.eclipse.jdt.internal.ui.text.correction.proposals.RefactoringCorrectionProposal)1 Image (org.eclipse.swt.graphics.Image)1