eclipse plugin: Make the variables reside in the...

...project cache instead of the file
This commit is contained in:
Timotei Dolean 2011-07-26 15:28:11 +00:00
parent 84c2a50213
commit 16d4519de8
4 changed files with 62 additions and 43 deletions

View file

@ -30,6 +30,9 @@ import org.wesnoth.utils.WorkspaceUtils;
import org.wesnoth.wml.core.WMLConfig;
import org.wesnoth.wml.core.WMLVariable;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
/**
* A class that stores some project specific infos
* for current session.
@ -50,6 +53,7 @@ public class ProjectCache
private Map< String, WMLConfig > configFiles_;
private Map< String, Define > defines_;
private DependencyListBuilder dependTree_;
private Multimap<String, WMLVariable> variables_;
private IProject project_;
@ -57,8 +61,9 @@ public class ProjectCache
{
project_ = project;
configFiles_ = new HashMap<String, WMLConfig>();
defines_ = new HashMap<String, Define>(0);
configFiles_ = new HashMap<String, WMLConfig>( );
defines_ = new HashMap<String, Define>( );
variables_ = ArrayListMultimap.create( );
dependTree_ = new DependencyListBuilder( project_ );
@ -115,20 +120,26 @@ public class ProjectCache
tmp.ScenarioId = config.get( "scenario_id" ); //$NON-NLS-1$
tmp.CampaignId = config.get( "campaign_id" ); //$NON-NLS-1$
for(IDialogSettings variable : config.getSection("variables").getSections()) //$NON-NLS-1$
{
if (variable.getName().startsWith("var") == false) //$NON-NLS-1$
continue;
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$
}
configFiles_.put(config.get("filename"), tmp); //$NON-NLS-1$
}
}
if ( properties_.getSection( "variables" ) != null ){
for(IDialogSettings variable : properties_.getSection("variables").getSections()) //$NON-NLS-1$
{
if (variable.getName().startsWith("var") == false) //$NON-NLS-1$
continue;
variables_.put( variable.get( "name" ),
new WMLVariable(variable.get("name"), //$NON-NLS-1$
variable.get("location"), //$NON-NLS-1$
variable.getInt("offset"),
variable.getInt( "startIndex" ),
variable.getInt( "endIndex" ))); //$NON-NLS-1$
}
}
// unserialize the tree builder
if ( treeCacheFile_.exists( ) ) {
FileInputStream inStream = new FileInputStream( treeCacheFile_ );
@ -185,6 +196,15 @@ public class ProjectCache
return config;
}
/**
* Returns the variables found in this project
* @return A multimap containing all the variables
*/
public Multimap<String, WMLVariable> getVariables()
{
return variables_;
}
/**
* Saves the cache to disk.
* Saves:
@ -207,20 +227,23 @@ public class ProjectCache
configSection.put("campaign_id", config.CampaignId); //$NON-NLS-1$
configSection.put("filename", config.getFilename()); //$NON-NLS-1$
IDialogSettings variablesSection = configSection.addNewSection("variables"); //$NON-NLS-1$
int varCnt = 0;
for(WMLVariable var : config.getVariables().values( ))
{
IDialogSettings varSection = variablesSection.addNewSection("var" + varCnt); //$NON-NLS-1$
varSection.put("name", var.getName()); //$NON-NLS-1$
varSection.put("location", var.getLocation()); //$NON-NLS-1$
varSection.put("offset", var.getOffset()); //$NON-NLS-1$
++varCnt;
}
++configCnt;
}
IDialogSettings variablesSection = properties_.addNewSection("variables"); //$NON-NLS-1$
int varCnt = 0;
for(WMLVariable var : variables_.values( ))
{
IDialogSettings varSection = variablesSection.addNewSection("var" + varCnt); //$NON-NLS-1$
varSection.put("name", var.getName()); //$NON-NLS-1$
varSection.put("location", var.getLocation()); //$NON-NLS-1$
varSection.put("offset", var.getOffset()); //$NON-NLS-1$
varSection.put( "startIndex", var.getScopeStartIndex( ) );
varSection.put( "endIndex", var.getScopeEndIndex( ) );
++varCnt;
}
// store properties
properties_.save( wesnothFile_.getAbsolutePath() );
propertiesTimestamp_ = wesnothFile_.lastModified();

View file

@ -13,6 +13,7 @@ import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.nodemodel.ICompositeNode;
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
import org.wesnoth.projects.ProjectCache;
import org.wesnoth.utils.ResourceUtils;
import org.wesnoth.utils.WMLUtils;
import org.wesnoth.wml.WMLKey;
@ -29,6 +30,7 @@ public class SimpleWMLParser
{
protected WMLConfig config_;
protected IFile file_;
protected ProjectCache projectCache_;
/**
* Creates a new parser for the specified file
@ -53,9 +55,6 @@ public class SimpleWMLParser
*/
public void parse()
{
// clear all variables before parsing them
config_.getVariables( ).clear( );
WMLRoot root = ResourceUtils.getWMLRoot( file_ );
TreeIterator<EObject> itor = root.eAllContents( );
WMLTag currentTag = null;
@ -123,7 +122,7 @@ public class SimpleWMLParser
}
if ( ! variable.getName( ).isEmpty( ) ) {
config_.getVariables( ).put( variable.getName( ), variable );
projectCache_.getVariables( ).put( variable.getName( ), variable );
}
}

View file

@ -8,8 +8,6 @@
*******************************************************************************/
package org.wesnoth.wml.core;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
/**
* A class that stores WML config file specific information
@ -32,12 +30,10 @@ public class WMLConfig
*/
public boolean IsCampaign;
private Multimap<String, WMLVariable> variables_;
private String filename_;
public WMLConfig(String filename)
{
variables_ = ArrayListMultimap.create( );
filename_ = filename;
}
@ -46,11 +42,6 @@ public class WMLConfig
return filename_;
}
public Multimap<String, WMLVariable> getVariables()
{
return variables_;
}
@Override
public String toString()
{

View file

@ -25,16 +25,22 @@ public class WMLVariable
this("", "", 0); //$NON-NLS-1$ //$NON-NLS-2$
}
public WMLVariable(String name, String location, int offset)
public WMLVariable( String name, String location, int offset )
{
name_ = name;
location_ = location;
offset_ = offset;
scopeStartIndex_ = Integer.MAX_VALUE;
scopeEndIndex_ = Integer.MAX_VALUE;
this( name, location, offset, Integer.MAX_VALUE, Integer.MAX_VALUE );
}
public WMLVariable( String name, String location, int offset,
int startIndex, int endIndex )
{
name_ = name;
location_ = location;
offset_ = offset;
scopeStartIndex_ = startIndex;
scopeEndIndex_ = endIndex;
}
public String getName()
{
return name_;