eclipse plugin: Switch over to using a Multimap...

...for storing the variables in each WML Config fil
This commit is contained in:
Timotei Dolean 2011-07-26 15:27:10 +00:00
parent c275ae48be
commit 0215dd54e7
5 changed files with 43 additions and 21 deletions

View file

@ -27,8 +27,8 @@ import org.wesnoth.preprocessor.Define;
import org.wesnoth.preprocessor.PreprocessorUtils;
import org.wesnoth.utils.ResourceUtils;
import org.wesnoth.utils.WorkspaceUtils;
import org.wesnoth.wml.core.Variable;
import org.wesnoth.wml.core.WMLConfig;
import org.wesnoth.wml.core.WMLVariable;
/**
* A class that stores some project specific infos
@ -119,8 +119,9 @@ public class ProjectCache
{
if (variable.getName().startsWith("var") == false) //$NON-NLS-1$
continue;
tmp.getVariables().add(
new Variable(variable.get("name"), //$NON-NLS-1$
tmp.getVariables().put(
variable.get( "name" ),
new WMLVariable(variable.get("name"), //$NON-NLS-1$
variable.get("location"), //$NON-NLS-1$
variable.getInt("offset"))); //$NON-NLS-1$
}
@ -208,7 +209,7 @@ public class ProjectCache
IDialogSettings variablesSection = configSection.addNewSection("variables"); //$NON-NLS-1$
int varCnt = 0;
for(Variable var : config.getVariables())
for(WMLVariable var : config.getVariables().values( ))
{
IDialogSettings varSection = variablesSection.addNewSection("var" + varCnt); //$NON-NLS-1$
varSection.put("name", var.getName()); //$NON-NLS-1$

View file

@ -11,7 +11,7 @@ package org.wesnoth.utils;
import java.util.Stack;
import org.wesnoth.wml.core.WMLConfig;
import org.wesnoth.wml.core.Variable;
import org.wesnoth.wml.core.WMLVariable;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
@ -23,7 +23,7 @@ import org.xml.sax.helpers.DefaultHandler;
public class WMLSaxHandler extends DefaultHandler
{
private Stack<String> stack_;
private Variable tmpVar_;
private WMLVariable tmpVar_;
private String filePath_;
private WMLConfig cfg_;
@ -50,12 +50,12 @@ public class WMLSaxHandler extends DefaultHandler
if (rawName.equals("set_variable")) //$NON-NLS-1$
{
STATUS = SET_VARIABLE;
tmpVar_ = new Variable();
tmpVar_ = new WMLVariable();
}
else if (rawName.equals("set_variables")) //$NON-NLS-1$
{
STATUS = SET_VARIABLE_ARRAY;
tmpVar_ = new Variable();
tmpVar_ = new WMLVariable();
tmpVar_.setIsArray(true);
}
else if (rawName.equals("campaign")) //$NON-NLS-1$
@ -101,7 +101,7 @@ public class WMLSaxHandler extends DefaultHandler
tmpVar_.setOffset(start);
tmpVar_.setLocation(filePath_);
cfg_.getVariables().add(tmpVar_);
cfg_.getVariables().put(name, tmpVar_);
}
}
}

View file

@ -14,9 +14,12 @@ import org.eclipse.emf.ecore.EObject;
import org.wesnoth.utils.ResourceUtils;
import org.wesnoth.utils.WMLUtils;
import org.wesnoth.wml.WMLKey;
import org.wesnoth.wml.WMLMacroCall;
import org.wesnoth.wml.WMLRoot;
import org.wesnoth.wml.WMLTag;
import com.google.common.base.Preconditions;
/**
* A simple WML Parser that parses a xtext WML Config file resource
*/
@ -39,10 +42,7 @@ public class SimpleWMLParser
*/
public SimpleWMLParser( IFile file, WMLConfig config )
{
if ( config == null )
throw new IllegalArgumentException( "The config must not be null." );
config_ = config;
config_ = Preconditions.checkNotNull( config );
file_ = file;
}
@ -58,6 +58,7 @@ public class SimpleWMLParser
while ( itor.hasNext( ) ) {
EObject object = itor.next( );
System.out.println( object );
if ( object instanceof WMLTag ) {
currentTag = ( WMLTag ) object;
@ -78,15 +79,35 @@ public class SimpleWMLParser
config_.ScenarioId = WMLUtils.getKeyValue( key.getValue( ) );
else if ( currentTagName.equals( "campaign" ) )
config_.CampaignId = WMLUtils.getKeyValue( key.getValue( ) );
} else if ( keyName.equals( "name" ) ) {
if ( currentTagName.equals( "set_variable" ) ||
currentTagName.equals( "set_variables" ) ) {
handleSetVariable( object );
}
}
}
}
else if ( object instanceof WMLMacroCall ) {
WMLMacroCall macroCall = ( WMLMacroCall ) object;
String macroCallName = macroCall.getName( );
if ( macroCallName.equals( "VARIABLE" ) ) {
handleSetVariable( object );
}
}
}
System.out.println( "parsed config: " + config_ );
}
protected void handleSetVariable( EObject context )
{
}
protected void handleUnsetVariable( EObject context )
{
}
public WMLConfig getParsedConfig()
{

View file

@ -8,8 +8,8 @@
*******************************************************************************/
package org.wesnoth.wml.core;
import java.util.ArrayList;
import java.util.List;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
/**
* A class that stores WML config file specific information
@ -32,12 +32,12 @@ public class WMLConfig
*/
public boolean IsCampaign;
private List<Variable> variables_;
private Multimap<String, WMLVariable> variables_;
private String filename_;
public WMLConfig(String filename)
{
variables_ = new ArrayList<Variable>();
variables_ = ArrayListMultimap.create( );
filename_ = filename;
}
@ -46,7 +46,7 @@ public class WMLConfig
return filename_;
}
public List<Variable> getVariables()
public Multimap<String, WMLVariable> getVariables()
{
return variables_;
}

View file

@ -11,19 +11,19 @@ package org.wesnoth.wml.core;
/**
* Represents a WML Variable
*/
public class Variable
public class WMLVariable
{
private String name_;
private String location_;
private int offset_;
private boolean isArray_;
public Variable()
public WMLVariable()
{
this("", "", 0); //$NON-NLS-1$ //$NON-NLS-2$
}
public Variable(String name, String location, int offset)
public WMLVariable(String name, String location, int offset)
{
name_ = name;
location_ = location;