Skip to content

Commit

Permalink
Fix providing code actions with undefined type
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenLooman committed Sep 11, 2023
1 parent 5a29298 commit ccbe2fc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,28 @@ public String getFullString() {
return this.currentPackage + ":" + this.string;
}

/**
* Test if this type is undefined.
* @return {@code true} if this type is undefined.
*/
public boolean isUndefined() {
return !this.isCombined()
&& this.getString().equalsIgnoreCase(UndefinedType.SERIALIZED_NAME);
}

/**
* Test if this type contains an undefined type.
* @return {@code true} if this type contains an undefined type.
*/
public boolean containsUndefined() {
if (this.isCombined()) {
return this.combinedTypes.stream()
.anyMatch(TypeString::containsUndefined);
}

return this.isUndefined();
}

public boolean isSelf() {
return !this.isCombined()
&& this.getString().equalsIgnoreCase(SelfType.SERIALIZED_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,26 @@ private List<CodeAction> extractReturnTypeCodeActions(
return StreamUtils.zip(methodResultString.stream(), typeDocNodes.entrySet().stream())
.map(entry -> {
final TypeString methodTypeString = entry.getKey();
if (methodTypeString == TypeString.UNDEFINED) {
if (methodTypeString != null && methodTypeString.containsUndefined()) {
// Don't propose code actions for undefined types.
return null;
}

final Map.Entry<AstNode, TypeString> typeDocEntry = entry.getValue();
if (methodTypeString != null && typeDocEntry == null) {
// Code action: Add type-doc line.
return this.createAddReturnCodeAction(methodDefinition, methodTypeString);
}

final TypeString typeDocTypeString = typeDocEntry.getValue();
final AstNode typeDocNode = typeDocEntry.getKey();
final AstNode typeValueNode = typeDocNode.getFirstChild(TypeDocGrammar.TYPE_VALUE);
if (methodTypeString == null && typeDocEntry != null) {
// Code action: Remove type-doc line.
return this.createRemoveReturnCodeAction(typeValueNode);
} else if (methodTypeString != null // && typeDocTypeString != null
&& methodTypeString != TypeString.UNDEFINED
}

final TypeString typeDocTypeString = typeDocEntry.getValue();
if (methodTypeString != null // && typeDocTypeString != null
&& !methodTypeString.containsUndefined()
&& !methodTypeString.equals(typeDocTypeString)) {
// Code action: Update type-doc line.
return this.createUpdateReturnCodeAction(methodTypeString, typeValueNode);
}

Expand Down

0 comments on commit ccbe2fc

Please sign in to comment.