eclipse plugin:more validation for tag names

This commit is contained in:
Timotei Dolean 2010-08-01 18:54:28 +00:00
parent 7e3ca20e3c
commit 0cfa9e5dd8
4 changed files with 41 additions and 3 deletions

View File

@ -24,6 +24,7 @@ import wesnoth_eclipse_plugin.utils.StringUtils;
*/
public class SchemaParser
{
//TODO: add a faster search method for keys/tags by name
private static SchemaParser instance_;
public static SchemaParser getInstance()

View File

@ -21,6 +21,7 @@ public class Tag
private String extendedTagName_ = "";
private List<Tag> tagChildren_;
private List<TagKey> keyChildren_;
private Tag description_;
private char cardinality_ = ' ';

View File

@ -8,14 +8,17 @@
*******************************************************************************/
package org.wesnoth;
import wesnoth_eclipse_plugin.schema.SchemaParser;
/**
* Initialization support for running Xtext languages
* without equinox extension registry
*/
public class WMLStandaloneSetup extends WMLStandaloneSetupGenerated{
public class WMLStandaloneSetup extends WMLStandaloneSetupGenerated
{
public static void doSetup() {
new WMLStandaloneSetup().createInjectorAndDoEMFRegistration();
SchemaParser.getInstance().parseSchema(false);
}
}

View File

@ -8,17 +8,50 @@
*******************************************************************************/
package org.wesnoth.validation;
import org.eclipse.xtext.parsetree.CompositeNode;
import org.eclipse.xtext.parsetree.LeafNode;
import org.eclipse.xtext.parsetree.NodeUtil;
import org.eclipse.xtext.validation.Check;
import org.wesnoth.wML.WMLPackage;
import org.wesnoth.wML.WMLTag;
import wesnoth_eclipse_plugin.schema.SchemaParser;
import wesnoth_eclipse_plugin.schema.Tag;
public class WMLJavaValidator extends AbstractWMLJavaValidator
{
@Check
public void checkTagName(WMLTag tag)
{
CompositeNode node = NodeUtil.getNodeAdapter(tag).getParserNode();
if (node != null)
{
LeafNode parentNode = (LeafNode)
NodeUtil.findLeafNodeAtOffset(node, node.getOffset() + 2);
boolean found = false;
String searchName = parentNode.getText();
if (node.getParent().eContainer() == null) // root node
{
searchName = "root";
}
if (SchemaParser.getInstance().getTags().get(searchName) != null)
{
for(Tag childTag : SchemaParser.getInstance().getTags().get(searchName).
getTagChildren())
{
if (childTag.getName().equals(tag.getName()))
{
found = true;
break;
}
}
if (found == false)
warning("There is no such wml tag name.", WMLPackage.WML_TAG__NAME);
}
}
if (!tag.getName().equals(tag.getEndName()))
error("Incorrect closing tag name", WMLPackage.WML_TAG__END_NAME);
error("Incorrect closing tag name.", WMLPackage.WML_TAG__END_NAME);
}
// @Check
// public void checkGreetingStartsWithCapital(Attributes attr) {