9package org.dartlang.analysis.server.protocol;
11import java.util.Arrays;
14import com.google.common.collect.Lists;
15import com.google.dart.server.utilities.general.JsonUtilities;
16import com.google.dart.server.utilities.general.ObjectUtilities;
17import com.google.gson.JsonArray;
18import com.google.gson.JsonElement;
19import com.google.gson.JsonObject;
20import com.google.gson.JsonPrimitive;
21import org.apache.commons.lang3.builder.HashCodeBuilder;
22import java.util.ArrayList;
23import java.util.Iterator;
24import org.apache.commons.lang3.StringUtils;
32@SuppressWarnings(
"unused")
42 private final String kind;
47 private final int relevance;
54 private final String completion;
60 private final String displayText;
68 private final Integer replacementOffset;
75 private final Integer replacementLength;
81 private final int selectionOffset;
86 private final int selectionLength;
91 private final boolean isDeprecated;
97 private final boolean isPotential;
103 private final String docSummary;
109 private final String docComplete;
115 private final String declaringType;
120 private final String defaultArgumentListString;
129 private final int[] defaultArgumentListTextRanges;
140 private final String returnType;
158 private final Integer requiredParameterCount;
164 private final Boolean hasNamedParameters;
170 private final String parameterName;
176 private final String parameterType;
191 private final String libraryUri;
198 private final Boolean isNotImported;
203 public CompletionSuggestion(String kind,
int relevance, String completion, String displayText, Integer replacementOffset, Integer replacementLength,
int selectionOffset,
int selectionLength,
boolean isDeprecated,
boolean isPotential, String docSummary, String docComplete, String declaringType, String defaultArgumentListString,
int[] defaultArgumentListTextRanges,
Element element, String returnType,
List<String> parameterNames,
List<String> parameterTypes, Integer requiredParameterCount, Boolean hasNamedParameters, String parameterName, String parameterType, String libraryUri, Boolean isNotImported) {
205 this.relevance = relevance;
206 this.completion = completion;
207 this.displayText = displayText;
208 this.replacementOffset = replacementOffset;
209 this.replacementLength = replacementLength;
210 this.selectionOffset = selectionOffset;
211 this.selectionLength = selectionLength;
212 this.isDeprecated = isDeprecated;
213 this.isPotential = isPotential;
214 this.docSummary = docSummary;
215 this.docComplete = docComplete;
216 this.declaringType = declaringType;
217 this.defaultArgumentListString = defaultArgumentListString;
218 this.defaultArgumentListTextRanges = defaultArgumentListTextRanges;
219 this.element = element;
220 this.returnType = returnType;
221 this.parameterNames = parameterNames;
222 this.parameterTypes = parameterTypes;
223 this.requiredParameterCount = requiredParameterCount;
224 this.hasNamedParameters = hasNamedParameters;
225 this.parameterName = parameterName;
226 this.parameterType = parameterType;
227 this.libraryUri = libraryUri;
228 this.isNotImported = isNotImported;
236 ObjectUtilities.
equals(other.kind, kind) &&
237 other.relevance == relevance &&
238 ObjectUtilities.equals(other.completion, completion) &&
239 ObjectUtilities.equals(other.displayText, displayText) &&
240 ObjectUtilities.equals(other.replacementOffset, replacementOffset) &&
241 ObjectUtilities.equals(other.replacementLength, replacementLength) &&
242 other.selectionOffset == selectionOffset &&
243 other.selectionLength == selectionLength &&
244 other.isDeprecated == isDeprecated &&
245 other.isPotential == isPotential &&
246 ObjectUtilities.equals(other.docSummary, docSummary) &&
247 ObjectUtilities.equals(other.docComplete, docComplete) &&
248 ObjectUtilities.equals(other.declaringType, declaringType) &&
249 ObjectUtilities.equals(other.defaultArgumentListString, defaultArgumentListString) &&
250 Arrays.equals(other.defaultArgumentListTextRanges, defaultArgumentListTextRanges) &&
251 ObjectUtilities.equals(other.element, element) &&
252 ObjectUtilities.equals(other.returnType, returnType) &&
253 ObjectUtilities.equals(other.parameterNames, parameterNames) &&
254 ObjectUtilities.equals(other.parameterTypes, parameterTypes) &&
255 ObjectUtilities.equals(other.requiredParameterCount, requiredParameterCount) &&
256 ObjectUtilities.equals(other.hasNamedParameters, hasNamedParameters) &&
257 ObjectUtilities.equals(other.parameterName, parameterName) &&
258 ObjectUtilities.equals(other.parameterType, parameterType) &&
259 ObjectUtilities.equals(other.libraryUri, libraryUri) &&
260 ObjectUtilities.equals(other.isNotImported, isNotImported);
266 String kind = jsonObject.get(
"kind").getAsString();
267 int relevance = jsonObject.get(
"relevance").getAsInt();
268 String completion = jsonObject.get(
"completion").getAsString();
269 String displayText = jsonObject.get(
"displayText") ==
null ? null : jsonObject.get(
"displayText").getAsString();
270 Integer replacementOffset = jsonObject.get(
"replacementOffset") ==
null ? null : jsonObject.get(
"replacementOffset").getAsInt();
271 Integer replacementLength = jsonObject.get(
"replacementLength") ==
null ? null : jsonObject.get(
"replacementLength").getAsInt();
272 int selectionOffset = jsonObject.get(
"selectionOffset").getAsInt();
273 int selectionLength = jsonObject.get(
"selectionLength").getAsInt();
274 boolean isDeprecated = jsonObject.get(
"isDeprecated").getAsBoolean();
275 boolean isPotential = jsonObject.get(
"isPotential").getAsBoolean();
276 String docSummary = jsonObject.get(
"docSummary") ==
null ? null : jsonObject.get(
"docSummary").getAsString();
277 String docComplete = jsonObject.get(
"docComplete") ==
null ? null : jsonObject.get(
"docComplete").getAsString();
278 String declaringType = jsonObject.get(
"declaringType") ==
null ? null : jsonObject.get(
"declaringType").getAsString();
279 String defaultArgumentListString = jsonObject.get(
"defaultArgumentListString") ==
null ? null : jsonObject.get(
"defaultArgumentListString").getAsString();
280 int[] defaultArgumentListTextRanges = jsonObject.get(
"defaultArgumentListTextRanges") ==
null ? null : JsonUtilities.decodeIntArray(jsonObject.get(
"defaultArgumentListTextRanges").getAsJsonArray());
281 Element element = jsonObject.get(
"element") ==
null ? null :
Element.
fromJson(jsonObject.get(
"element").getAsJsonObject());
282 String returnType = jsonObject.get(
"returnType") ==
null ? null : jsonObject.get(
"returnType").getAsString();
283 List<String> parameterNames = jsonObject.get(
"parameterNames") ==
null ? null : JsonUtilities.decodeStringList(jsonObject.get(
"parameterNames").getAsJsonArray());
284 List<String> parameterTypes = jsonObject.get(
"parameterTypes") ==
null ? null : JsonUtilities.decodeStringList(jsonObject.get(
"parameterTypes").getAsJsonArray());
285 Integer requiredParameterCount = jsonObject.get(
"requiredParameterCount") ==
null ? null : jsonObject.get(
"requiredParameterCount").getAsInt();
286 Boolean hasNamedParameters = jsonObject.get(
"hasNamedParameters") ==
null ? null : jsonObject.get(
"hasNamedParameters").getAsBoolean();
287 String parameterName = jsonObject.get(
"parameterName") ==
null ? null : jsonObject.get(
"parameterName").getAsString();
288 String parameterType = jsonObject.get(
"parameterType") ==
null ? null : jsonObject.get(
"parameterType").getAsString();
289 String libraryUri = jsonObject.get(
"libraryUri") ==
null ? null : jsonObject.get(
"libraryUri").getAsString();
290 Boolean isNotImported = jsonObject.get(
"isNotImported") ==
null ? null : jsonObject.get(
"isNotImported").getAsBoolean();
291 return new CompletionSuggestion(kind, relevance, completion, displayText, replacementOffset, replacementLength, selectionOffset, selectionLength, isDeprecated, isPotential, docSummary, docComplete, declaringType, defaultArgumentListString, defaultArgumentListTextRanges, element, returnType, parameterNames, parameterTypes, requiredParameterCount, hasNamedParameters, parameterName, parameterType, libraryUri, isNotImported);
295 if (jsonArray ==
null) {
298 ArrayList<CompletionSuggestion> list =
new ArrayList<CompletionSuggestion>(jsonArray.size());
299 Iterator<JsonElement> iterator = jsonArray.iterator();
300 while (iterator.hasNext()) {
301 list.add(fromJson(iterator.next().getAsJsonObject()));
320 return declaringType;
327 return defaultArgumentListString;
338 return defaultArgumentListTextRanges;
377 return hasNamedParameters;
393 return isNotImported;
433 return parameterName;
441 return parameterNames;
449 return parameterType;
457 return parameterTypes;
473 return replacementLength;
483 return replacementOffset;
491 return requiredParameterCount;
506 return selectionLength;
514 return selectionOffset;
519 HashCodeBuilder
builder =
new HashCodeBuilder();
524 builder.append(replacementOffset);
525 builder.append(replacementLength);
526 builder.append(selectionOffset);
527 builder.append(selectionLength);
533 builder.append(defaultArgumentListString);
534 builder.append(defaultArgumentListTextRanges);
537 builder.append(parameterNames);
538 builder.append(parameterTypes);
539 builder.append(requiredParameterCount);
540 builder.append(hasNamedParameters);
549 JsonObject jsonObject =
new JsonObject();
550 jsonObject.addProperty(
"kind", kind);
551 jsonObject.addProperty(
"relevance", relevance);
552 jsonObject.addProperty(
"completion", completion);
553 if (displayText !=
null) {
554 jsonObject.addProperty(
"displayText", displayText);
556 if (replacementOffset !=
null) {
557 jsonObject.addProperty(
"replacementOffset", replacementOffset);
559 if (replacementLength !=
null) {
560 jsonObject.addProperty(
"replacementLength", replacementLength);
562 jsonObject.addProperty(
"selectionOffset", selectionOffset);
563 jsonObject.addProperty(
"selectionLength", selectionLength);
564 jsonObject.addProperty(
"isDeprecated", isDeprecated);
565 jsonObject.addProperty(
"isPotential", isPotential);
566 if (docSummary !=
null) {
567 jsonObject.addProperty(
"docSummary", docSummary);
569 if (docComplete !=
null) {
570 jsonObject.addProperty(
"docComplete", docComplete);
572 if (declaringType !=
null) {
573 jsonObject.addProperty(
"declaringType", declaringType);
575 if (defaultArgumentListString !=
null) {
576 jsonObject.addProperty(
"defaultArgumentListString", defaultArgumentListString);
578 if (defaultArgumentListTextRanges !=
null) {
579 JsonArray jsonArrayDefaultArgumentListTextRanges =
new JsonArray();
580 for (
int elt : defaultArgumentListTextRanges) {
581 jsonArrayDefaultArgumentListTextRanges.add(
new JsonPrimitive(elt));
583 jsonObject.add(
"defaultArgumentListTextRanges", jsonArrayDefaultArgumentListTextRanges);
585 if (element !=
null) {
586 jsonObject.add(
"element", element.
toJson());
588 if (returnType !=
null) {
589 jsonObject.addProperty(
"returnType", returnType);
591 if (parameterNames !=
null) {
592 JsonArray jsonArrayParameterNames =
new JsonArray();
593 for (String elt : parameterNames) {
594 jsonArrayParameterNames.add(
new JsonPrimitive(elt));
596 jsonObject.add(
"parameterNames", jsonArrayParameterNames);
598 if (parameterTypes !=
null) {
599 JsonArray jsonArrayParameterTypes =
new JsonArray();
600 for (String elt : parameterTypes) {
601 jsonArrayParameterTypes.add(
new JsonPrimitive(elt));
603 jsonObject.add(
"parameterTypes", jsonArrayParameterTypes);
605 if (requiredParameterCount !=
null) {
606 jsonObject.addProperty(
"requiredParameterCount", requiredParameterCount);
608 if (hasNamedParameters !=
null) {
609 jsonObject.addProperty(
"hasNamedParameters", hasNamedParameters);
611 if (parameterName !=
null) {
612 jsonObject.addProperty(
"parameterName", parameterName);
614 if (parameterType !=
null) {
615 jsonObject.addProperty(
"parameterType", parameterType);
617 if (libraryUri !=
null) {
618 jsonObject.addProperty(
"libraryUri", libraryUri);
620 if (isNotImported !=
null) {
621 jsonObject.addProperty(
"isNotImported", isNotImported);
628 StringBuilder
builder =
new StringBuilder();
633 builder.append(relevance +
", ");
635 builder.append(completion +
", ");
636 builder.append(
"displayText=");
637 builder.append(displayText +
", ");
638 builder.append(
"replacementOffset=");
639 builder.append(replacementOffset +
", ");
640 builder.append(
"replacementLength=");
641 builder.append(replacementLength +
", ");
642 builder.append(
"selectionOffset=");
643 builder.append(selectionOffset +
", ");
644 builder.append(
"selectionLength=");
645 builder.append(selectionLength +
", ");
646 builder.append(
"isDeprecated=");
647 builder.append(isDeprecated +
", ");
648 builder.append(
"isPotential=");
649 builder.append(isPotential +
", ");
651 builder.append(docSummary +
", ");
652 builder.append(
"docComplete=");
653 builder.append(docComplete +
", ");
654 builder.append(
"declaringType=");
655 builder.append(declaringType +
", ");
656 builder.append(
"defaultArgumentListString=");
657 builder.append(defaultArgumentListString +
", ");
658 builder.append(
"defaultArgumentListTextRanges=");
659 builder.append(StringUtils.join(defaultArgumentListTextRanges,
", ") +
", ");
661 builder.append(element +
", ");
663 builder.append(returnType +
", ");
664 builder.append(
"parameterNames=");
665 builder.append(StringUtils.join(parameterNames,
", ") +
", ");
666 builder.append(
"parameterTypes=");
667 builder.append(StringUtils.join(parameterTypes,
", ") +
", ");
668 builder.append(
"requiredParameterCount=");
669 builder.append(requiredParameterCount +
", ");
670 builder.append(
"hasNamedParameters=");
671 builder.append(hasNamedParameters +
", ");
672 builder.append(
"parameterName=");
673 builder.append(parameterName +
", ");
674 builder.append(
"parameterType=");
675 builder.append(parameterType +
", ");
677 builder.append(libraryUri +
", ");
678 builder.append(
"isNotImported=");
Integer getReplacementOffset()
static CompletionSuggestion fromJson(JsonObject jsonObject)
String getParameterType()
CompletionSuggestion(String kind, int relevance, String completion, String displayText, Integer replacementOffset, Integer replacementLength, int selectionOffset, int selectionLength, boolean isDeprecated, boolean isPotential, String docSummary, String docComplete, String declaringType, String defaultArgumentListString, int[] defaultArgumentListTextRanges, Element element, String returnType, List< String > parameterNames, List< String > parameterTypes, Integer requiredParameterCount, Boolean hasNamedParameters, String parameterName, String parameterType, String libraryUri, Boolean isNotImported)
List< String > getParameterTypes()
String getDeclaringType()
boolean equals(Object obj)
Integer getRequiredParameterCount()
int[] getDefaultArgumentListTextRanges()
Boolean getIsNotImported()
String getParameterName()
Integer getReplacementLength()
List< String > getParameterNames()
Boolean getHasNamedParameters()
String getDefaultArgumentListString()
static List< CompletionSuggestion > fromJsonArray(JsonArray jsonArray)
static Element fromJson(JsonObject jsonObject)