String alreadyTyped = getTagName();
if (alreadyTyped != null) {
if (!alreadyTyped.startsWith("[")) {
Iterator<TMLTag> it = TMLTagDefinitions.getInstance(WGADesignStructureHelper.getWGAVersionCompliance(activeFile)).getTagsByPrefix(alreadyTyped).iterator();
while (it.hasNext()) {
TMLTag tag = it.next();
proposals.addAll(createTagProposals(alreadyTyped, tag, _document, _cursorAbsolute,activeFile));
}
} else {
Version wgaVersion = (Version) WGADesignConfigurationModel.VERSIONCOMPLIANCE_TO_WGA_VERSION.get(WGADesignStructureHelper.getWGAVersionCompliance(activeFile).getKey());
if (wgaVersion.isAtLeast(4, 1)) {
proposals.addAll(createIncludeModuleProposals(alreadyTyped, _document, _cursorAbsolute, activeFile));
}
}
}
} else if (!isCursorInAttributeValue()) {
// create attribute name proposals
String search = _content.substring(0, _cursorRelative);
int attributePrefixStartPos = searchBackwards(" ", search, "<");
if (attributePrefixStartPos != -1) {
attributePrefixStartPos += 1;
String typed = search.substring(attributePrefixStartPos, _cursorRelative);
TMLTag tag = TMLTagDefinitions.getInstance(WGADesignStructureHelper.getWGAVersionCompliance(activeFile)).getTagByName(getTagName());
if (tag != null) {
Iterator<TMLTagAttribute> it = tag.getAttributesByPrefix(typed).iterator();
while (it.hasNext()) {
TMLTagAttribute attrib = it.next();
if (!_attributes.containsKey(attrib.getName()) && !attrib.isDeprecated()) {
String attName = attrib.getName();
String display = attName;
StringBuffer replacement = new StringBuffer();
replacement.append(attName);
replacement.append("=\"\"");
int cursorPosAfterReplace = replacement.toString().length() - 1;
ContextInformation contextInfo = Plugin.getDefault().getContextInformationProvider().getAttributeInformation(tag.getName(), attrib.getName(), activeFile);
proposals.add(new TMLCompletionProposal(replacement.toString(), _cursorAbsolute - typed.length(), typed.length(), cursorPosAfterReplace, null, display, contextInfo));
}
}
}
}
} else if (getAttributeNameOfValueCursorPosition() != null) {
// create attribute value proposals
String attribute = getAttributeNameOfValueCursorPosition();
String search = _content.substring(0, _cursorRelative);
int attributeValueStartPos = searchBackwards("\"", search, "=");
String typed = "";
if (attributeValueStartPos != -1) {
typed = _content.substring(attributeValueStartPos + 1, _cursorRelative);
} else {
typed = "";
}
TMLTag tag = TMLTagDefinitions.getInstance(WGADesignStructureHelper.getWGAVersionCompliance(activeFile)).getTagByName(getTagName());
if (tag != null) {
TMLTagAttribute tagAttribute = tag.getAttribute(attribute);
if (tagAttribute != null) {
if (tagAttribute.isTmlscriptExpression()) {
// perform tmlscript code completion
try {
IRegion region = getAttributeValueRegion(attribute);
TMLScriptRegion tmlScriptRegion = TMLScriptRegion.parse(region, _document, _cursorAbsolute, WGADesignStructureHelper.getWGAVersionCompliance(activeFile));
proposals.addAll(tmlScriptRegion.createProposals());
}
catch (BadLocationException e) {
}
} else {
// lookup attribute values
Iterator<String> values = tag.getAttributeValuesByPrefix(attribute, typed, _document, this, viewer, activeFile).iterator();
while (values.hasNext()) {
String value = values.next();
String display = value;
StringBuffer replacement = new StringBuffer();
replacement.append(value);
int cursorPosAfterReplace = replacement.toString().length() + 1;
ContextInformation info = Plugin.getDefault().getContextInformationProvider().getAttributeInformation(tag.getName(), attribute, value,activeFile);
proposals.add(new TMLCompletionProposal(replacement.toString(), _cursorAbsolute - typed.length(), typed.length(), cursorPosAfterReplace, null, display, info));
}
}
}
}