Skip to content

Commit

Permalink
IDEA-83090 Combination of script and tag functions in a CFC only has …
Browse files Browse the repository at this point in the history
…tag functions in outline
  • Loading branch information
Maxim.Mossienko authored and Maxim.Mossienko committed Jul 27, 2015
1 parent 7f20bd1 commit f062199
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 31 deletions.
Expand Up @@ -16,7 +16,6 @@
package com.intellij.coldFusion.UI.editorActions.structureView;

import com.intellij.coldFusion.model.files.CfmlFile;
import com.intellij.coldFusion.model.info.CfmlFunctionDescription;
import com.intellij.coldFusion.model.psi.CfmlComponent;
import com.intellij.coldFusion.model.psi.CfmlFunction;
import com.intellij.coldFusion.model.psi.CfmlTag;
Expand All @@ -43,18 +42,22 @@ protected CfmlStructureViewElement(final PsiElement psiElement) {
super(psiElement);
}

private void collectResults(Collection<StructureViewTreeElement> result, PsiElement element) {
private static void collectResults(Collection<StructureViewTreeElement> result, PsiElement element) {
if (element instanceof CfmlComponent) {
result.addAll(makeCollection(((CfmlComponent)element).getFunctions()));
}
else if (element instanceof CfmlFunction) {
result.add(new CfmlStructureViewElement(element));
}
else if (element instanceof CfmlTag) {
final PsiElement[] children = element.getChildren();
for (PsiElement child : children) {
collectResults(result, child);
}
collectResultsFromChildren(result, element);
}
}

private static void collectResultsFromChildren(Collection<StructureViewTreeElement> result, PsiElement element) {
final PsiElement[] children = element.getChildren();
for (PsiElement child : children) {
collectResults(result, child);
}
}

Expand All @@ -64,10 +67,7 @@ public Collection<StructureViewTreeElement> getChildrenBase() {
Collection<StructureViewTreeElement> result = new LinkedList<StructureViewTreeElement>();

if (element != null && (element instanceof CfmlFile || !(element instanceof CfmlFunction))) {
final PsiElement[] children = element.getChildren();
for (PsiElement child : children) {
collectResults(result, child);
}
collectResultsFromChildren(result, element);
}

return result;
Expand All @@ -90,11 +90,7 @@ else if (element instanceof CfmlFile) {
return "";
}

public static String getParameterPresentation(CfmlFunctionDescription.CfmlParameterDescription param) {
return param.getPresetableText();
}

private Collection<StructureViewTreeElement> makeCollection(@Nullable PsiElement[] tags) {
private static Collection<StructureViewTreeElement> makeCollection(@Nullable PsiElement[] tags) {
if (tags == null) {
return Collections.emptyList();
}
Expand Down
Expand Up @@ -17,29 +17,27 @@

import com.intellij.coldFusion.model.CfmlUtil;
import com.intellij.coldFusion.model.lexer.CfmlTokenTypes;
import com.intellij.coldFusion.model.parsers.CfmlElementTypes;
import com.intellij.coldFusion.model.psi.*;
import com.intellij.coldFusion.model.psi.stubs.CfmlStubElementTypes;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.scope.PsiScopeProcessor;
import com.intellij.psi.stubs.NamedStub;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.ArrayUtil;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class CfmlTagComponentImpl extends CfmlTagImpl implements CfmlComponent, StubBasedPsiElement<NamedStub> {

private final static String TAG_NAME = "cfcomponent";

public CfmlTagComponentImpl(ASTNode astNode) {
public CfmlTagComponentImpl(ASTNode astNode) {
super(astNode);
}

public CfmlTagComponentImpl(@NotNull NamedStub<CfmlComponent> stub) {
super(stub, CfmlElementTypes.COMPONENT_TAG);
super(stub, CfmlStubElementTypes.COMPONENT_TAG);
}

@Override
Expand All @@ -56,7 +54,15 @@ public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperatio
@NotNull
@Override
public CfmlFunction[] getFunctions() {
return findChildrenByClass(CfmlFunction.class);
CfmlFunction[] functions = findChildrenByClass(CfmlFunction.class);
final CfmlTagScriptImpl[] tagScripts = PsiTreeUtil.getChildrenOfType(this, CfmlTagScriptImpl.class);
if (tagScripts != null) {
for(CfmlTagScriptImpl tagScript:tagScripts) {
final CfmlFunction[] functionsFromScript = PsiTreeUtil.getChildrenOfType(tagScript, CfmlFunction.class);
if (functionsFromScript != null) functions = ArrayUtil.mergeArrays(functions, functionsFromScript);
}
}
return functions;
}

@NotNull
Expand Down Expand Up @@ -153,11 +159,6 @@ public PsiElement getNameIdentifier() {
return getNavigationElement();
}

@Nullable
private CfmlComponentReference getReferenceToSuperComponent() {
return null;
}

@NotNull
@Override
public PsiReference[] getReferences() {
Expand Down
12 changes: 8 additions & 4 deletions CFML/tests/com/intellij/coldFusion/CfmlStructureViewTest.java
Expand Up @@ -15,7 +15,6 @@
*/
package com.intellij.coldFusion;

import com.intellij.codeInsight.CodeInsightTestCase;
import com.intellij.coldFusion.model.files.CfmlFileType;
import com.intellij.coldFusion.model.files.CfmlFileViewProvider;
import com.intellij.ide.structureView.StructureView;
Expand All @@ -28,19 +27,24 @@
import com.intellij.ide.util.treeView.smartTree.TreeElement;
import com.intellij.ide.util.treeView.smartTree.TreeStructureUtil;
import com.intellij.lang.LanguageStructureViewBuilder;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.vfs.VirtualFile;
import junit.framework.Assert;

import java.io.File;

/**
* @author vnikolaenko
*/
public class CfmlStructureViewTest extends CfmlCodeInsightFixtureTestCase {
public void testScriptAndTagFunctions() throws Exception {
myFixture.configureByFile(getTestName(true) + ".test.cfc");
final Object[] topLevelObjects = getTopLevelItems();
assertEquals(topLevelObjects.length, 2);
assertEquals("someFunction1(arg1, [arg2])", getText(topLevelObjects[0]));
assertEquals("someFunction2()", getText(topLevelObjects[1]));
}

public void testScriptFunctions() throws Exception {
myFixture.configureByFile(getTestName(true) + ".test.cfml");
final Object[] topLevelObjects = getTopLevelItems();
Expand Down
6 changes: 6 additions & 0 deletions CFML/tests/testData/highlighter/assertion.test.cfml
Expand Up @@ -2,6 +2,12 @@
<cfscript>
variables.eventDateTimeCEName = <weak_warning descr="Can't resolve">getEventDateTimeCEName</weak_warning>();
variables.eventDateTimeViewName = <weak_warning descr="Can't resolve">getCEViewName</weak_warning>(variables.eventDateTimeCEName);
function foo() {}
</cfscript>
<cfset ApplicationMetadata2 = <weak_warning descr="Can't resolve">GetApplicationMetadata2</weak_warning>() >
<cffunction name="bar">
<cfscript>
foo();
</cfscript>
</cffunction>
</cfcomponent>
10 changes: 10 additions & 0 deletions CFML/tests/testData/structureView/scriptAndTagFunctions.test.cfc
@@ -0,0 +1,10 @@
<cfcomponent>
<cfscript>
function someFunction2() {
}
</cfscript>
<cffunction name="someFunction1">
<cfargument name="arg1" required="true">
<cfargument name="arg2">
</cffunction>
</cfcomponent>

0 comments on commit f062199

Please sign in to comment.