mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-28 21:32:01 +00:00
eclipse plugin: make the schema parser resolve the inheritance
This commit is contained in:
parent
f4d783c88c
commit
94dacc9d8d
@ -85,7 +85,18 @@ public class SchemaParser
|
||||
{
|
||||
if (line.charAt(line.indexOf("[") + 1) == '/')
|
||||
{
|
||||
// propagate the 'needsexpanding' property to upper levels
|
||||
boolean expand = false;
|
||||
if (!tagStack.isEmpty() &&
|
||||
tags_.containsKey(tagStack.peek()))
|
||||
expand = tags_.get(tagStack.peek()).NeedsExpanding;
|
||||
|
||||
tagStack.pop();
|
||||
|
||||
if (!tagStack.isEmpty() &&
|
||||
tags_.containsKey(tagStack.peek()) &&
|
||||
expand == true)
|
||||
tags_.get(tagStack.peek()).NeedsExpanding = expand;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -96,22 +107,25 @@ public class SchemaParser
|
||||
{
|
||||
simpleTagName = tagName.split(":")[0];
|
||||
extendedTagName = tagName.split(":")[1];
|
||||
// System.out.println(tagName);
|
||||
}
|
||||
tagStack.push(simpleTagName);
|
||||
|
||||
if (!tagName.equals("description"))
|
||||
{
|
||||
//System.out.println(simpleTagName);
|
||||
if (tags_.containsKey(simpleTagName))
|
||||
{
|
||||
// this tags was already refered in the schema
|
||||
// before they were declared
|
||||
currentTag = tags_.get(simpleTagName);
|
||||
currentTag.ExtendedTagName = extendedTagName;
|
||||
currentTag.NeedsExpanding = !extendedTagName.isEmpty();
|
||||
}
|
||||
else
|
||||
{
|
||||
Tag tag = new Tag(simpleTagName, extendedTagName, '_');
|
||||
currentTag = tag;
|
||||
currentTag.NeedsExpanding = false;
|
||||
currentTag.NeedsExpanding = !extendedTagName.isEmpty();
|
||||
tags_.put(simpleTagName, tag);
|
||||
}
|
||||
}
|
||||
@ -190,13 +204,9 @@ public class SchemaParser
|
||||
}
|
||||
|
||||
currentTag.addTag(targetTag);
|
||||
currentTag.NeedsExpanding = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!(primitives_.containsKey(value[1])))
|
||||
currentTag.NeedsExpanding = true;
|
||||
|
||||
if (primitives_.get(value[1]) == null)
|
||||
Logger.getInstance().logError("Undefined primitive type in schema.cfg for: " + value[1]);
|
||||
|
||||
@ -213,10 +223,37 @@ public class SchemaParser
|
||||
}
|
||||
|
||||
sortTags();
|
||||
|
||||
for (Tag tag : tags_.values())
|
||||
{
|
||||
expandTag(tag,0);
|
||||
}
|
||||
|
||||
Logger.getInstance().log("parsing done");
|
||||
parsingDone_ = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Expands the tags that need to (the ones based on inheritance)
|
||||
*/
|
||||
private void expandTag(Tag tag, int ind)
|
||||
{
|
||||
if (tag.NeedsExpanding)
|
||||
{
|
||||
tag.NeedsExpanding = false;
|
||||
for (Tag child : tag.TagChildren)
|
||||
{
|
||||
expandTag(child,ind+1);
|
||||
}
|
||||
|
||||
if (tags_.containsKey(tag.ExtendedTagName))
|
||||
{
|
||||
tag.KeyChildren.addAll(tags_.get(tag.ExtendedTagName).KeyChildren);
|
||||
tag.TagChildren.addAll(tags_.get(tag.ExtendedTagName).TagChildren);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the tags in the hashmap
|
||||
*/
|
||||
@ -266,6 +303,7 @@ public class SchemaParser
|
||||
*/
|
||||
public String getOutput(Tag tag, String indent)
|
||||
{
|
||||
System.out.println(tag);
|
||||
String res = indent + "[" + tag.Name + "]\n";
|
||||
for (TagKey key : tag.KeyChildren)
|
||||
{
|
||||
@ -273,6 +311,9 @@ public class SchemaParser
|
||||
}
|
||||
for (Tag tmpTag : tag.TagChildren)
|
||||
{
|
||||
// skip recursive calls
|
||||
if (tmpTag.TagChildren.contains(tag))
|
||||
continue;
|
||||
res += (getOutput(tmpTag, indent + "\t"));
|
||||
}
|
||||
res += (indent + "[/" + tag.Name + "]\n");
|
||||
|
@ -23,7 +23,7 @@ public class Tag
|
||||
public List<TagKey> KeyChildren;
|
||||
public char Cardinality;
|
||||
|
||||
public boolean NeedsExpanding;
|
||||
public boolean NeedsExpanding = false;
|
||||
|
||||
public Tag(String name, List<Tag> tagChildren, List<TagKey> keyChildren, char cardinality) {
|
||||
Name = name;
|
||||
@ -108,4 +108,10 @@ public class Tag
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return new String(Name + " " + ExtendedTagName);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user