forked from redhat-developer/quarkus-ls
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes redhat-developer#784 Signed-off-by: azerr <azerr@redhat.com>
- Loading branch information
1 parent
5a1b1cf
commit 6e1ced7
Showing
11 changed files
with
322 additions
and
356 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
qute.ls/com.redhat.qute.ls/src/main/java/com/redhat/qute/project/tags/UserTagParameter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.redhat.qute.project.tags; | ||
|
||
import com.redhat.qute.parser.expression.ObjectPart; | ||
|
||
public class UserTagParameter { | ||
|
||
private final ObjectPart part; | ||
|
||
private boolean required; | ||
|
||
public UserTagParameter(ObjectPart part) { | ||
this.part = part; | ||
} | ||
|
||
public ObjectPart getPart() { | ||
return part; | ||
} | ||
|
||
public void setRequired(Boolean required) { | ||
this.required = required; | ||
} | ||
|
||
public Boolean isRequired() { | ||
return required; | ||
} | ||
|
||
public String getPartName() { | ||
return part.getPartName(); | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
....redhat.qute.ls/src/main/java/com/redhat/qute/project/tags/UserTagParameterCollector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package com.redhat.qute.project.tags; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import com.redhat.qute.parser.expression.MethodPart; | ||
import com.redhat.qute.parser.expression.ObjectPart; | ||
import com.redhat.qute.parser.expression.Part; | ||
import com.redhat.qute.parser.expression.Parts; | ||
import com.redhat.qute.parser.expression.Parts.PartKind; | ||
import com.redhat.qute.parser.template.ASTVisitor; | ||
import com.redhat.qute.parser.template.Parameter; | ||
import com.redhat.qute.parser.template.Section; | ||
import com.redhat.qute.parser.template.sections.IfSection; | ||
import com.redhat.qute.parser.template.sections.LetSection; | ||
import com.redhat.qute.utils.StringUtils; | ||
|
||
public class UserTagParameterCollector extends ASTVisitor { | ||
|
||
private final Map<String, UserTagParameter> parameters; | ||
|
||
private final List<List<String>> stack; | ||
|
||
public UserTagParameterCollector() { | ||
parameters = new LinkedHashMap<>(); | ||
stack = new ArrayList<>(); | ||
} | ||
|
||
@Override | ||
public boolean visit(IfSection node) { | ||
addStack(node); | ||
return super.visit(node); | ||
} | ||
|
||
public boolean visit(LetSection node) { | ||
// addStack(node); | ||
return super.visit(node); | ||
} | ||
|
||
private void addStack(Section node) { | ||
List<String> optionalParameterNames = null; | ||
List<Parameter> parameters = node.getParameters(); | ||
for (Parameter parameter : parameters) { | ||
String name = parameter.getName(); | ||
if (!StringUtils.isEmpty(name) && (parameter.isOptional())) { | ||
if (optionalParameterNames == null) { | ||
optionalParameterNames = new ArrayList<>(); | ||
} | ||
optionalParameterNames.add(name); | ||
} | ||
} | ||
stack.add(optionalParameterNames != null ? optionalParameterNames : Collections.emptyList()); | ||
} | ||
|
||
@Override | ||
public void endVisit(IfSection node) { | ||
removeStack(); | ||
super.endVisit(node); | ||
} | ||
|
||
@Override | ||
public void endVisit(LetSection node) { | ||
// removeStack(); | ||
super.endVisit(node); | ||
} | ||
|
||
private void removeStack() { | ||
stack.remove(stack.size() - 1); | ||
} | ||
|
||
@Override | ||
public boolean visit(ObjectPart node) { | ||
if (node.getNamespace() == null) { | ||
String partName = node.getPartName(); | ||
UserTagParameter parameter = parameters.get(partName); | ||
if (parameter == null) { | ||
parameter = new UserTagParameter(node); | ||
parameters.put(partName, parameter); | ||
} | ||
if (!parameter.isRequired()) { | ||
boolean ignore = false; | ||
for (List<String> optionalNames : stack) { | ||
if (optionalNames.contains(partName)) { | ||
ignore = true; | ||
} | ||
} | ||
if (!ignore) { | ||
boolean required = false; | ||
Parts parts = node.getParent(); | ||
int index = parts.getPartIndex(node); | ||
if (index + 1 < parts.getChildCount()) { | ||
Part next = parts.getChild(index + 1); | ||
if (next != null && next.getPartKind() == PartKind.Method) { | ||
MethodPart methodPart = (MethodPart) next; | ||
if (!("?:".equals(methodPart.getPartName()) || "or".equals(methodPart.getPartName()))) { | ||
required = true; | ||
} | ||
} | ||
} else { | ||
required = true; | ||
} | ||
parameter.setRequired(required); | ||
} | ||
} | ||
} | ||
return super.visit(node); | ||
} | ||
|
||
public Map<String, UserTagParameter> getParameters() { | ||
return parameters; | ||
} | ||
} |
Oops, something went wrong.