eclipse plugin: Refactor a bit the SimpleWMLParser...
...to make it more concrete on what it can do
This commit is contained in:
parent
43f91931b7
commit
b50f805750
3 changed files with 39 additions and 33 deletions
|
@ -310,8 +310,8 @@ public class WesnothProjectBuilder extends IncrementalProjectBuilder
|
|||
monitor.subTask( String.format( Messages.WesnothProjectBuilder_22, filePath ) );
|
||||
|
||||
WMLConfig config = projectCache_.getWMLConfig( filePath );
|
||||
SimpleWMLParser parser = new SimpleWMLParser( file, config );
|
||||
parser.parse( false );
|
||||
SimpleWMLParser parser = new SimpleWMLParser( file, config, projectCache_ );
|
||||
parser.parse( );
|
||||
|
||||
monitor.worked(10);
|
||||
|
||||
|
|
|
@ -409,7 +409,7 @@ public class ResourceUtils
|
|||
public static String getCampaignID(IResource resource)
|
||||
{
|
||||
SimpleWMLParser parser = new SimpleWMLParser( getMainConfigLocation( resource ) );
|
||||
parser.parse( true );
|
||||
parser.parse( );
|
||||
return parser.getParsedConfig( ).CampaignId;
|
||||
}
|
||||
|
||||
|
@ -421,7 +421,7 @@ public class ResourceUtils
|
|||
public static String getScenarioID(IFile file)
|
||||
{
|
||||
SimpleWMLParser parser = new SimpleWMLParser( file );
|
||||
parser.parse( true );
|
||||
parser.parse( );
|
||||
return parser.getParsedConfig( ).ScenarioId;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,10 +14,10 @@ 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.projects.ProjectUtils;
|
||||
import org.wesnoth.utils.ResourceUtils;
|
||||
import org.wesnoth.utils.WMLUtils;
|
||||
import org.wesnoth.wml.WMLKey;
|
||||
import org.wesnoth.wml.WMLLuaCode;
|
||||
import org.wesnoth.wml.WMLMacroCall;
|
||||
import org.wesnoth.wml.WMLRoot;
|
||||
import org.wesnoth.wml.WMLTag;
|
||||
|
@ -37,30 +37,35 @@ public class SimpleWMLParser
|
|||
|
||||
/**
|
||||
* Creates a new parser for the specified file
|
||||
*
|
||||
* @param file The file which to parse
|
||||
*/
|
||||
public SimpleWMLParser( IFile file )
|
||||
{
|
||||
this( file, new WMLConfig( file.getProjectRelativePath( ).toString( ) ) );
|
||||
this( file, new WMLConfig( file.getProjectRelativePath( ).toString( ) ), null );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new parser and fills the specified config file
|
||||
*
|
||||
* @param file The file which to parse
|
||||
* @param config The config to fill
|
||||
* @param projCache The project cache (can be null) on which to reflect
|
||||
* the parsed data
|
||||
*/
|
||||
public SimpleWMLParser( IFile file, WMLConfig config )
|
||||
public SimpleWMLParser( IFile file, WMLConfig config, ProjectCache projCache )
|
||||
{
|
||||
config_ = Preconditions.checkNotNull( config );
|
||||
file_ = file;
|
||||
projectCache_ = ProjectUtils.getCacheForProject( file.getProject( ) );
|
||||
projectCache_ = projCache;
|
||||
|
||||
dependencyIndex_ = ResourceUtils.getDependencyIndex( file );
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the config. The results will be available in {@link #getParsedConfig()}
|
||||
* @param configOnly If true, the parsing won't modify anything external
|
||||
* to the config object (like adding the variables to the project cache)
|
||||
* Parses the config. The resulted config will be available in {@link #getParsedConfig()}
|
||||
*/
|
||||
public void parse( boolean configOnly )
|
||||
public void parse( )
|
||||
{
|
||||
WMLRoot root = ResourceUtils.getWMLRoot( file_ );
|
||||
TreeIterator<EObject> itor = root.eAllContents( );
|
||||
|
@ -89,34 +94,29 @@ public class SimpleWMLParser
|
|||
config_.ScenarioId = WMLUtils.getKeyValue( key.getValue( ) );
|
||||
else if ( currentTagName.equals( "campaign" ) )
|
||||
config_.CampaignId = WMLUtils.getKeyValue( key.getValue( ) );
|
||||
}
|
||||
|
||||
// now follows just things that modify project/file's related info
|
||||
if ( configOnly == false ) {
|
||||
if ( keyName.equals( "name" ) ) {
|
||||
if ( currentTagName.equals( "set_variable" ) ||
|
||||
currentTagName.equals( "set_variables" ) ) {
|
||||
handleSetVariable( object );
|
||||
} else if ( currentTagName.equals( "clear_variable" ) ||
|
||||
currentTagName.equals( "clear_variables" ) ) {
|
||||
handleUnsetVariable( object );
|
||||
}
|
||||
} else if ( keyName.equals( "name" ) ) {
|
||||
if ( currentTagName.equals( "set_variable" ) ||
|
||||
currentTagName.equals( "set_variables" ) ) {
|
||||
handleSetVariable( object );
|
||||
} else if ( currentTagName.equals( "clear_variable" ) ||
|
||||
currentTagName.equals( "clear_variables" ) ) {
|
||||
handleUnsetVariable( object );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( object instanceof WMLMacroCall ) {
|
||||
|
||||
if ( configOnly == false ) {
|
||||
WMLMacroCall macroCall = ( WMLMacroCall ) object;
|
||||
String macroCallName = macroCall.getName( );
|
||||
if ( macroCallName.equals( "VARIABLE" ) ) {
|
||||
handleSetVariable( object );
|
||||
} else if ( macroCallName.equals( "CLEAR_VARIABLE" ) ) {
|
||||
handleUnsetVariable( object );
|
||||
}
|
||||
WMLMacroCall macroCall = ( WMLMacroCall ) object;
|
||||
String macroCallName = macroCall.getName( );
|
||||
if ( macroCallName.equals( "VARIABLE" ) ) {
|
||||
handleSetVariable( object );
|
||||
} else if ( macroCallName.equals( "CLEAR_VARIABLE" ) ) {
|
||||
handleUnsetVariable( object );
|
||||
}
|
||||
}
|
||||
else if ( object instanceof WMLLuaCode ) {
|
||||
|
||||
}
|
||||
}
|
||||
//TODO: parse custom events
|
||||
|
||||
|
@ -142,6 +142,9 @@ public class SimpleWMLParser
|
|||
|
||||
protected void handleSetVariable( EObject context )
|
||||
{
|
||||
if ( projectCache_ == null )
|
||||
return;
|
||||
|
||||
String variableName = getVariableNameByContext( context );
|
||||
|
||||
if ( variableName == null ) {
|
||||
|
@ -168,6 +171,9 @@ public class SimpleWMLParser
|
|||
|
||||
protected void handleUnsetVariable( EObject context )
|
||||
{
|
||||
if ( projectCache_ == null )
|
||||
return;
|
||||
|
||||
String variableName = getVariableNameByContext( context );
|
||||
if ( variableName == null ) {
|
||||
Logger.getInstance( ).logWarn(
|
||||
|
|
Loading…
Add table
Reference in a new issue