CodeActionContext clone(CodeActionContext codeActionContext) { if (codeActionContext == null) { return null; } List<Diagnostic> diagnostics = codeActionContext.getDiagnostics(); List<String> only = codeActionContext.getOnly(); CodeActionContext cloned = new CodeActionContext(); cloned.setDiagnostics(cloneD(diagnostics)); cloned.setOnly(only == null ? null : new ArrayList<>(only)); return cloned; }
public CodeActionContextDto(org.eclipse.lsp4j.CodeActionContext o) { if (o.getOnly() == null) { setOnly((java.util.List<java.lang.String>)null); } else { ArrayList<java.lang.String> onlyVal= new ArrayList<java.lang.String>(); for (java.lang.String onlyValX : o.getOnly()) { java.lang.String onlyValY = (java.lang.String)makeDto(onlyValX);; onlyVal.add(onlyValY); } setOnly((java.util.List<java.lang.String>)onlyVal); } if (o.getDiagnostics() == null) { setDiagnostics((java.util.List<org.eclipse.lsp4j.Diagnostic>)null); } else { ArrayList<org.eclipse.lsp4j.Diagnostic> diagnosticsVal= new ArrayList<org.eclipse.lsp4j.Diagnostic>(); for (org.eclipse.lsp4j.Diagnostic diagnosticsValX : o.getDiagnostics()) { org.eclipse.lsp4j.Diagnostic diagnosticsValY = new DiagnosticDto(diagnosticsValX); diagnosticsVal.add(diagnosticsValY); } setDiagnostics((java.util.List<org.eclipse.lsp4j.Diagnostic>)diagnosticsVal); } }
private boolean appliesToContext(CodeActionContext context) { if (context!=null) { return context.getDiagnostics().stream().anyMatch(diag -> this.diagMsg == null || this.diagMsg.equals(diag.getMessage()) ); } return true; } }
@Override @Pure public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((this.textDocument== null) ? 0 : this.textDocument.hashCode()); result = prime * result + ((this.range== null) ? 0 : this.range.hashCode()); return prime * result + ((this.context== null) ? 0 : this.context.hashCode()); } }
@Override @Pure public boolean equals(final Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; CodeActionParams other = (CodeActionParams) obj; if (this.textDocument == null) { if (other.textDocument != null) return false; } else if (!this.textDocument.equals(other.textDocument)) return false; if (this.range == null) { if (other.range != null) return false; } else if (!this.range.equals(other.range)) return false; if (this.context == null) { if (other.context != null) return false; } else if (!this.context.equals(other.context)) return false; return true; }
public List<CodeAction> getCodeActions(TextDocumentInfo doc, Diagnostic problem) throws Exception { CodeActionContext context = new CodeActionContext(ImmutableList.of(problem)); List<Either<Command, org.eclipse.lsp4j.CodeAction>> actions = getServer().getTextDocumentService().codeAction(new CodeActionParams(doc.getId(), problem.getRange(), context)).get(); return actions.stream() .map(e -> e.getLeft()) .map((command) -> new CodeAction(this, command)) .collect(Collectors.toList()); }
InnovationContext context = new InnovationContext(unit, start, end - start); context.setASTRoot(getASTRoot(unit)); IProblemLocationCore[] locations = this.getProblemLocationCores(unit, params.getContext().getDiagnostics()); if (params.getContext().getOnly() != null && !params.getContext().getOnly().isEmpty()) { List<CUCorrectionProposal> resultList = new ArrayList<>(); List<String> acceptedActionKinds = params.getContext().getOnly(); for (CUCorrectionProposal proposal : candidates) { if (acceptedActionKinds.contains(proposal.getKind())) {
int line = params.getRange().getStart().getLine(); LSDocument document = new LSDocument(fileUri); List<Diagnostic> diagnostics = params.getContext().getDiagnostics();
@Override @Pure public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((this.textDocument== null) ? 0 : this.textDocument.hashCode()); result = prime * result + ((this.range== null) ? 0 : this.range.hashCode()); return prime * result + ((this.context== null) ? 0 : this.context.hashCode()); } }
@Override @Pure public boolean equals(final Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; CodeActionParams other = (CodeActionParams) obj; if (this.textDocument == null) { if (other.textDocument != null) return false; } else if (!this.textDocument.equals(other.textDocument)) return false; if (this.range == null) { if (other.range != null) return false; } else if (!this.range.equals(other.range)) return false; if (this.context == null) { if (other.context != null) return false; } else if (!this.context.equals(other.context)) return false; return true; }
private Optional<Either<Command, CodeAction>> getCodeActionFromProposal(CUCorrectionProposal proposal, CodeActionContext context) throws CoreException { String name = proposal.getName(); ICompilationUnit unit = proposal.getCompilationUnit(); WorkspaceEdit edit = convertChangeToWorkspaceEdit(unit, proposal.getChange()); if (!ChangeUtil.hasChanges(edit)) { return Optional.empty(); } Command command = new Command(name, COMMAND_ID_APPLY_EDIT, Collections.singletonList(edit)); if (preferenceManager.getClientPreferences().isSupportedCodeActionKind(proposal.getKind())) { CodeAction codeAction = new CodeAction(name); codeAction.setKind(proposal.getKind()); codeAction.setCommand(command); codeAction.setDiagnostics(context.getDiagnostics()); return Optional.of(Either.forRight(codeAction)); } else { return Optional.of(Either.forLeft(command)); } }