for (int i = 0; i < tagList.size(); i++) {
TagInfo tagInfo = tagList.get(i);
if (tagInfo instanceof TextInfo) {
TextInfo textInfo = (TextInfo) tagInfo;
if ((textInfo.getText().toLowerCase()).indexOf(word) == 0) {
list.add(new CompletionProposal(textInfo.getText(), documentOffset - word.length(), word.length(), textInfo.getPosition(), _tagImage, textInfo.getDisplayString(), null, tagInfo.getDescription()));
}
continue;
}
String tagName = tagInfo.getTagName();
String tagNameMatch = "<" + tagName.toLowerCase();
if (tagNameMatch.startsWith(word) && !(tagNameMatch.equals(word) && next.startsWith(">"))) {
String assistKeyword = tagName;
int position = 0;
// required attributes
AttributeInfo[] requireAttrs;
if (inTag) {
requireAttrs = new AttributeInfo[0];
position = tagName.length() + 1;
}
else {
requireAttrs = tagInfo.getRequiredAttributeInfo();
for (int j = 0; j < requireAttrs.length; j++) {
assistKeyword = assistKeyword + " " + requireAttrs[j].getAttributeName();
if (requireAttrs[j].hasValue()) {
assistKeyword = assistKeyword + equals + "\"\"";
if (j == 0) {
position = tagName.length() + requireAttrs[j].getAttributeName().length() + (spacesAroundEquals ? 5 : 3);
}
}
}
}
boolean forceAttributePosition = (requireAttrs.length == 0 && tagInfo.requiresAttributes());
if (!inTag) {
if (tagInfo.hasBody()) {
assistKeyword = assistKeyword + ">";
if (_assistCloseTag) {
if (position == 0) {
position = assistKeyword.length();
}
assistKeyword = assistKeyword + "</" + tagName + ">";
}
}
else {
if (tagInfo.isEmptyTag() && _xhtmlMode == false) {
assistKeyword = assistKeyword + ">";
}
else {
assistKeyword = assistKeyword + "/>";
}
}
}
if (position == 0) {
position = assistKeyword.length();
}
if (forceAttributePosition && position > 0) {
if (tagInfo.hasBody()) {
position--;
}
else if (tagInfo.isEmptyTag()) {
if (_xhtmlMode) {
position -= 2;
}
else {
position--;
}
}
}
try {
if (tagInfo instanceof InlineWodTagInfo && BindingReflectionUtils.memberIsDeprecated(((InlineWodTagInfo)tagInfo).getElementType())) {
list.add(new HTMLDeprecatedCompletionProposal(assistKeyword, documentOffset - word.length() + 1, word.length() - 1, position, _tagImage, tagName, null, tagInfo.getDescription()));
} else {
list.add(new CompletionProposal(assistKeyword, documentOffset - word.length() + 1, word.length() - 1, position, _tagImage, tagName, null, tagInfo.getDescription()));
}
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}
// custom elements
for (int i = 0; i < _customElems.size(); i++) {
CustomElement element = _customElems.get(i);
if ((element.getAssistString().toLowerCase()).indexOf(word) == 0) {
int position = element.getAssistString().indexOf('"');
if (position == -1) {
position = element.getAssistString().indexOf("><");
}
if (position == -1) {
position = element.getAssistString().length();
}
list.add(new CompletionProposal(element.getAssistString(), documentOffset - word.length(), word.length(), position + 1, _tagImage, element.getDisplayName(), null, null));
}
}
// attribute
}
else if (!prev.equals("")) {
String tagName = prev;
TagInfo tagInfo = getTagInfo(tagName);
if (tagInfo != null) {
AttributeInfo[] attrList = tagInfo.getAttributeInfo();
for (int j = 0; j < attrList.length; j++) {
if (attrList[j].getAttributeName().toLowerCase().indexOf(word) == 0) {
String assistKeyword = null;
int position = 0;
if (attrList[j].hasValue()) {
assistKeyword = attrList[j].getAttributeName() + equals + "\"\"";
position = equals.length() + 1;
}
else {
assistKeyword = attrList[j].getAttributeName();
position = 0;
}
list.add(new CompletionProposal(assistKeyword, documentOffset - word.length(), word.length(), attrList[j].getAttributeName().length() + position, _attrImage, attrList[j].getAttributeName(), null, attrList[j].getDescription()));
}
}
}
// custom attributes
for (int i = 0; i < _customAttrs.size(); i++) {
CustomAttribute attrInfo = _customAttrs.get(i);
if (attrInfo.getTargetTag().equals("*") || attrInfo.getTargetTag().equals(tagName)) {
if (tagName.indexOf(":") < 0 || _customElemNames.contains(tagName)) {
list.add(new CompletionProposal(attrInfo.getAttributeName() + equals + "\"\"", documentOffset - word.length(), word.length(), attrInfo.getAttributeName().length() + 2, _attrImage, attrInfo.getAttributeName(), null, null));
}
}
}
// close tag
}
else if (!last.equals("")) {
TagInfo info = getTagInfo(last);
if (info == null || _xhtmlMode == true || info.hasBody() || !info.isEmptyTag()) {
String assistKeyword = "</" + last + ">";
int length = 0;
if (assistKeyword.toLowerCase().startsWith(word)) {
length = word.length();
}
list.add(new CompletionProposal(assistKeyword, documentOffset - length, length, assistKeyword.length(), _tagImage, assistKeyword, null, null));
}
}
HTMLUtil.sortCompilationProposal(list);