eclipse plugin: Implement the adding of new found variables

This commit is contained in:
Timotei Dolean 2011-07-26 15:27:38 +00:00
parent 0215dd54e7
commit 84c2a50213
4 changed files with 67 additions and 1 deletions

View file

@ -39,7 +39,7 @@ public class DependencyListNode implements Serializable
*/
public static final int INDEX_STEP = 100000;
protected static final QualifiedName PDL_INDEX = new QualifiedName( Constants.PLUGIN_ID, "pdl_index" ); //$NON-NLS-1$
public static final QualifiedName PDL_INDEX = new QualifiedName( Constants.PLUGIN_ID, "pdl_index" ); //$NON-NLS-1$
private DependencyListNode previous_;
private DependencyListNode next_;

View file

@ -51,6 +51,7 @@ import org.eclipse.swt.SWT;
import org.wesnoth.Constants;
import org.wesnoth.Logger;
import org.wesnoth.Messages;
import org.wesnoth.builder.DependencyListNode;
import org.wesnoth.preprocessor.PreprocessorUtils;
import org.wesnoth.projects.ProjectUtils;
import org.wesnoth.templates.ReplaceableParameter;
@ -609,6 +610,26 @@ public class ResourceUtils
return containersToAdd;
}
/**
* Gets the associated dependency index for the specified file
* @param file The file to get the index for
* @return An index or {@link Integer.MAX_VALUE}
*/
public static int getDependencyIndex( IFile file )
{
int index = Integer.MAX_VALUE;
try {
index = Integer.parseInt( file.getPersistentProperty( DependencyListNode.PDL_INDEX ) );
}
catch ( CoreException e ) {
// not interested
}
catch (NumberFormatException e) {
// not interested
}
return index;
}
/**
* This is a WML files comparator, based on the WML parsing rules.

View file

@ -11,6 +11,8 @@ package org.wesnoth.wml.core;
import org.eclipse.core.resources.IFile;
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.utils.ResourceUtils;
import org.wesnoth.utils.WMLUtils;
import org.wesnoth.wml.WMLKey;
@ -51,6 +53,9 @@ 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;
@ -101,7 +106,25 @@ public class SimpleWMLParser
protected void handleSetVariable( EObject context )
{
WMLVariable variable = new WMLVariable( );
ICompositeNode node = NodeModelUtils.getNode( context ) ;
variable.setLocation( file_.getLocation( ).toOSString( ) );
variable.setScopeStartIndex( ResourceUtils.getDependencyIndex( file_ ) );
variable.setOffset( node.getTotalOffset( ) );
if ( context instanceof WMLKey ) {
variable.setName( WMLUtils.getKeyValue( ( ( WMLKey ) context ).getValue( ) ) );
} else if ( context instanceof WMLMacroCall ) {
WMLMacroCall macro = ( WMLMacroCall ) context;
if ( macro.getParameters( ).size( ) > 0 ) {
variable.setName( WMLUtils.toString( macro.getParameters( ).get( 0 ) ) );
}
}
if ( ! variable.getName( ).isEmpty( ) ) {
config_.getVariables( ).put( variable.getName( ), variable );
}
}
protected void handleUnsetVariable( EObject context )

View file

@ -17,6 +17,8 @@ public class WMLVariable
private String location_;
private int offset_;
private boolean isArray_;
private int scopeStartIndex_;
private int scopeEndIndex_;
public WMLVariable()
{
@ -28,6 +30,9 @@ public class WMLVariable
name_ = name;
location_ = location;
offset_ = offset;
scopeStartIndex_ = Integer.MAX_VALUE;
scopeEndIndex_ = Integer.MAX_VALUE;
}
public String getName()
@ -62,4 +67,21 @@ public class WMLVariable
{
isArray_ = isArray;
}
public int getScopeEndIndex()
{
return scopeEndIndex_;
}
public int getScopeStartIndex()
{
return scopeStartIndex_;
}
public void setScopeEndIndex( int scopeEndIndex )
{
scopeEndIndex_ = scopeEndIndex;
}
public void setScopeStartIndex( int scopeStartIndex )
{
scopeStartIndex_ = scopeStartIndex;
}
}