use of com.intellij.coldFusion.model.files.CfmlFile 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.files.CfmlFile in project intellij-plugins by JetBrains.
the class CfmlFoldingBuilder method buildFoldRegions.
@NotNull
public FoldingDescriptor[] buildFoldRegions(@NotNull ASTNode node, @NotNull Document document) {
final PsiElement element = node.getPsi();
if (element instanceof CfmlFile) {
final CfmlFile file = (CfmlFile) element;
final PsiElement[] children = file.getChildren();
Collection<FoldingDescriptor> result = new LinkedList<>();
for (PsiElement child : children) {
if (child != null && (child instanceof CfmlCompositeElement || child instanceof PsiComment)) {
List<FoldingDescriptor> descriptors = new ArrayList<>();
addFoldingDescriptors(descriptors, child, document);
result.addAll(descriptors);
}
}
return result.toArray(FoldingDescriptor.EMPTY);
}
return FoldingDescriptor.EMPTY;
}
use of com.intellij.coldFusion.model.files.CfmlFile in project intellij-plugins by JetBrains.
the class CfmlPsiUtil method createConstantString.
@NotNull
public static PsiElement createConstantString(final String text, final Project project) {
final CfmlFile dummyFile = createDummyFile(project, "<cffunction name=\"" + text + "\"></cffunction>");
final PsiElement tag = dummyFile.getFirstChild();
assert tag != null;
final CfmlAttributeNameImpl namedAttribute = PsiTreeUtil.getChildOfType(tag, CfmlAttributeNameImpl.class);
assert namedAttribute != null;
final PsiElement element = namedAttribute.getValueElement();
assert element != null;
return element;
}
use of com.intellij.coldFusion.model.files.CfmlFile in project intellij-plugins by JetBrains.
the class CfmlComponentReference method addFakeMappingsForImports.
private static void addFakeMappingsForImports(CfmlComponentReference ref, CfmlMappingsConfig mappings) {
if (PsiTreeUtil.getParentOfType(ref, CfmlImport.class) != null) {
// create fake mappings for imports
CfmlFile file = ref.getContainingFile();
Collection<String> importStrings = file.getImportStrings();
for (String importString : importStrings) {
final int index = importString.lastIndexOf('.');
if (index == -1) {
continue;
}
final String leftMapping = file.getComponentQualifiedName(importString).substring(0, index);
if (!StringUtil.isEmpty(leftMapping)) {
mappings.putToServerMappings("", leftMapping);
}
}
}
}
Aggregations