mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-05 19:50:33 +00:00
eclipse plugin: Refactor the IFile to WMLRoot...
...conversion to its own method
This commit is contained in:
parent
d3750307b3
commit
77b3e42c12
@ -26,10 +26,13 @@ Require-Bundle: org.eclipse.xtext,
|
|||||||
Import-Package: org.apache.log4j
|
Import-Package: org.apache.log4j
|
||||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
|
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
|
||||||
Export-Package: org.wesnoth,
|
Export-Package: org.wesnoth,
|
||||||
org.wesnoth.services,
|
org.wesnoth.formatting,
|
||||||
org.wesnoth.parseTreeConstruction,
|
org.wesnoth.parseTreeConstruction,
|
||||||
org.wesnoth.parser.antlr,
|
org.wesnoth.parser.antlr,
|
||||||
org.wesnoth.parser.antlr.internal,
|
org.wesnoth.parser.antlr.internal,
|
||||||
|
org.wesnoth.scoping,
|
||||||
|
org.wesnoth.services,
|
||||||
|
org.wesnoth.tests,
|
||||||
org.wesnoth.validation,
|
org.wesnoth.validation,
|
||||||
org.wesnoth.wml,
|
org.wesnoth.wml,
|
||||||
org.wesnoth.wml.impl,
|
org.wesnoth.wml.impl,
|
||||||
|
@ -57,3 +57,6 @@ Export-Package: org.wesnoth,
|
|||||||
org.wesnoth.wml.core,
|
org.wesnoth.wml.core,
|
||||||
org.wesnoth.wml.schema,
|
org.wesnoth.wml.schema,
|
||||||
org.wesnoth.wml.schema.impl
|
org.wesnoth.wml.schema.impl
|
||||||
|
Import-Package: org.wesnoth.wml,
|
||||||
|
org.wesnoth.wml.impl,
|
||||||
|
org.wesnoth.wml.util
|
||||||
|
@ -24,6 +24,8 @@ import org.eclipse.core.runtime.CoreException;
|
|||||||
import org.wesnoth.Logger;
|
import org.wesnoth.Logger;
|
||||||
import org.wesnoth.builder.WesnothProjectBuilder.WMLFilesComparator;
|
import org.wesnoth.builder.WesnothProjectBuilder.WMLFilesComparator;
|
||||||
import org.wesnoth.projects.ProjectDependencyNode;
|
import org.wesnoth.projects.ProjectDependencyNode;
|
||||||
|
import org.wesnoth.utils.ResourceUtils;
|
||||||
|
import org.wesnoth.wml.WMLRoot;
|
||||||
|
|
||||||
public class DependencyTreeBuilder
|
public class DependencyTreeBuilder
|
||||||
{
|
{
|
||||||
@ -53,9 +55,9 @@ public class DependencyTreeBuilder
|
|||||||
IResource main_cfg = container.findMember( "_main.cfg" );
|
IResource main_cfg = container.findMember( "_main.cfg" );
|
||||||
if ( main_cfg != null ) {
|
if ( main_cfg != null ) {
|
||||||
// add main.cfg to tree
|
// add main.cfg to tree
|
||||||
|
WMLRoot root = ResourceUtils.getWMLRoot( ( IFile ) main_cfg );
|
||||||
|
|
||||||
//TODO process the other children depending on the contents
|
// iterate to find macro calls that include other dirs
|
||||||
// of the file
|
|
||||||
}else {
|
}else {
|
||||||
List<IResource> members = null;
|
List<IResource> members = null;
|
||||||
try {
|
try {
|
||||||
|
@ -12,11 +12,7 @@ import org.eclipse.core.commands.AbstractHandler;
|
|||||||
import org.eclipse.core.commands.ExecutionEvent;
|
import org.eclipse.core.commands.ExecutionEvent;
|
||||||
import org.eclipse.core.commands.ExecutionException;
|
import org.eclipse.core.commands.ExecutionException;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.emf.common.util.URI;
|
import org.wesnoth.utils.ResourceUtils;
|
||||||
import org.eclipse.emf.ecore.EObject;
|
|
||||||
import org.eclipse.emf.ecore.resource.Resource;
|
|
||||||
import org.eclipse.emf.ecore.resource.ResourceSet;
|
|
||||||
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
|
|
||||||
import org.wesnoth.utils.WorkspaceUtils;
|
import org.wesnoth.utils.WorkspaceUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -29,11 +25,7 @@ public class TestHandler extends AbstractHandler
|
|||||||
public Object execute(ExecutionEvent event) throws ExecutionException
|
public Object execute(ExecutionEvent event) throws ExecutionException
|
||||||
{
|
{
|
||||||
IFile file = WorkspaceUtils.getSelectedFile( );
|
IFile file = WorkspaceUtils.getSelectedFile( );
|
||||||
URI uri = URI.createPlatformResourceURI( file.getFullPath( ).toString( ), true );
|
System.out.println( ResourceUtils.getWMLRoot( file ));
|
||||||
ResourceSet resSet = new ResourceSetImpl( );
|
|
||||||
Resource res = resSet.getResource( uri, true );
|
|
||||||
EObject obj = res.getContents( ).get( 0 );
|
|
||||||
System.out.println( obj);
|
|
||||||
|
|
||||||
// IFile file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new Path("E:\\work\\java\\runtime-EclipseApplication\\A_Simple_Campaign\\scenarios\\atemplate.cfg"));
|
// IFile file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new Path("E:\\work\\java\\runtime-EclipseApplication\\A_Simple_Campaign\\scenarios\\atemplate.cfg"));
|
||||||
// try
|
// try
|
||||||
|
@ -34,6 +34,11 @@ import org.eclipse.core.runtime.CoreException;
|
|||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
|
import org.eclipse.emf.common.util.URI;
|
||||||
|
import org.eclipse.emf.ecore.EObject;
|
||||||
|
import org.eclipse.emf.ecore.resource.Resource;
|
||||||
|
import org.eclipse.emf.ecore.resource.ResourceSet;
|
||||||
|
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
|
||||||
import org.eclipse.jface.dialogs.DialogSettings;
|
import org.eclipse.jface.dialogs.DialogSettings;
|
||||||
import org.eclipse.swt.SWT;
|
import org.eclipse.swt.SWT;
|
||||||
import org.wesnoth.Constants;
|
import org.wesnoth.Constants;
|
||||||
@ -43,6 +48,7 @@ import org.wesnoth.preprocessor.PreprocessorUtils;
|
|||||||
import org.wesnoth.projects.ProjectUtils;
|
import org.wesnoth.projects.ProjectUtils;
|
||||||
import org.wesnoth.templates.ReplaceableParameter;
|
import org.wesnoth.templates.ReplaceableParameter;
|
||||||
import org.wesnoth.templates.TemplateProvider;
|
import org.wesnoth.templates.TemplateProvider;
|
||||||
|
import org.wesnoth.wml.WMLRoot;
|
||||||
import org.xml.sax.InputSource;
|
import org.xml.sax.InputSource;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
import org.xml.sax.helpers.DefaultHandler;
|
import org.xml.sax.helpers.DefaultHandler;
|
||||||
@ -476,4 +482,26 @@ public class ResourceUtils
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the WML Grammar root of the specified file
|
||||||
|
* @param file The file to get the WML model from
|
||||||
|
* @return A WMLRoot instance or null if there is none
|
||||||
|
*/
|
||||||
|
public static WMLRoot getWMLRoot( IFile file )
|
||||||
|
{
|
||||||
|
URI uri = URI.createPlatformResourceURI( file.getFullPath( ).toString( ), true );
|
||||||
|
ResourceSet resourceSet = new ResourceSetImpl( );
|
||||||
|
Resource resource = resourceSet.getResource( uri, true );
|
||||||
|
if ( resource == null ||
|
||||||
|
resource.getContents( ).isEmpty( ) )
|
||||||
|
return null;
|
||||||
|
|
||||||
|
EObject result = resource.getContents( ).get( 0 );
|
||||||
|
|
||||||
|
if ( result instanceof WMLRoot == false )
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return ( WMLRoot ) result;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user