use of com.intellij.coldFusion.model.psi.impl.CfmlAttributeImpl in project intellij-plugins by JetBrains.
the class CfmlAttributeNamesCompletionProvider method addCompletions.
public void addCompletions(@NotNull final CompletionParameters parameters, final ProcessingContext context, @NotNull final CompletionResultSet result) {
PsiElement element = parameters.getPosition();
String tagName = "";
while (element != null && !(element instanceof CfmlTag) && !(element instanceof CfmlComponent) && !(element instanceof CfmlPropertyImpl)) {
PsiElement prevNode = element.getPrevSibling();
PsiElement superPrevNode = prevNode != null ? prevNode.getPrevSibling() : null;
if (superPrevNode != null && superPrevNode.getText().equalsIgnoreCase("property")) {
tagName = "cfproperty";
break;
}
element = element.getParent();
}
if (element == null) {
return;
}
if (tagName.isEmpty()) {
tagName = element instanceof CfmlTag ? ((CfmlTag) element).getTagName() : element instanceof CfmlPropertyImpl ? "cfproperty" : "cfcomponent";
}
Set<String> excluded = new HashSet<>();
final CfmlAttributeImpl[] attributes = PsiTreeUtil.getChildrenOfType(element, CfmlAttributeImpl.class);
if (attributes != null) {
for (CfmlAttributeImpl attribute : attributes) {
excluded.add(attribute.getAttributeName());
}
}
for (CfmlAttributeDescription s : CfmlUtil.getAttributes(tagName, element.getProject())) {
if (s.getName() == null) {
continue;
}
if (excluded.contains(s.getName())) {
continue;
}
result.addElement(TailTypeDecorator.withTail(LookupElementBuilder.create(s.getName()).withCaseSensitivity(false), new TailType() {
public int processTail(Editor editor, int tailOffset) {
HighlighterIterator iterator = ((EditorEx) editor).getHighlighter().createIterator(tailOffset);
if (!iterator.atEnd() && iterator.getTokenType() == CfmlTokenTypes.WHITE_SPACE)
iterator.advance();
if (!iterator.atEnd() && iterator.getTokenType() == CfmlTokenTypes.ASSIGN) {
iterator.advance();
} else {
editor.getDocument().insertString(tailOffset, "=\"\"");
return moveCaret(editor, tailOffset, 2);
}
int offset = iterator.getStart();
if (!iterator.atEnd() && iterator.getTokenType() == CfmlTokenTypes.WHITE_SPACE)
iterator.advance();
if (!iterator.atEnd() && CfmlTokenTypes.STRING_ELEMENTS.contains(iterator.getTokenType())) {
return tailOffset;
}
editor.getDocument().insertString(offset, "\"\"");
return moveCaret(editor, tailOffset, offset - tailOffset + 1);
}
}));
}
}
use of com.intellij.coldFusion.model.psi.impl.CfmlAttributeImpl in project intellij-plugins by JetBrains.
the class CfmlAttributeValuesCompletionProvider method addCompletions.
public void addCompletions(@NotNull final CompletionParameters parameters, final ProcessingContext context, @NotNull final CompletionResultSet result) {
PsiElement element = parameters.getPosition();
while (element != null && !(element instanceof CfmlAttributeImpl)) {
element = element.getParent();
}
if (element == null) {
return;
}
CfmlAttributeImpl attribute = (CfmlAttributeImpl) element;
String attributeName = attribute.getFirstChild().getText();
while (element != null && !(element instanceof CfmlTag)) {
element = element.getParent();
}
if (element == null) {
return;
}
CfmlTag tag = (CfmlTag) element;
String tagName = tag.getTagName();
String[] attributeValue = CfmlUtil.getAttributeValues(tagName, attributeName, parameters.getPosition().getProject());
if ("type".equalsIgnoreCase(attributeName) && "cfargument".equalsIgnoreCase(tagName) || "returntype".equalsIgnoreCase(attributeName) && "cffunction".equalsIgnoreCase(tagName)) {
Object[] objects = CfmlComponentReference.buildVariants(attribute.getPureAttributeValue(), element.getContainingFile(), element.getProject(), null, true);
for (Object o : objects) {
result.addElement((LookupElement) o);
}
}
for (String s : attributeValue) {
result.addElement(LookupElementBuilder.create(s).withCaseSensitivity(false));
}
}
Aggregations