mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-19 06:08:55 +00:00
eclipse plugin:more validation for tag names
This commit is contained in:
parent
7e3ca20e3c
commit
0cfa9e5dd8
@ -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()
|
||||
|
@ -21,6 +21,7 @@ public class Tag
|
||||
private String extendedTagName_ = "";
|
||||
private List<Tag> tagChildren_;
|
||||
private List<TagKey> keyChildren_;
|
||||
|
||||
private Tag description_;
|
||||
private char cardinality_ = ' ';
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user