mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:10:43 +07:00
IDEA-110995 Custom variables dialog does not appear for included templates.
This commit is contained in:
@@ -88,8 +88,17 @@ public class FileTemplatesTest extends IdeaTestCase {
|
||||
}
|
||||
|
||||
public void "test collect undefined attribute names"() {
|
||||
String name = "myclass";
|
||||
FileTemplate template = addTestTemplate(name, '${ABC} ${DEF} ${NAME}')
|
||||
FileTemplate template = addTestTemplate("myclass", '${ABC} ${DEF} ${NAME}')
|
||||
Properties properties = new Properties()
|
||||
properties.NAME = 'zzz'
|
||||
assert template.getUnsetAttributes(properties) as Set == ['ABC', 'DEF'] as Set
|
||||
}
|
||||
|
||||
public void "test collect undefined attribute names from included templates"() {
|
||||
def included = addTestTemplate("included", '${ABC} ${DEF}')
|
||||
assert included == FileTemplateManager.instance.getTemplate("included.java")
|
||||
|
||||
FileTemplate template = addTestTemplate("myclass", '#parse("included.java") ${DEF} ${NAME}')
|
||||
Properties properties = new Properties()
|
||||
properties.NAME = 'zzz'
|
||||
assert template.getUnsetAttributes(properties) as Set == ['ABC', 'DEF'] as Set
|
||||
@@ -116,7 +125,7 @@ public class FileTemplatesTest extends IdeaTestCase {
|
||||
}
|
||||
|
||||
private FileTemplate addTestTemplate(String name, String text) {
|
||||
FileTemplate template = FileTemplateManager.getInstance().addInternal(name, "java");
|
||||
FileTemplate template = FileTemplateManager.getInstance().addTemplate(name, "java");
|
||||
disposeOnTearDown({ FileTemplateManager.getInstance().removeTemplate(template) } as Disposable)
|
||||
template.setText(text);
|
||||
template
|
||||
|
||||
@@ -46,10 +46,8 @@ import org.apache.velocity.runtime.RuntimeServices;
|
||||
import org.apache.velocity.runtime.RuntimeSingleton;
|
||||
import org.apache.velocity.runtime.log.LogSystem;
|
||||
import org.apache.velocity.runtime.parser.ParseException;
|
||||
import org.apache.velocity.runtime.parser.node.ASTReference;
|
||||
import org.apache.velocity.runtime.parser.node.ASTSetDirective;
|
||||
import org.apache.velocity.runtime.parser.node.Node;
|
||||
import org.apache.velocity.runtime.parser.node.SimpleNode;
|
||||
import org.apache.velocity.runtime.parser.Token;
|
||||
import org.apache.velocity.runtime.parser.node.*;
|
||||
import org.apache.velocity.runtime.resource.Resource;
|
||||
import org.apache.velocity.runtime.resource.loader.ResourceLoader;
|
||||
import org.apache.velocity.util.StringUtils;
|
||||
@@ -143,18 +141,19 @@ public class FileTemplateUtil{
|
||||
final Set<String> definedAttributes = new HashSet<String>();
|
||||
//noinspection HardCodedStringLiteral
|
||||
SimpleNode template = RuntimeSingleton.parse(new StringReader(templateContent), "MyTemplate");
|
||||
collectAttributes(unsetAttributes, definedAttributes, template, propertiesNames, includeDummies);
|
||||
collectAttributes(unsetAttributes, definedAttributes, template, propertiesNames, includeDummies, new HashSet<String>());
|
||||
for (String definedAttribute : definedAttributes) {
|
||||
unsetAttributes.remove(definedAttribute);
|
||||
}
|
||||
return ArrayUtil.toStringArray(unsetAttributes);
|
||||
}
|
||||
|
||||
private static void collectAttributes(Set<String> referenced, Set<String> defined, Node apacheNode, Set<String> propertiesNames, boolean includeDummies){
|
||||
private static void collectAttributes(Set<String> referenced, Set<String> defined, Node apacheNode, final Set<String> propertiesNames, final boolean includeDummies, Set<String> visitedIncludes)
|
||||
throws ParseException {
|
||||
int childCount = apacheNode.jjtGetNumChildren();
|
||||
for(int i = 0; i < childCount; i++){
|
||||
Node apacheChild = apacheNode.jjtGetChild(i);
|
||||
collectAttributes(referenced, defined, apacheChild, propertiesNames, includeDummies);
|
||||
collectAttributes(referenced, defined, apacheChild, propertiesNames, includeDummies, visitedIncludes);
|
||||
if (apacheChild instanceof ASTReference){
|
||||
ASTReference apacheReference = (ASTReference)apacheChild;
|
||||
String s = apacheReference.literal();
|
||||
@@ -170,6 +169,20 @@ public class FileTemplateUtil{
|
||||
defined.add(attr);
|
||||
}
|
||||
}
|
||||
else if (apacheChild instanceof ASTDirective && "parse".equals(((ASTDirective)apacheChild).getDirectiveName()) && apacheChild.jjtGetNumChildren() == 1) {
|
||||
Node literal = apacheChild.jjtGetChild(0);
|
||||
if (literal instanceof ASTStringLiteral && literal.jjtGetNumChildren() == 0) {
|
||||
Token firstToken = literal.getFirstToken();
|
||||
if (firstToken != null) {
|
||||
String s = StringUtil.trimEnd(StringUtil.trimStart(firstToken.toString(), "\""), "\"");
|
||||
final FileTemplate includedTemplate = FileTemplateManager.getInstance().getTemplate(s);
|
||||
if (includedTemplate != null && visitedIncludes.add(s)) {
|
||||
SimpleNode template = RuntimeSingleton.parse(new StringReader(includedTemplate.getText()), "MyTemplate");
|
||||
collectAttributes(referenced, defined, template, propertiesNames, includeDummies, visitedIncludes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user