eclipse plugin: Refactor the whole generated schema.
Now it bases on the same classes the grammar model uses.
This commit is contained in:
parent
3edabb3e68
commit
5bdcb47e8f
14 changed files with 221 additions and 570 deletions
|
@ -29,8 +29,6 @@ import org.wesnoth.preprocessor.Define;
|
|||
import org.wesnoth.projects.ProjectCache;
|
||||
import org.wesnoth.projects.ProjectUtils;
|
||||
import org.wesnoth.schema.SchemaParser;
|
||||
import org.wesnoth.schema.Tag;
|
||||
import org.wesnoth.schema.TagKey;
|
||||
import org.wesnoth.templates.TemplateProvider;
|
||||
import org.wesnoth.ui.WMLUiModule;
|
||||
import org.wesnoth.ui.editor.WMLEditor;
|
||||
|
@ -39,6 +37,7 @@ import org.wesnoth.utils.ResourceUtils;
|
|||
import org.wesnoth.utils.StringUtils;
|
||||
import org.wesnoth.utils.WMLUtils;
|
||||
import org.wesnoth.wml.WMLKey;
|
||||
import org.wesnoth.wml.WMLKeyValue;
|
||||
import org.wesnoth.wml.WMLTag;
|
||||
import org.wesnoth.wml.core.WMLConfig;
|
||||
import org.wesnoth.wml.core.WMLVariable;
|
||||
|
@ -205,16 +204,16 @@ public class WMLProposalProvider extends AbstractWMLProposalProvider
|
|||
{
|
||||
WMLTag parent = (WMLTag) model.eContainer();
|
||||
String tagName = parent.getName();
|
||||
Tag tag = schemaParser_.getTags().get( tagName );
|
||||
WMLTag tag = schemaParser_.getTags().get( tagName );
|
||||
if (tag != null)
|
||||
{
|
||||
TagKey tagKey = tag.getChildKey( keyName );
|
||||
if (tagKey.isEnum())
|
||||
WMLKey tagKey = WMLUtils.getKeyByName( tag, keyName );
|
||||
if ( tagKey != null && tagKey.is_Enum() )
|
||||
{
|
||||
String[] values = tagKey.getValue().split(","); //$NON-NLS-1$
|
||||
for(String val : values)
|
||||
for(WMLKeyValue val : tagKey.getValue( ) )
|
||||
{
|
||||
acceptor.accept(createCompletionProposal(val, context, KEY_VALUE_PRIORITY));
|
||||
acceptor.accept(createCompletionProposal(
|
||||
val.toString( ), context, KEY_VALUE_PRIORITY ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -274,29 +273,23 @@ public class WMLProposalProvider extends AbstractWMLProposalProvider
|
|||
|
||||
if (tag != null)
|
||||
{
|
||||
Tag schemaTag = schemaParser_.getTags().get(tag.getName());
|
||||
WMLTag schemaTag = schemaParser_.getTags().get(tag.getName());
|
||||
if ( schemaTag != null)
|
||||
{
|
||||
boolean found = false;
|
||||
for(TagKey key : schemaTag.getKeyChildren())
|
||||
for( WMLKey key : WMLUtils.getTagKeys( schemaTag ) )
|
||||
{
|
||||
// skip forbidden keys
|
||||
if (key.isForbidden())
|
||||
if ( key.is_Forbidden( ) )
|
||||
continue;
|
||||
|
||||
found = false;
|
||||
boolean toAdd = true;
|
||||
// check only non-repeatable keys
|
||||
if (key.isRepeatable() == false)
|
||||
{
|
||||
if ( ! key.is_Repeatable() ) {
|
||||
// don't suggest already completed keys
|
||||
for( WMLKey eKey: WMLUtils.getTagKeys( tag ) )
|
||||
if (eKey.getName().equals(key.getName())) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
toAdd = ( WMLUtils.getKeyByName( tag, key.getName( ) ) != null );
|
||||
}
|
||||
|
||||
if (found == false)
|
||||
if ( toAdd )
|
||||
acceptor.accept(createCompletionProposal(key.getName() + "=", //$NON-NLS-1$
|
||||
key.getName(), WML_KEY_IMAGE, context, KEY_NAME_PRIORITY));
|
||||
}
|
||||
|
@ -327,31 +320,26 @@ public class WMLProposalProvider extends AbstractWMLProposalProvider
|
|||
// remove ugly new lines that break indentation
|
||||
parentIndent = parentIndent.replace("\r", "").replace("\n", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
||||
|
||||
Tag tagChildren = schemaParser_.getTags().get(parentTag.getName());
|
||||
WMLTag tagChildren = schemaParser_.getTags().get(parentTag.getName());
|
||||
if (tagChildren != null)
|
||||
{
|
||||
boolean found = false;
|
||||
for(Tag tag : tagChildren.getTagChildren())
|
||||
boolean toAdd = true;
|
||||
for( WMLTag tag : WMLUtils.getTagTags( tagChildren ) )
|
||||
{
|
||||
// skip forbidden tags
|
||||
if (tag.isForbidden())
|
||||
if ( tag.is_Forbidden( ) )
|
||||
continue;
|
||||
|
||||
found = false;
|
||||
toAdd = true;
|
||||
|
||||
// check only non-repeatable tags
|
||||
if (tag.isRepeatable() == false)
|
||||
if ( ! tag.is_Repeatable() )
|
||||
{
|
||||
for( WMLTag wmlTag : WMLUtils.getTagTags( parentTag ) )
|
||||
if (wmlTag.getName().equals(tag.getName()))
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
toAdd = ( WMLUtils.getTagByName( parentTag, tag.getName( ) ) == null );
|
||||
}
|
||||
|
||||
if (found == false)
|
||||
acceptor.accept(createTagProposal(tag, parentIndent,
|
||||
if ( toAdd )
|
||||
acceptor.accept(createTagProposal( tag.asWMLTag( ), parentIndent,
|
||||
ruleProposal, context));
|
||||
}
|
||||
}
|
||||
|
@ -360,11 +348,11 @@ public class WMLProposalProvider extends AbstractWMLProposalProvider
|
|||
}
|
||||
else // we are at the root
|
||||
{
|
||||
Tag rootTag = schemaParser_.getTags().get("root"); //$NON-NLS-1$
|
||||
dbg("root node. adding tags: "+ rootTag.getTagChildren().size()); //$NON-NLS-1$
|
||||
for(Tag tag : rootTag.getTagChildren())
|
||||
WMLTag rootTag = schemaParser_.getTags().get("root"); //$NON-NLS-1$
|
||||
dbg( "root node. adding tags: "+ rootTag.getExpressions( ).size() ); //$NON-NLS-1$
|
||||
for( WMLTag tag : WMLUtils.getTagTags( rootTag ) )
|
||||
{
|
||||
acceptor.accept(createTagProposal(tag, "", ruleProposal, context)); //$NON-NLS-1$
|
||||
acceptor.accept( createTagProposal( tag, "", ruleProposal, context ) ); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -377,17 +365,17 @@ public class WMLProposalProvider extends AbstractWMLProposalProvider
|
|||
* @param context
|
||||
* @return
|
||||
*/
|
||||
private ICompletionProposal createTagProposal(Tag tag, String indent, boolean ruleProposal,
|
||||
ContentAssistContext context)
|
||||
private ICompletionProposal createTagProposal( WMLTag tag, String indent,
|
||||
boolean ruleProposal, ContentAssistContext context)
|
||||
{
|
||||
StringBuilder proposal = new StringBuilder();
|
||||
if (ruleProposal)
|
||||
proposal.append("["); //$NON-NLS-1$
|
||||
proposal.append(tag.getName());
|
||||
proposal.append("]\n"); //$NON-NLS-1$
|
||||
for(TagKey key : tag.getKeyChildren())
|
||||
for( WMLKey key : WMLUtils.getTagKeys( tag ) )
|
||||
{
|
||||
if (key.isRequired())
|
||||
if ( key.is_Required() )
|
||||
proposal.append(String.format("\t%s%s=\n", //$NON-NLS-1$
|
||||
indent, key.getName()));
|
||||
}
|
||||
|
|
|
@ -15,8 +15,8 @@ import org.eclipse.swt.SWT;
|
|||
import org.eclipse.swt.custom.StyleRange;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.wesnoth.schema.SchemaParser;
|
||||
import org.wesnoth.schema.Tag;
|
||||
import org.wesnoth.ui.Messages;
|
||||
import org.wesnoth.wml.WMLTag;
|
||||
|
||||
/**
|
||||
* Displays wml doc for a tag
|
||||
|
@ -24,7 +24,7 @@ import org.wesnoth.ui.Messages;
|
|||
*/
|
||||
public class WMLDocTag implements IWMLDocProvider
|
||||
{
|
||||
private Tag tag_;
|
||||
private WMLTag tag_;
|
||||
private String title_;
|
||||
private String contents_;
|
||||
private List<StyleRange> styleRanges_;
|
||||
|
@ -50,11 +50,11 @@ public class WMLDocTag implements IWMLDocProvider
|
|||
title_ = Messages.WMLDocTag_0 + tag_.getName() + "':"; //$NON-NLS-1$
|
||||
|
||||
StringBuilder content = new StringBuilder();
|
||||
if (tag_.getDescription() != null)
|
||||
if ( !tag_.get_Description().isEmpty( ) )
|
||||
{
|
||||
content.append(Messages.WMLDocTag_1);
|
||||
addStyleRange(0, content.length() - 1, SWT.BOLD);
|
||||
content.append(tag_.getDescription().getChildKey("text").getValue()); //$NON-NLS-1$
|
||||
content.append( tag_.get_Description() ); //$NON-NLS-1$
|
||||
}
|
||||
contents_ = content.toString();
|
||||
}
|
||||
|
|
|
@ -9,7 +9,9 @@
|
|||
package org.wesnoth.schema;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -21,6 +23,10 @@ import org.wesnoth.installs.WesnothInstallsUtils;
|
|||
import org.wesnoth.preferences.Preferences;
|
||||
import org.wesnoth.utils.ResourceUtils;
|
||||
import org.wesnoth.utils.StringUtils;
|
||||
import org.wesnoth.utils.WMLUtils;
|
||||
import org.wesnoth.wml.WMLExpression;
|
||||
import org.wesnoth.wml.WMLTag;
|
||||
import org.wesnoth.wml.WmlFactory2;
|
||||
|
||||
/**
|
||||
* This is a 'schema.cfg' parser.
|
||||
|
@ -64,7 +70,7 @@ public class SchemaParser
|
|||
}
|
||||
|
||||
private Map<String, String> primitives_;
|
||||
private Map<String, Tag> tags_;
|
||||
private Map<String, WMLTag> tags_;
|
||||
private boolean parsingDone_;
|
||||
private String installName_;
|
||||
|
||||
|
@ -72,7 +78,7 @@ public class SchemaParser
|
|||
{
|
||||
installName_ = installName;
|
||||
primitives_ = new HashMap<String, String>();
|
||||
tags_ = new HashMap<String, Tag>();
|
||||
tags_ = new HashMap<String, WMLTag>();
|
||||
parsingDone_ = false;
|
||||
}
|
||||
|
||||
|
@ -115,7 +121,7 @@ public class SchemaParser
|
|||
String[] lines = StringUtils.getLines(res);
|
||||
Stack<String> tagStack = new Stack<String>();
|
||||
|
||||
Tag currentTag = null;
|
||||
WMLTag currentTag = null;
|
||||
for (int index = 0; index < lines.length; index++)
|
||||
{
|
||||
String line = lines[index];
|
||||
|
@ -132,14 +138,14 @@ public class SchemaParser
|
|||
boolean expand = false;
|
||||
if (!tagStack.isEmpty() &&
|
||||
tags_.containsKey(tagStack.peek()))
|
||||
expand = tags_.get(tagStack.peek()).getNeedsExpanding();
|
||||
expand = tags_.get(tagStack.peek()).is_NeedingExpansion();
|
||||
|
||||
tagStack.pop();
|
||||
|
||||
if (!tagStack.isEmpty() &&
|
||||
tags_.containsKey(tagStack.peek()) &&
|
||||
expand == true)
|
||||
tags_.get(tagStack.peek()).setNeedsExpanding(expand);
|
||||
tags_.get(tagStack.peek()).set_NeedingExpansion(expand);
|
||||
}
|
||||
// opening tag
|
||||
else
|
||||
|
@ -161,14 +167,14 @@ public class SchemaParser
|
|||
// this tags was already refered in the schema
|
||||
// before they were declared
|
||||
currentTag = tags_.get(simpleTagName);
|
||||
currentTag.setExtendedTagName(extendedTagName);
|
||||
currentTag.setNeedsExpanding(!extendedTagName.isEmpty());
|
||||
currentTag.set_InhertedTagName(extendedTagName);
|
||||
currentTag.set_NeedingExpansion(!extendedTagName.isEmpty());
|
||||
}
|
||||
else
|
||||
{
|
||||
Tag tag = new Tag(simpleTagName, extendedTagName, '_');
|
||||
WMLTag tag = WmlFactory2.eINSTANCE.createWMLTag( simpleTagName, extendedTagName );
|
||||
tag.set_NeedingExpansion( ! extendedTagName.isEmpty( ) );
|
||||
currentTag = tag;
|
||||
currentTag.setNeedsExpanding(!extendedTagName.isEmpty());
|
||||
tags_.put(simpleTagName, tag);
|
||||
}
|
||||
}
|
||||
|
@ -220,9 +226,7 @@ public class SchemaParser
|
|||
}
|
||||
|
||||
if ( currentTag != null ) {
|
||||
currentTag.setDescription(new Tag("description", '?')); //$NON-NLS-1$
|
||||
currentTag.getDescription().getKeyChildren().add(
|
||||
new TagKey(tokens[0], '?', "", value.toString(), true)); //$NON-NLS-1$
|
||||
currentTag.set_Description( value.toString( ) );
|
||||
}else {
|
||||
System.out.println( "Tag shouldn't have been null!" ); //$NON-NLS-1$
|
||||
}
|
||||
|
@ -253,17 +257,17 @@ public class SchemaParser
|
|||
{
|
||||
if (tokens[0].startsWith("_")) // reference to another tag //$NON-NLS-1$
|
||||
{
|
||||
Tag targetTag = null;
|
||||
if (tags_.containsKey(value[1]))
|
||||
targetTag = tags_.get(value[1]);
|
||||
else
|
||||
// tag wasn't created yet
|
||||
WMLTag targetTag = null;
|
||||
targetTag = tags_.get(value[1]);
|
||||
|
||||
// tag wasn't created yet
|
||||
if ( targetTag == null )
|
||||
{
|
||||
targetTag = new Tag(value[1], getCardinality(value[0]));
|
||||
targetTag = WmlFactory2.eINSTANCE.createWMLTag( value[1], "", getCardinality( value[0] ) );
|
||||
tags_.put(value[1], targetTag);
|
||||
}
|
||||
|
||||
currentTag.addTag(targetTag);
|
||||
currentTag.getExpressions( ).add( targetTag );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -271,8 +275,12 @@ public class SchemaParser
|
|||
Logger.getInstance().logError(
|
||||
"Undefined primitive type in schema.cfg for: " + value[1]); //$NON-NLS-1$
|
||||
|
||||
currentTag.addKey(tokens[0], primitives_.get(value[1]),
|
||||
getCardinality(value[0]), value[1].equals("tstring")); //$NON-NLS-1$
|
||||
currentTag.getExpressions( ).add(
|
||||
WmlFactory2.eINSTANCE.createWMLKey(
|
||||
tokens[0],
|
||||
primitives_.get( value[1] ),
|
||||
getCardinality( value[0] ),
|
||||
value[1].equals( "tstring" ) ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -283,12 +291,13 @@ public class SchemaParser
|
|||
}
|
||||
}
|
||||
|
||||
sortTags();
|
||||
for( WMLTag tag : tags_.values() ) {
|
||||
sortChildren(tag);
|
||||
}
|
||||
|
||||
for (Tag tag : tags_.values())
|
||||
{
|
||||
expandTag(tag,0);
|
||||
}
|
||||
for ( WMLTag tag : tags_.values( ) ) {
|
||||
expandTag( tag );
|
||||
}
|
||||
|
||||
Logger.getInstance().log("parsing done"); //$NON-NLS-1$
|
||||
parsingDone_ = true;
|
||||
|
@ -297,73 +306,51 @@ public class SchemaParser
|
|||
/**
|
||||
* Expands the tags that need to (the ones based on inheritance)
|
||||
*/
|
||||
private void expandTag(Tag tag, int ind)
|
||||
private void expandTag( WMLTag tag )
|
||||
{
|
||||
if (tag.getNeedsExpanding())
|
||||
if (tag.is_NeedingExpansion())
|
||||
{
|
||||
tag.setNeedsExpanding(false);
|
||||
for (Tag child : tag.getTagChildren())
|
||||
{
|
||||
expandTag(child,ind+1);
|
||||
}
|
||||
tag.set_NeedingExpansion(false);
|
||||
|
||||
if (tags_.containsKey(tag.getExtendedTagName()))
|
||||
{
|
||||
tag.getKeyChildren().addAll(tags_.get(tag.getExtendedTagName()).getKeyChildren());
|
||||
tag.getTagChildren().addAll(tags_.get(tag.getExtendedTagName()).getTagChildren());
|
||||
}
|
||||
}
|
||||
}
|
||||
for ( WMLTag subTag : WMLUtils.getTagTags( tag ) ) {
|
||||
expandTag( subTag );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the tags in the hashmap
|
||||
*/
|
||||
private void sortTags()
|
||||
{
|
||||
for(Tag tag : tags_.values())
|
||||
{
|
||||
sortChildren(tag);
|
||||
WMLTag inhertedTag = tags_.get( tag.get_InhertedTagName( ) );
|
||||
if ( inhertedTag != null ) {
|
||||
tag.getExpressions( ).addAll( inhertedTag.getExpressions( ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts all tag's children by using the cardinality comparator
|
||||
* @param tag
|
||||
* @param tag The tag to whom to sort the children
|
||||
*/
|
||||
private void sortChildren(Tag tag)
|
||||
private void sortChildren( WMLTag tag)
|
||||
{
|
||||
Collections.sort(tag.getTagChildren(), new Tag.CardinalityComparator());
|
||||
Collections.sort(tag.getKeyChildren(), new TagKey.CardinalityComparator());
|
||||
Collections.sort( tag.getExpressions( ), new CardinalityComparator( ) );
|
||||
|
||||
for (Tag childTag : tag.getTagChildren())
|
||||
{
|
||||
sortChildren(childTag);
|
||||
}
|
||||
for ( WMLTag subTag : WMLUtils.getTagTags( tag ) ) {
|
||||
sortChildren( subTag );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the hasmap with parsed tags
|
||||
*/
|
||||
public Map<String, Tag> getTags()
|
||||
public Map< String, WMLTag> getTags()
|
||||
{
|
||||
return tags_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the hasmap with the parsed primitives
|
||||
*/
|
||||
public Map<String, String> getPrimitives()
|
||||
{
|
||||
return primitives_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the cardinality as a character of the specified value
|
||||
* required = 1
|
||||
* optional = ?
|
||||
* repeated = *
|
||||
* forbidden = -
|
||||
* @param value The value
|
||||
* @param value The value the parse
|
||||
*/
|
||||
public char getCardinality(String value)
|
||||
{
|
||||
|
@ -377,4 +364,27 @@ public class SchemaParser
|
|||
return '-';
|
||||
return 'a';
|
||||
}
|
||||
|
||||
/**
|
||||
* A WML Expression comparator that sorts just after required cardinality.
|
||||
* That is, after the sort the required wmlexpressions will be first
|
||||
*/
|
||||
public static class CardinalityComparator implements Comparator< WMLExpression >, Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 6103884038547449868L;
|
||||
|
||||
@Override
|
||||
public int compare( WMLExpression o1, WMLExpression o2)
|
||||
{
|
||||
char o1_card = o1.get_Cardinality( );
|
||||
char o2_card = o2.get_Cardinality( );
|
||||
|
||||
if ( o1_card == '1' && o2_card != '1' )
|
||||
return -1;
|
||||
else if ( o2_card == '1' && o1_card != '1' )
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,236 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2010 - 2011 by Timotei Dolean <timotei21@gmail.com>
|
||||
*
|
||||
* This program and the accompanying materials are made available
|
||||
* under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*******************************************************************************/
|
||||
package org.wesnoth.schema;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This represents a wml tag parsed by the schema.
|
||||
*/
|
||||
public class Tag
|
||||
{
|
||||
private String name_ = ""; //$NON-NLS-1$
|
||||
private String extendedTagName_ = ""; //$NON-NLS-1$
|
||||
private List<Tag> tagChildren_;
|
||||
private List<TagKey> keyChildren_;
|
||||
|
||||
private Tag description_;
|
||||
private char cardinality_ = ' ';
|
||||
|
||||
private boolean needsExpanding_ = false;
|
||||
|
||||
public Tag(String name, List<Tag> tagChildren, List<TagKey> keyChildren, char cardinality) {
|
||||
name_ = name;
|
||||
tagChildren_ = tagChildren;
|
||||
keyChildren_ = keyChildren;
|
||||
cardinality_ = cardinality;
|
||||
}
|
||||
|
||||
public Tag(String name, char cardinality) {
|
||||
name_ = name;
|
||||
cardinality_ = cardinality;
|
||||
}
|
||||
|
||||
public Tag(String name, String extendedTagName, char cardinality) {
|
||||
name_ = name;
|
||||
extendedTagName_ = extendedTagName;
|
||||
cardinality_ = cardinality;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ads a child tag
|
||||
* @param tag the Tag to add
|
||||
*/
|
||||
public void addTag(Tag tag)
|
||||
{
|
||||
if (tagChildren_ == null)
|
||||
tagChildren_ = new ArrayList<Tag>();
|
||||
tagChildren_.add(tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a child key
|
||||
* @param key the TagKey to add
|
||||
*/
|
||||
public void addKey(TagKey key)
|
||||
{
|
||||
if (keyChildren_ == null)
|
||||
keyChildren_ = new ArrayList<TagKey>();
|
||||
keyChildren_.add(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a child key
|
||||
* @param name the name of the key
|
||||
* @param valueType the valuetype of the key
|
||||
* @param cardinality the cardinality
|
||||
* @param translate true if it's translatable
|
||||
*/
|
||||
public void addKey(String name, String valueType, char cardinality,
|
||||
boolean translatable)
|
||||
{
|
||||
addKey(new TagKey(name, cardinality, valueType, translatable));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return (name_ + " " + extendedTagName_); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets tag cardinality. Possible values:
|
||||
* required = 1
|
||||
* optional = ?
|
||||
* repeated = *
|
||||
* forbidden = -
|
||||
* @return
|
||||
*/
|
||||
public char getCardinality()
|
||||
{
|
||||
return cardinality_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this tag is required
|
||||
* @return
|
||||
*/
|
||||
public boolean isRequired()
|
||||
{
|
||||
return cardinality_ == '1';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this tag is forbidden to appear
|
||||
* @return
|
||||
*/
|
||||
public boolean isForbidden()
|
||||
{
|
||||
return cardinality_ == '-';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this tag is repeatable
|
||||
* @return
|
||||
*/
|
||||
public boolean isRepeatable()
|
||||
{
|
||||
return cardinality_ == '*';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this tag is optional
|
||||
* @return
|
||||
*/
|
||||
public boolean isOptional()
|
||||
{
|
||||
return cardinality_ == '?';
|
||||
}
|
||||
|
||||
public void setDescription(Tag description)
|
||||
{
|
||||
description_ = description;
|
||||
}
|
||||
public Tag getDescription()
|
||||
{
|
||||
return description_;
|
||||
}
|
||||
|
||||
public String getExtendedTagName()
|
||||
{
|
||||
return extendedTagName_;
|
||||
}
|
||||
public void setExtendedTagName(String extendedTagName)
|
||||
{
|
||||
extendedTagName_ = extendedTagName;
|
||||
}
|
||||
|
||||
public void setNeedsExpanding(boolean needsExpanding)
|
||||
{
|
||||
needsExpanding_ = needsExpanding;
|
||||
}
|
||||
public boolean getNeedsExpanding()
|
||||
{
|
||||
return needsExpanding_;
|
||||
}
|
||||
|
||||
public List<TagKey> getKeyChildren()
|
||||
{
|
||||
if (keyChildren_ == null)
|
||||
keyChildren_ = new ArrayList<TagKey>();
|
||||
return keyChildren_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key child that has the specified name or
|
||||
* null if none found
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public TagKey getChildKey(String name)
|
||||
{
|
||||
for(TagKey key : keyChildren_)
|
||||
{
|
||||
if (key.getName().equals(name))
|
||||
return key;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<Tag> getTagChildren()
|
||||
{
|
||||
if (tagChildren_ == null)
|
||||
tagChildren_ = new ArrayList<Tag>();
|
||||
return tagChildren_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the tag child that has the specified name
|
||||
* or null if none found
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public Tag getChildTag(String name)
|
||||
{
|
||||
for (Tag tag : tagChildren_)
|
||||
{
|
||||
if (tag.getName().equals(name))
|
||||
return tag;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* A tag comparator that sorts just after required cardinality.
|
||||
*/
|
||||
public static class CardinalityComparator implements Comparator<Tag>, Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 6586560133116048689L;
|
||||
|
||||
@Override
|
||||
public int compare(Tag o1, Tag o2)
|
||||
{
|
||||
if (o1.cardinality_ == o2.cardinality_)
|
||||
return 0;
|
||||
if (o1.cardinality_ == '1')
|
||||
return 1;
|
||||
else if (o2.cardinality_ == '1')
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,157 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2010 - 2011 by Timotei Dolean <timotei21@gmail.com>
|
||||
*
|
||||
* This program and the accompanying materials are made available
|
||||
* under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*******************************************************************************/
|
||||
package org.wesnoth.schema;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
* This class represents a tag's key parsed by the schema
|
||||
*/
|
||||
public class TagKey
|
||||
{
|
||||
private String name_;
|
||||
/**
|
||||
* Cardinality can be:
|
||||
* 1 = required
|
||||
* ? = optional
|
||||
* * = repeated
|
||||
* - = forbidden
|
||||
*/
|
||||
private char cardinality_;
|
||||
private String value_;
|
||||
private boolean isEnum_;
|
||||
private boolean isTranslatable_;
|
||||
|
||||
public TagKey(String name, char cardinality, String valueType, boolean trans) {
|
||||
name_ = name;
|
||||
cardinality_ = cardinality;
|
||||
value_ = ""; //$NON-NLS-1$
|
||||
|
||||
if (valueType == null || valueType.isEmpty())
|
||||
{
|
||||
isEnum_ = false;
|
||||
isTranslatable_ = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
isEnum_ = valueType.substring(1, valueType.indexOf(" ")).equals("enum"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
// remove the " "
|
||||
value_ = valueType.substring(valueType.indexOf(" ") + 1, valueType.length() - 1); //$NON-NLS-1$
|
||||
isTranslatable_ = trans;
|
||||
}
|
||||
}
|
||||
|
||||
public TagKey(String name, char cardinality, String valueType,
|
||||
String defaultValue, boolean trans)
|
||||
{
|
||||
this(name, cardinality, valueType, trans);
|
||||
value_ = defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* A tag comparator that sorts just after required cardinality.
|
||||
*/
|
||||
public static class CardinalityComparator implements Comparator<TagKey>, Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 6103884038547449868L;
|
||||
|
||||
@Override
|
||||
public int compare(TagKey o1, TagKey o2)
|
||||
{
|
||||
if (o1.cardinality_ == o2.cardinality_)
|
||||
return 0;
|
||||
if (o1.cardinality_ == '1')
|
||||
return -1;
|
||||
else if (o2.cardinality_ == '1')
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Possible values:
|
||||
* required = 1
|
||||
* optional = ?
|
||||
* repeated = *
|
||||
* forbidden = -
|
||||
* @return
|
||||
*/
|
||||
public char getCardinality()
|
||||
{
|
||||
return cardinality_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this key is required
|
||||
* @return
|
||||
*/
|
||||
public boolean isRequired()
|
||||
{
|
||||
return cardinality_ == '1';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this key is forbidden to appear
|
||||
* @return
|
||||
*/
|
||||
public boolean isForbidden()
|
||||
{
|
||||
return cardinality_ == '-';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this key is repeatable
|
||||
* @return
|
||||
*/
|
||||
public boolean isRepeatable()
|
||||
{
|
||||
return cardinality_ == '*';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this key is optional
|
||||
* @return
|
||||
*/
|
||||
public boolean isOptional()
|
||||
{
|
||||
return cardinality_ == '?';
|
||||
}
|
||||
|
||||
public void setCardinality(char cardinality)
|
||||
{
|
||||
cardinality_ = cardinality;
|
||||
}
|
||||
|
||||
public String getValue()
|
||||
{
|
||||
return value_;
|
||||
}
|
||||
|
||||
public void setValue(String value)
|
||||
{
|
||||
value_ = value;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
public boolean isTranslatable()
|
||||
{
|
||||
return isTranslatable_;
|
||||
}
|
||||
|
||||
public boolean isEnum()
|
||||
{
|
||||
return isEnum_;
|
||||
}
|
||||
}
|
|
@ -41,13 +41,29 @@ public class WMLUtils
|
|||
{
|
||||
List<WMLKey> result = new ArrayList<WMLKey>();
|
||||
for ( WMLExpression expression : tag.getExpressions( ) ) {
|
||||
if ( expression instanceof WMLKey )
|
||||
result.add( ( WMLKey ) expression );
|
||||
if ( expression.isWMLKey( ) )
|
||||
result.add( expression.asWMLKey( ) );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the child key of the specified tag by its name.
|
||||
* @param tag The tag to search into
|
||||
* @param name The name of the key to search for
|
||||
* @return Returns the found key or null if non existing
|
||||
*/
|
||||
public static WMLKey getKeyByName( WMLTag tag, String name )
|
||||
{
|
||||
for ( WMLKey key: getTagKeys( tag ) ) {
|
||||
if ( key.getName( ).equals( name ) )
|
||||
return key;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of child tags for this tag
|
||||
* @param tag The tag to process
|
||||
|
@ -57,13 +73,29 @@ public class WMLUtils
|
|||
{
|
||||
List<WMLTag> result = new ArrayList<WMLTag>();
|
||||
for ( WMLExpression expression : tag.getExpressions( ) ) {
|
||||
if ( expression instanceof WMLTag )
|
||||
result.add( ( WMLTag ) expression );
|
||||
if ( expression.isWMLTag( ) )
|
||||
result.add( expression.asWMLTag( ) );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the child tag of the specified tag by its name.
|
||||
* @param tag The tag to search into
|
||||
* @param name The name of the tag to search for
|
||||
* @return Returns the found tag or null if non existing
|
||||
*/
|
||||
public static WMLTag getTagByName( WMLTag tag, String name )
|
||||
{
|
||||
for ( WMLTag subTag : getTagTags( tag ) ) {
|
||||
if ( subTag.asWMLTag( ).getName( ).equals( name ) )
|
||||
return subTag;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key value from the list as a string value
|
||||
* @param values The list of values of the key
|
||||
|
@ -95,15 +127,15 @@ public class WMLUtils
|
|||
StringBuilder res = new StringBuilder( );
|
||||
|
||||
res.append( indent + "[" + tag.getName( ) );
|
||||
if ( ! tag.get_extendedTagName( ).isEmpty( ) )
|
||||
res.append( ":" + tag.get_extendedTagName( ) );
|
||||
if ( ! tag.get_InhertedTagName( ).isEmpty( ) )
|
||||
res.append( ":" + tag.get_InhertedTagName( ) );
|
||||
res.append( "]\n"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
for ( WMLExpression expression : tag.getExpressions( ) ) {
|
||||
if ( expression instanceof WMLKey )
|
||||
res.append( indent + "\t" + toWMLString( ( WMLKey ) expression ) );
|
||||
else if ( expression instanceof WMLTag )
|
||||
res.append( indent + "\t" + toWMLString( ( WMLTag ) expression ) );
|
||||
if ( expression.isWMLKey( ) )
|
||||
res.append( indent + "\t" + toWMLString( expression.asWMLKey( ) ) );
|
||||
else if ( expression.isWMLTag( ) )
|
||||
res.append( indent + "\t" + toWMLString( expression.asWMLTag( ) ) );
|
||||
}
|
||||
|
||||
res.append( indent + "[/" + tag.getEndName( ) + "]\n" );
|
||||
|
|
|
@ -20,7 +20,7 @@ import org.eclipse.xtext.validation.CheckType;
|
|||
import org.wesnoth.Messages;
|
||||
import org.wesnoth.installs.WesnothInstallsUtils;
|
||||
import org.wesnoth.schema.SchemaParser;
|
||||
import org.wesnoth.schema.Tag;
|
||||
import org.wesnoth.wml.WMLExpression;
|
||||
import org.wesnoth.wml.WMLKey;
|
||||
import org.wesnoth.wml.WMLMacroCall;
|
||||
import org.wesnoth.wml.WMLRoot;
|
||||
|
@ -65,14 +65,14 @@ public class WMLJavaValidator extends AbstractWMLJavaValidator
|
|||
IResource file = ResourcesPlugin.getWorkspace( ).getRoot( ).
|
||||
getFile( new Path( resource.getURI( ).toPlatformString( true ) ) );
|
||||
|
||||
Tag schemaTag = SchemaParser.getInstance(
|
||||
WMLTag schemaTag = SchemaParser.getInstance(
|
||||
WesnothInstallsUtils.getInstallNameForResource( file ) ).getTags().get(searchName);
|
||||
|
||||
if ( schemaTag != null )
|
||||
{
|
||||
for(Tag childTag : schemaTag.getTagChildren())
|
||||
for( WMLExpression expression : schemaTag.getExpressions( ) )
|
||||
{
|
||||
if (childTag.getName().equals(tag.getName()))
|
||||
if (expression.getName().equals(tag.getName()))
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
|
|
|
@ -8,12 +8,16 @@
|
|||
*******************************************************************************/
|
||||
package org.wesnoth.wizards.generator;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jface.wizard.IWizardPage;
|
||||
import org.wesnoth.Constants;
|
||||
import org.wesnoth.schema.SchemaParser;
|
||||
import org.wesnoth.schema.Tag;
|
||||
import org.wesnoth.utils.StringUtils;
|
||||
import org.wesnoth.utils.WMLUtils;
|
||||
import org.wesnoth.wizards.NewWizardTemplate;
|
||||
import org.wesnoth.wml.WMLKey;
|
||||
import org.wesnoth.wml.WMLTag;
|
||||
|
||||
|
||||
public class WizardGenerator extends NewWizardTemplate
|
||||
|
@ -24,7 +28,7 @@ public class WizardGenerator extends NewWizardTemplate
|
|||
public WizardGenerator(String title, String tagName, int indent) {
|
||||
SchemaParser.getInstance( null ).parseSchema(false);
|
||||
setWindowTitle(title);
|
||||
Tag tagContent = SchemaParser.getInstance( null ).getTags().get(tagName);
|
||||
WMLTag tagContent = SchemaParser.getInstance( null ).getTags().get(tagName);
|
||||
|
||||
tagName_ = tagName;
|
||||
indent_ = indent;
|
||||
|
@ -33,37 +37,40 @@ public class WizardGenerator extends NewWizardTemplate
|
|||
else
|
||||
{
|
||||
// keys section
|
||||
int keysNr = tagContent.getKeyChildren().size();
|
||||
List<WMLKey> keys = WMLUtils.getTagKeys( tagContent );
|
||||
int keysNr = keys.size();
|
||||
int startKey = 0, pgsKey = (keysNr / Constants.WIZ_MaxTextBoxesOnPage);
|
||||
WizardGeneratorPageKey tempPageKey;
|
||||
for (int i = 0; i < pgsKey; i++)
|
||||
{
|
||||
tempPageKey = new WizardGeneratorPageKey(tagName, tagContent.getKeyChildren(), startKey,
|
||||
startKey + Constants.WIZ_MaxTextBoxesOnPage, indent_ + 1 );
|
||||
tempPageKey = new WizardGeneratorPageKey(tagName, keys,
|
||||
startKey, startKey + Constants.WIZ_MaxTextBoxesOnPage, indent_ + 1 );
|
||||
startKey += Constants.WIZ_MaxTextBoxesOnPage;
|
||||
addPage(tempPageKey);
|
||||
}
|
||||
|
||||
if (keysNr - 1 > 0)
|
||||
{
|
||||
tempPageKey = new WizardGeneratorPageKey(tagName, tagContent.getKeyChildren(),
|
||||
tempPageKey = new WizardGeneratorPageKey(tagName, keys,
|
||||
startKey, keysNr - 1, indent_ + 1 );
|
||||
addPage(tempPageKey);
|
||||
}
|
||||
|
||||
// tags section
|
||||
int tagsNr = tagContent.getTagChildren().size();
|
||||
List<WMLTag> tags = WMLUtils.getTagTags( tagContent );
|
||||
int tagsNr = tags.size();
|
||||
int startTag = 0, pgsTag = (tagsNr / Constants.WIZ_MaxGroupsOnPage);
|
||||
WizardGeneratorPageTag tempPageTag;
|
||||
for (int i = 0; i < pgsTag; i++)
|
||||
{
|
||||
tempPageTag = new WizardGeneratorPageTag(tagName, tagContent.getTagChildren(), startTag,
|
||||
tempPageTag = new WizardGeneratorPageTag(tagName, tags, startTag,
|
||||
startTag + Constants.WIZ_MaxGroupsOnPage, indent_ + 1);
|
||||
startTag += Constants.WIZ_MaxTextBoxesOnPage;
|
||||
addPage(tempPageTag);
|
||||
}
|
||||
if (tagsNr - 1 > 0)
|
||||
{
|
||||
tempPageTag = new WizardGeneratorPageTag(tagName, tagContent.getTagChildren(),
|
||||
tempPageTag = new WizardGeneratorPageTag(tagName, tags,
|
||||
startTag, tagsNr - 1, indent_ + 1 );
|
||||
addPage(tempPageTag);
|
||||
}
|
||||
|
|
|
@ -21,19 +21,20 @@ import org.eclipse.swt.widgets.Control;
|
|||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
import org.wesnoth.Messages;
|
||||
import org.wesnoth.schema.TagKey;
|
||||
import org.wesnoth.utils.StringUtils;
|
||||
import org.wesnoth.wizards.NewWizardPageTemplate;
|
||||
import org.wesnoth.wml.WMLKey;
|
||||
import org.wesnoth.wml.WMLKeyValue;
|
||||
|
||||
|
||||
public class WizardGeneratorPageKey extends NewWizardPageTemplate
|
||||
{
|
||||
private List<TagKey> keys_;
|
||||
private List<WMLKey> keys_;
|
||||
private int startIndex_, endIndex_;
|
||||
private Composite container_;
|
||||
private int indent_;
|
||||
|
||||
public WizardGeneratorPageKey(String tagName, List<TagKey> keys,
|
||||
public WizardGeneratorPageKey(String tagName, List<WMLKey> keys,
|
||||
int startIndex, int endIndex, int indent) {
|
||||
super(Messages.WizardGeneratorPageKey_0 + startIndex);
|
||||
setTitle(tagName + Messages.WizardGeneratorPageKey_1);
|
||||
|
@ -56,24 +57,27 @@ public class WizardGeneratorPageKey extends NewWizardPageTemplate
|
|||
|
||||
for (int i = startIndex_; i <= endIndex_; i++)
|
||||
{
|
||||
TagKey key = keys_.get(i);
|
||||
WMLKey key = keys_.get(i);
|
||||
|
||||
if (key.isForbidden())
|
||||
if (key.is_Forbidden())
|
||||
continue;
|
||||
|
||||
Label label = new Label(container_, SWT.NONE);
|
||||
label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
|
||||
// add star to required items
|
||||
label.setText(key.getName() + (key.isRequired() ? "*" : "") + ":"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
label.setText(key.getName() + (key.is_Enum() ? "*" : "") + ":"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
|
||||
// if the is an enum create a combobox instead of textbox
|
||||
if (key.isEnum())
|
||||
if (key.is_Enum())
|
||||
{
|
||||
Combo combo = new Combo(container_, SWT.READ_ONLY);
|
||||
combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
|
||||
combo.setData("name", key.getName()); //$NON-NLS-1$
|
||||
String[] items = key.getValue().split(","); //$NON-NLS-1$
|
||||
combo.setItems(items);
|
||||
|
||||
for ( WMLKeyValue value : key.getValue( ) ) {
|
||||
combo.add( value.toString( ) );
|
||||
}
|
||||
|
||||
combo.select(0);
|
||||
}
|
||||
else
|
||||
|
@ -83,9 +87,9 @@ public class WizardGeneratorPageKey extends NewWizardPageTemplate
|
|||
|
||||
textBox.setData("name", key.getName()); //$NON-NLS-1$
|
||||
textBox.setData("valType", key.getValue()); //$NON-NLS-1$
|
||||
textBox.setData("card", key.getCardinality()); //$NON-NLS-1$
|
||||
textBox.setData("trans", key.isTranslatable()); //$NON-NLS-1$
|
||||
if (key.isRequired())
|
||||
textBox.setData("card", key.get_Cardinality()); //$NON-NLS-1$
|
||||
textBox.setData("trans", key.is_Translatable()); //$NON-NLS-1$
|
||||
if ( key.is_Required( ) )
|
||||
textBox.setData("comp", false); // is textbox complete //$NON-NLS-1$
|
||||
|
||||
textBox.addModifyListener(new ModifyListener() {
|
||||
|
|
|
@ -24,23 +24,23 @@ import org.eclipse.swt.widgets.Control;
|
|||
import org.eclipse.swt.widgets.Group;
|
||||
import org.eclipse.swt.widgets.List;
|
||||
import org.wesnoth.Messages;
|
||||
import org.wesnoth.schema.Tag;
|
||||
import org.wesnoth.utils.GUIUtils;
|
||||
import org.wesnoth.utils.ListUtils;
|
||||
import org.wesnoth.utils.StringUtils;
|
||||
import org.wesnoth.utils.WizardUtils;
|
||||
import org.wesnoth.wizards.NewWizardPageTemplate;
|
||||
import org.wesnoth.wml.WMLTag;
|
||||
|
||||
|
||||
public class WizardGeneratorPageTag extends NewWizardPageTemplate
|
||||
{
|
||||
private java.util.List<Tag> tags_;
|
||||
private java.util.List<WMLTag> tags_;
|
||||
private Map<String, java.util.List<String>> content_;
|
||||
private int startIndex_, endIndex_;
|
||||
private Composite container_;
|
||||
private int indent_;
|
||||
|
||||
public WizardGeneratorPageTag(String tagName, java.util.List<Tag> tags,
|
||||
public WizardGeneratorPageTag(String tagName, java.util.List<WMLTag> tags,
|
||||
int startIndex, int endIndex, int indent) {
|
||||
super("wizardPageTag" + startIndex); //$NON-NLS-1$
|
||||
setTitle(tagName + Messages.WizardGeneratorPageTag_1);
|
||||
|
@ -64,8 +64,8 @@ public class WizardGeneratorPageTag extends NewWizardPageTemplate
|
|||
|
||||
for (int i = startIndex_; i <= endIndex_; i++)
|
||||
{
|
||||
final Tag tag = tags_.get(i);
|
||||
if (tag.isForbidden())
|
||||
final WMLTag tag = tags_.get(i);
|
||||
if (tag.is_Forbidden())
|
||||
continue;
|
||||
|
||||
Group tagGroup = new Group(container_, SWT.NONE);
|
||||
|
@ -116,9 +116,9 @@ public class WizardGeneratorPageTag extends NewWizardPageTemplate
|
|||
updatePageIsComplete();
|
||||
}
|
||||
|
||||
private void addNewItem(List targetList, Tag tag)
|
||||
private void addNewItem(List targetList, WMLTag tag)
|
||||
{
|
||||
if ((tag.isOptional() || tag.isRequired()) &&
|
||||
if ((tag.is_Optional() || tag.is_Required()) &&
|
||||
targetList.getItemCount() == 1)
|
||||
{
|
||||
GUIUtils.showWarnMessageBox(Messages.WizardGeneratorPageTag_12);
|
||||
|
@ -159,8 +159,8 @@ public class WizardGeneratorPageTag extends NewWizardPageTemplate
|
|||
continue;
|
||||
|
||||
int cnt = ((List)control.getData("list")).getItemCount(); //$NON-NLS-1$
|
||||
Tag tag = (Tag)control.getData("tag"); //$NON-NLS-1$
|
||||
if (cnt == 0 && tag.isRequired())
|
||||
WMLTag tag = (WMLTag)control.getData("tag"); //$NON-NLS-1$
|
||||
if (cnt == 0 && tag.is_Required())
|
||||
{
|
||||
setErrorMessage(String.format(Messages.WizardGeneratorPageTag_0, tag.getName()));
|
||||
return;
|
||||
|
|
|
@ -19,6 +19,5 @@ public interface WmlFactory2 extends WmlFactory
|
|||
WMLTag createWMLTag( String name, String extendedName, char cardinality );
|
||||
|
||||
WMLKey createWMLKey( String name, String dataType );
|
||||
WMLKey createWMLKey( String name, String dataType, char cardinality );
|
||||
WMLKey createWMLKey( String name, String dataType, char cardinality, boolean translatable );
|
||||
}
|
||||
|
|
|
@ -16,8 +16,9 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import org.wesnoth.Logger;
|
||||
import org.wesnoth.schema.Tag;
|
||||
import org.wesnoth.utils.StringUtils;
|
||||
import org.wesnoth.wml.WMLTag;
|
||||
import org.wesnoth.wml.WmlFactory2;
|
||||
|
||||
/**
|
||||
* This is a simple Lua parser that returns the found interesting tokens
|
||||
|
@ -25,7 +26,7 @@ import org.wesnoth.utils.StringUtils;
|
|||
*/
|
||||
public class SimpleLuaParser
|
||||
{
|
||||
private List<Tag> tags_;
|
||||
private List<WMLTag> tags_;
|
||||
private Reader reader_;
|
||||
|
||||
private final static String TAG_REGEX = "wml_actions\\..+\\( *cfg *\\)";
|
||||
|
@ -34,7 +35,7 @@ public class SimpleLuaParser
|
|||
|
||||
public SimpleLuaParser( String contents )
|
||||
{
|
||||
tags_ = new ArrayList<Tag> ( );
|
||||
tags_ = new ArrayList<WMLTag> ( );
|
||||
reader_ = new StringReader( contents == null ? "" : contents );
|
||||
}
|
||||
|
||||
|
@ -46,7 +47,7 @@ public class SimpleLuaParser
|
|||
BufferedReader reader = new BufferedReader( reader_ );
|
||||
String line = null;
|
||||
|
||||
Tag currentTag = null;
|
||||
WMLTag currentTag = null;
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -61,7 +62,7 @@ public class SimpleLuaParser
|
|||
token.indexOf( '.' ) + 1,
|
||||
token.lastIndexOf( '(' ) );
|
||||
|
||||
currentTag = new Tag( tagName, '*' );
|
||||
currentTag = WmlFactory2.eINSTANCE.createWMLTag( tagName );
|
||||
tags_.add( currentTag );
|
||||
}
|
||||
|
||||
|
@ -72,7 +73,8 @@ public class SimpleLuaParser
|
|||
String attributeName = token.substring(
|
||||
token.indexOf( '.' ) + 1 );
|
||||
|
||||
currentTag.addKey( attributeName, "string", '*', true );
|
||||
currentTag.getExpressions( ).add(
|
||||
WmlFactory2.eINSTANCE.createWMLKey( attributeName, "string" ) );
|
||||
}
|
||||
|
||||
List<String> childTokens = StringUtils.getGroups( ATTRIBUTE_CHILD_REGEX, line );
|
||||
|
@ -81,7 +83,8 @@ public class SimpleLuaParser
|
|||
token.indexOf( '"' ) + 1,
|
||||
token.lastIndexOf( '"' ) );
|
||||
|
||||
currentTag.addKey( childName, "string", '*', true );
|
||||
currentTag.getExpressions( ).add(
|
||||
WmlFactory2.eINSTANCE.createWMLKey( childName, "string" ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -95,7 +98,7 @@ public class SimpleLuaParser
|
|||
* Returns the parsed tags from the lua code
|
||||
* @return A list with Tags
|
||||
*/
|
||||
public List<Tag> getTags()
|
||||
public List< WMLTag > getTags()
|
||||
{
|
||||
return tags_;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ import org.eclipse.emf.ecore.EObject;
|
|||
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
|
||||
import org.wesnoth.Logger;
|
||||
import org.wesnoth.projects.ProjectCache;
|
||||
import org.wesnoth.schema.Tag;
|
||||
import org.wesnoth.utils.ResourceUtils;
|
||||
import org.wesnoth.utils.WMLUtils;
|
||||
import org.wesnoth.wml.WMLKey;
|
||||
|
@ -38,7 +37,7 @@ public class SimpleWMLParser
|
|||
protected IFile file_;
|
||||
protected ProjectCache projectCache_;
|
||||
protected int dependencyIndex_;
|
||||
protected List<Tag> tags_;
|
||||
protected List<WMLTag> tags_;
|
||||
|
||||
/**
|
||||
* Creates a new parser for the specified file
|
||||
|
@ -64,7 +63,7 @@ public class SimpleWMLParser
|
|||
file_ = file;
|
||||
projectCache_ = projCache;
|
||||
|
||||
tags_ = new ArrayList<Tag>();
|
||||
tags_ = new ArrayList<WMLTag>();
|
||||
|
||||
dependencyIndex_ = ResourceUtils.getDependencyIndex( file );
|
||||
}
|
||||
|
@ -214,7 +213,7 @@ public class SimpleWMLParser
|
|||
* Returns the parsed tags
|
||||
* @return A list of tags
|
||||
*/
|
||||
public List<Tag> getParsedTags()
|
||||
public List<WMLTag> getParsedTags()
|
||||
{
|
||||
return tags_;
|
||||
}
|
||||
|
|
|
@ -43,13 +43,7 @@ public class WmlFactory2Impl extends WmlFactoryImpl implements WmlFactory2
|
|||
@Override
|
||||
public WMLKey createWMLKey( String name, String dataType )
|
||||
{
|
||||
return createWMLKey( name, dataType, '*' );
|
||||
}
|
||||
|
||||
@Override
|
||||
public WMLKey createWMLKey( String name, String dataType, char cardinality )
|
||||
{
|
||||
return createWMLKey( name, dataType, cardinality, false );
|
||||
return createWMLKey( name, dataType, '*', false );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -60,6 +54,14 @@ public class WmlFactory2Impl extends WmlFactoryImpl implements WmlFactory2
|
|||
key.setName( name );
|
||||
|
||||
key.set_DataType( dataType );
|
||||
|
||||
if ( dataType.startsWith( "enum" ) ) {
|
||||
// add the enums values
|
||||
//TODO: fix
|
||||
|
||||
key.set_Enum( true );
|
||||
}
|
||||
|
||||
key.set_Cardinality( cardinality );
|
||||
key.set_Translatable( translatable );
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue