/** * Adds a linked position proposal to the group with the given id. * @param groupID The id of the group that should present the proposal * @param displayString The name of the proposal * @param proposal The string to insert. * @param image The image to show for the position proposal or <code>null</code> if * no image is desired. * @deprecated use {@link #addLinkedPositionProposal(String, String, Image)} instead */ @Deprecated public void addLinkedPositionProposal(String groupID, String displayString, String proposal, Image image) { addLinkedPositionProposal(groupID, proposal, image); }
@Override public Object getAdditionalProposalInfo(IProgressMonitor monitor) { StringBuilder result= new StringBuilder(); IStatus status= getFixStatus(); if (status != null && !status.isOK()) { result.append("<b>"); //$NON-NLS-1$ if (status.getSeverity() == IStatus.WARNING) { result.append(CorrectionMessages.FixCorrectionProposal_WarningAdditionalProposalInfo); } else if (status.getSeverity() == IStatus.ERROR) { result.append(CorrectionMessages.FixCorrectionProposal_ErrorAdditionalProposalInfo); } result.append("</b>"); //$NON-NLS-1$ result.append(status.getMessage()); result.append("<br><br>"); //$NON-NLS-1$ } String info= fFix.getAdditionalProposalInfo(); if (info != null) { result.append(info); } else { result.append(super.getAdditionalProposalInfo(monitor)); } return result.toString(); }
/** * Adds a linked position proposal to the group with the given id. * @param groupID The id of the group that should present the proposal * @param type The binding to use as type name proposal. */ public void addLinkedPositionProposal(String groupID, ITypeBinding type) { getLinkedProposalModel().getPositionGroup(groupID, true).addProposal(type, getCompilationUnit(), 10); }
LinkedCorrectionProposal proposal= new LinkedCorrectionProposal(label, cu, rewrite, IProposalRelevance.VOID_METHOD_RETURNS, image); ImportRewrite imports= proposal.createImportRewrite(astRoot); ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(methodDeclaration, imports); Type newReturnType= imports.addImport(binding, ast, importRewriteContext, TypeLocation.RETURN_TYPE); proposal.addLinkedPosition(rewrite.track(newReturnType), true, key); ITypeBinding[] bindings= ASTResolving.getRelaxingTypes(ast, binding); for (int i= 0; i < bindings.length; i++) { proposal.addLinkedPositionProposal(key, bindings[i]); proposal.addLinkedPosition(rewrite.track(commentStart), false, "comment_start"); //$NON-NLS-1$
LinkedCorrectionProposal proposal= new LinkedCorrectionProposal(label, cu, rewrite, IProposalRelevance.CAST_AND_ASSIGN, image); proposal.addLinkedPositionProposal(KEY_NAME, varNames[i], null); proposal.addLinkedPosition(rewrite.track(vdf.getName()), true, KEY_NAME); proposal.addLinkedPosition(rewrite.track(vds.getType()), false, KEY_TYPE); proposal.addLinkedPosition(rewrite.track(castExpression.getType()), false, KEY_TYPE); proposal.setEndPosition(rewrite.track(vds)); // set cursor after expression statement
ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST()); ICompilationUnit cu= context.getCompilationUnit(); LinkedCorrectionProposal proposal= new LinkedCorrectionProposal(label, cu, rewrite, IProposalRelevance.OVERRIDE_DEFAULT_METHOD, image); ImportRewrite importRewrite= proposal.createImportRewrite(astRoot); ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(astRoot, typeNode.getStartPosition(), importRewrite); CodeGenerationSettings settings= JavaPreferencesSettings.getCodeGenerationSettings(cu.getJavaProject()); BodyDeclarationRewrite.create(rewrite, typeNode).insert(stub, null); proposal.setEndPosition(rewrite.track(stub)); } catch (CoreException e) { JavaPlugin.log(e);
LinkedCorrectionProposal proposal= new LinkedCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.JOIN_VARIABLE_DECLARATION, image); proposal.setCommandId(SPLIT_JOIN_VARIABLE_DECLARATION_ID); proposal.setEndPosition(rewrite.track(fragment.getName())); resultingCollections.add(proposal); return true;
Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); LinkedCorrectionProposal proposal= new LinkedCorrectionProposal(label, cu, rewrite, IProposalRelevance.INITIALIZE_VARIABLE, image); proposal.addLinkedPosition(rewrite.track(expression), false, "initializer"); //$NON-NLS-1$ proposals.add(proposal);
private static boolean getConvertMethodReferenceToLambdaProposal(IInvocationContext context, ASTNode covering, Collection<ICommandAccess> resultingCollections) throws JavaModelException { MethodReference methodReference; if (covering instanceof MethodReference) { methodReference= (MethodReference) covering; } else if (covering.getParent() instanceof MethodReference) { methodReference= (MethodReference) covering.getParent(); } else { return false; } IMethodBinding functionalMethod= getFunctionalMethodForMethodReference(methodReference); if (functionalMethod == null || functionalMethod.isGenericMethod()) { // generic lambda expressions are not allowed return false; } if (resultingCollections == null) return true; ASTRewrite rewrite= ASTRewrite.create(methodReference.getAST()); LinkedProposalModel linkedProposalModel= new LinkedProposalModel(); LambdaExpression lambda= convertMethodRefernceToLambda(methodReference, functionalMethod, context.getASTRoot(), rewrite, linkedProposalModel, false); // add proposal String label= CorrectionMessages.QuickAssistProcessor_convert_to_lambda_expression; Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); LinkedCorrectionProposal proposal= new LinkedCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.CONVERT_METHOD_REFERENCE_TO_LAMBDA, image); proposal.setLinkedProposalModel(linkedProposalModel); proposal.setEndPosition(rewrite.track(lambda)); resultingCollections.add(proposal); return true; }
Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); final String KEY_NAME= "name"; //$NON-NLS-1$ final LinkedCorrectionProposal proposal= new LinkedCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.INVERSE_BOOLEAN_VARIABLE, image); proposal.addLinkedPositionProposal(KEY_NAME, newIdentifier, null); proposal.addLinkedPositionProposal(KEY_NAME, oldIdentifier, null); proposal.addLinkedPosition(rewrite.track(newName), name == coveringName, KEY_NAME);
LinkedCorrectionProposal proposal= new LinkedCorrectionProposal(label, cu, rewrite, IProposalRelevance.ADD_ADDITIONAL_CATCH, image); ImportRewrite imports= proposal.createImportRewrite(context.getASTRoot()); ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(decl, imports); proposal.addLinkedPosition(rewrite.track(var.getType()), false, typeKey); proposal.addLinkedPosition(rewrite.track(var.getName()), false, nameKey); addExceptionTypeLinkProposals(proposal, excBinding, typeKey); Image image= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_EXCEPTION); ASTRewrite rewrite= ASTRewrite.create(ast); LinkedCorrectionProposal proposal= new LinkedCorrectionProposal(label, cu, rewrite, IProposalRelevance.ADD_EXCEPTIONS_TO_EXISTING_CATCH, image); ImportRewrite imports= proposal.createImportRewrite(context.getASTRoot()); ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(decl, imports); proposal.addLinkedPosition(rewrite.track(type2), false, typeKey); addExceptionTypeLinkProposals(proposal, excBinding, typeKey); proposal.addLinkedPosition(rewrite.track(type2), false, typeKey); addExceptionTypeLinkProposals(proposal, excBinding, typeKey); Image image= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_EXCEPTION); ASTRewrite rewrite= ASTRewrite.create(ast); LinkedCorrectionProposal proposal= new LinkedCorrectionProposal(label, cu, rewrite, IProposalRelevance.ADD_ADDITIONAL_MULTI_CATCH, image); ImportRewrite imports= proposal.createImportRewrite(context.getASTRoot()); ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(decl, imports); proposal.addLinkedPosition(rewrite.track(type2), false, typeKey); addExceptionTypeLinkProposals(proposal, excBinding, typeKey);
/** * Sets the end position of the linked mode to the end of the passed range. * @param position The position that describes the end position of the linked mode. */ public void setEndPosition(ITrackedNodePosition position) { getLinkedProposalModel().setEndPosition(position); }
Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); LinkedCorrectionProposal proposal= new LinkedCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.ADD_TYPE_TO_ARRAY_INITIALIZER, image); ImportRewrite imports= proposal.createImportRewrite(context.getASTRoot()); ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(node, imports); String typeName= imports.addImport(typeBinding, importRewriteContext);
LinkedCorrectionProposal proposal= new LinkedCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.THROW_ALLOCATED_OBJECT, image); proposal.setEndPosition(rewrite.track(throwStatement)); proposals.add(proposal); relevance= IProposalRelevance.RETURN_ALLOCATED_OBJECT; LinkedCorrectionProposal proposal= new LinkedCorrectionProposal(label, context.getCompilationUnit(), rewrite, relevance, image); proposal.setEndPosition(rewrite.track(returnStatement)); proposals.add(proposal);
LinkedCorrectionProposal proposal= new LinkedCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.COMBINE_STRINGS, image); resultingCollections.add(proposal); return true;
@Override public int getRelevance() { IStatus status= getFixStatus(); if (status != null && !status.isOK()) { return super.getRelevance() - 100; } else { return super.getRelevance(); } }
@Override public Image getImage() { IStatus status= getFixStatus(); if (status != null && !status.isOK()) { ImageImageDescriptor image= new ImageImageDescriptor(super.getImage()); int flag= JavaElementImageDescriptor.WARNING; if (status.getSeverity() == IStatus.ERROR) { flag= JavaElementImageDescriptor.ERROR; } else if (status.getSeverity() == IStatus.INFO) { flag= JavaElementImageDescriptor.INFO; } ImageDescriptor composite= new JavaElementImageDescriptor(image, flag, new Point(image.getImageData().width, image.getImageData().height)); return composite.createImage(); } else { return super.getImage(); } }
@Override protected void performChange(IEditorPart part, IDocument document) throws CoreException { try { super.performChange(part, document); if (part == null) { return; } if (fLinkedProposalModel != null) { if (fLinkedProposalModel.hasLinkedPositions() && part instanceof JavaEditor) { // enter linked mode ITextViewer viewer= ((JavaEditor) part).getViewer(); new LinkedProposalModelPresenter().enterLinkedMode(viewer, part, didOpenEditor(), fLinkedProposalModel); } else if (part instanceof ITextEditor) { LinkedProposalPositionGroup.PositionInformation endPosition= fLinkedProposalModel.getEndPosition(); if (endPosition != null) { // select a result int pos= endPosition.getOffset() + endPosition.getLength(); ((ITextEditor) part).selectAndReveal(pos, 0); } } } } catch (BadLocationException e) { throw new CoreException(JavaUIStatus.createError(IStatus.ERROR, e)); } } }
LinkedCorrectionProposal proposal= new LinkedCorrectionProposal(label, cu, rewrite, IProposalRelevance.VOID_METHOD_RETURNS, image); ImportRewrite imports= proposal.createImportRewrite(astRoot); ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(methodDeclaration, imports); Type newReturnType= imports.addImport(binding, ast, importRewriteContext); proposal.addLinkedPosition(rewrite.track(newReturnType), true, key); ITypeBinding[] bindings= ASTResolving.getRelaxingTypes(ast, binding); for (int i= 0; i < bindings.length; i++) { proposal.addLinkedPositionProposal(key, bindings[i]); proposal.addLinkedPosition(rewrite.track(commentStart), false, "comment_start"); //$NON-NLS-1$
String label= Messages.format(CorrectionMessages.QuickAssistProcessor_convert_to_string_buffer_description, mechanismName); Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); LinkedCorrectionProposal proposal= new LinkedCorrectionProposal(label, cu, rewrite, IProposalRelevance.CONVERT_TO_STRING_BUFFER, image); proposal.setCommandId(CONVERT_TO_STRING_BUFFER_ID); frag.setName(bufferNameDeclaration); proposal.addLinkedPosition(rewrite.track(bufferNameDeclaration), true, groupID); for (int i= 0; i < newBufferNames.length; i++) { proposal.addLinkedPositionProposal(groupID, newBufferNames[i], null); proposal.addLinkedPosition(rewrite.track(bufferNameReference), true, groupID); proposal.setEndPosition(rewrite.track(lastAppend)); if (insertAfter != null) { rewrite.remove(enclosingStatement, null); SimpleName bufferNameReference= ast.newSimpleName(bufferName); bufferToString.setExpression(bufferNameReference); proposal.addLinkedPosition(rewrite.track(bufferNameReference), true, groupID); proposal.setEndPosition(rewrite.track(bufferToString));