use of com.intellij.coldFusion.model.psi.CfmlTag in project intellij-plugins by JetBrains.
the class CfmlFoldingBuilder method addFoldingDescriptors.
private static void addFoldingDescriptors(final List<FoldingDescriptor> descriptors, final PsiElement tag, @NotNull Document document) {
TextRange elementRange = tag.getTextRange();
final int start = elementRange.getStartOffset();
final int end = elementRange.getEndOffset();
if (start + 1 < end) {
TextRange range = null;
ASTNode astNode = tag.getNode();
IElementType astType = astNode.getElementType();
if (tag instanceof CfmlTag) {
//if (tag instanceof CfmlTagFunctionImpl || tag instanceof CfmlTagComponentImpl || tag instanceof CfmlTagScriptImpl) {
range = buildRangeForBraces(range, astNode, CfmlTokenTypes.R_ANGLEBRACKET, CfmlTokenTypes.LSLASH_ANGLEBRACKET);
//}
} else if (astType == CfmlElementTypes.FUNCTIONBODY || astType == CfmlElementTypes.BLOCK_OF_STATEMENTS) {
range = buildRange(range, start, end);
} else if (astType == CfmlElementTypes.SWITCHEXPRESSION) {
ASTNode lparen = astNode.findChildByType(CfscriptTokenTypes.L_CURLYBRACKET);
ASTNode rparen = astNode.findChildByType(CfscriptTokenTypes.R_CURLYBRACKET);
if (lparen != null && rparen != null) {
range = buildRange(range, lparen.getStartOffset(), rparen.getTextRange().getEndOffset());
}
} else if (tag instanceof PsiComment) {
boolean isColdFusionComment = astNode.getElementType() == CfmlTokenTypes.COMMENT;
int endIndex = astNode.getText().lastIndexOf(isColdFusionComment ? "--->" : "*/");
if (endIndex != -1) {
String commentText = astNode.getText().substring(0, endIndex);
if (commentText.contains("\n")) {
int startOffset = tag.getTextRange().getStartOffset();
range = buildRange(range, startOffset + (isColdFusionComment ? "<!---" : "/*").length(), startOffset + commentText.length());
}
}
}
if (range != null) {
descriptors.add(new FoldingDescriptor(astNode, range));
}
// TODO: insert condition
addFoldingDescriptorsFromChildren(descriptors, tag, document);
}
}
use of com.intellij.coldFusion.model.psi.CfmlTag in project intellij-plugins by JetBrains.
the class CfmlFileReferenceInspection method buildVisitor.
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
return new PsiElementVisitor() {
public void visitElement(final PsiElement element) {
PsiElement tagParent = PsiTreeUtil.getParentOfType((element), CfmlTag.class);
if ((element.getNode().getElementType() == CfmlTokenTypes.STRING_TEXT)) {
if ((tagParent == null || (!((CfmlTag) tagParent).getTagName().equalsIgnoreCase("cfinclude") && !((CfmlTag) tagParent).getTagName().equalsIgnoreCase("cfmodule")))) {
PsiElement superParent = element.getParent() != null ? element.getParent().getParent() : null;
ASTNode superParentNode = superParent != null ? superParent.getNode() : null;
if ((superParentNode == null || superParentNode.getElementType() != CfmlElementTypes.INCLUDEEXPRESSION)) {
return;
}
}
final PsiReference[] refs = element.getParent().getReferences();
for (int i = 0, refsLength = refs.length; i < refsLength; i++) {
PsiReference ref = refs[i];
if (!(ref instanceof FileReference))
continue;
if (ref.resolve() == null) {
PsiDirectory dir;
if (i > 0) {
final PsiElement target = refs[i - 1].resolve();
dir = target instanceof PsiDirectory ? (PsiDirectory) target : null;
} else {
dir = element.getContainingFile().getParent();
}
holder.registerProblem(ref.getElement(), ref.getRangeInElement(), isOnTheFly ? "Path '" + ref.getCanonicalText() + "' not found" : "Path not found", isOnTheFly && dir != null ? new LocalQuickFix[] { new CreateFileFix(i < refs.length - 1, ref.getCanonicalText(), dir) } : LocalQuickFix.EMPTY_ARRAY);
// ProblemHighlightType.ERROR);
break;
}
}
}
}
};
}
use of com.intellij.coldFusion.model.psi.CfmlTag 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.CfmlTag in project intellij-plugins by JetBrains.
the class CfmlUnitQualifiedNameLocationProvider method findElement.
@Nullable
private static PsiElement findElement(String link, Project project) {
String[] location = link.split("::");
int tokensNumber = location.length;
if (tokensNumber <= 0 || tokensNumber > 3) {
return null;
}
PsiElement result;
String filePath = location[0];
VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByPath(filePath);
if (virtualFile != null) {
result = PsiManager.getInstance(project).findFile(virtualFile);
if (result == null || !(result instanceof CfmlFile)) {
return null;
}
// TODO: to move to index
final CfmlTag[] tags = PsiTreeUtil.getChildrenOfType(result, CfmlTag.class);
if (tags == null || tags.length == 0) {
return result;
}
for (CfmlTag tag : tags) {
if ("cfcomponent".equals(tag.getTagName().toLowerCase(Locale.ENGLISH))) {
result = tag;
break;
}
}
} else {
return null;
}
if (tokensNumber > 1) {
String functionName = location[1];
final CfmlTagFunctionImpl[] functions = PsiTreeUtil.getChildrenOfType(result, CfmlTagFunctionImpl.class);
if (functions != null) {
for (CfmlTagFunctionImpl function : functions) {
if (functionName.equals(function.getName())) {
result = function.getNavigationElement();
break;
}
}
}
final CfmlFunctionImpl[] scriptFunctions = PsiTreeUtil.getChildrenOfType(result, CfmlFunctionImpl.class);
if (scriptFunctions != null) {
for (CfmlFunctionImpl function : scriptFunctions) {
if (functionName.equals(function.getName())) {
result = function.getNavigationElement();
break;
}
}
}
}
return result;
}
use of com.intellij.coldFusion.model.psi.CfmlTag 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