Search in sources :

Example 1 with RefactoringProblem

use of org.dartlang.analysis.server.protocol.RefactoringProblem in project intellij-plugins by JetBrains.

the class GetRefactoringProcessor method process.

public void process(String requestId, JsonObject resultObject, RequestError requestError) {
    if (resultObject != null) {
        try {
            // problems
            List<RefactoringProblem> initialProblems = getRefactoringProblems(resultObject, "initialProblems");
            List<RefactoringProblem> optionsProblems = getRefactoringProblems(resultObject, "optionsProblems");
            List<RefactoringProblem> finalProblems = getRefactoringProblems(resultObject, "finalProblems");
            // change
            SourceChange change = null;
            if (resultObject.has("change")) {
                change = SourceChange.fromJson(resultObject.get("change").getAsJsonObject());
            }
            // potential edits
            List<String> potentialEdits = JsonUtilities.decodeStringList(resultObject.get("potentialEdits") != null ? resultObject.get("potentialEdits").getAsJsonArray() : null);
            //
            // Compute all refactoring-kind specific "Feedback" and put them into the feedback map
            //
            RefactoringFeedback feedback = null;
            if (resultObject.has("feedback")) {
                JsonObject feedbackObject = resultObject.get("feedback").getAsJsonObject();
                String kind = requestToRefactoringKindMap.remove(requestId);
                if (RefactoringKind.EXTRACT_LOCAL_VARIABLE.equals(kind)) {
                    feedback = ExtractLocalVariableFeedback.fromJson(feedbackObject);
                } else if (RefactoringKind.EXTRACT_METHOD.equals(kind)) {
                    feedback = ExtractMethodFeedback.fromJson(feedbackObject);
                } else if (RefactoringKind.INLINE_LOCAL_VARIABLE.equals(kind)) {
                    feedback = InlineLocalVariableFeedback.fromJson(feedbackObject);
                } else if (RefactoringKind.INLINE_METHOD.equals(kind)) {
                    feedback = InlineMethodFeedback.fromJson(feedbackObject);
                } else if (RefactoringKind.RENAME.equals(kind)) {
                    feedback = RenameFeedback.fromJson(feedbackObject);
                }
            }
            consumer.computedRefactorings(initialProblems, optionsProblems, finalProblems, feedback, change, potentialEdits);
        } catch (Exception exception) {
            // catch any exceptions in the formatting of this response
            requestError = generateRequestError(exception);
        }
    }
    if (requestError != null) {
        consumer.onError(requestError);
    }
}
Also used : RefactoringProblem(org.dartlang.analysis.server.protocol.RefactoringProblem) JsonObject(com.google.gson.JsonObject) SourceChange(org.dartlang.analysis.server.protocol.SourceChange) RefactoringFeedback(org.dartlang.analysis.server.protocol.RefactoringFeedback)

Aggregations

JsonObject (com.google.gson.JsonObject)1 RefactoringFeedback (org.dartlang.analysis.server.protocol.RefactoringFeedback)1 RefactoringProblem (org.dartlang.analysis.server.protocol.RefactoringProblem)1 SourceChange (org.dartlang.analysis.server.protocol.SourceChange)1