Home » Modeling » TMF (Xtext) » Exception while loading a xbase resource(Exception while loading a xbase resource)
Exception while loading a xbase resource [message #829522] |
Mon, 26 March 2012 12:00 |
Björn Beyreuther Messages: 7 Registered: March 2012 |
Junior Member |
|
|
Hi,
i tried to make use of the plain xbase implementation, but i have some trouble to load/access a xbase resource.
Basically the code looks like this:
package testxbase.ui;
import java.io.IOException;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.xtext.resource.XtextResourceSet;
import org.eclipse.xtext.util.CancelIndicator;
import org.eclipse.xtext.util.StringInputStream;
import org.eclipse.xtext.xbase.XExpression;
import org.eclipse.xtext.xbase.interpreter.IEvaluationContext;
import org.eclipse.xtext.xbase.interpreter.IEvaluationResult;
import org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter;
import com.google.inject.Inject;
import com.google.inject.Provider;
@SuppressWarnings("restriction")
public class EvaluateAction extends org.eclipse.core.commands.AbstractHandler {
@Inject
private XbaseInterpreter xbaseInterpreter;
@Inject
private Provider<IEvaluationContext> contextProvider;
public Object evaluate(XExpression expression, Object thisElement) {
IEvaluationContext evaluationContext = contextProvider.get();
IEvaluationResult result = xbaseInterpreter.evaluate(expression,
evaluationContext, CancelIndicator.NullImpl);
if (result.getException() != null) {
// handle exception
}
return result.getResult();
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
XtextResourceSet resourceSet = new XtextResourceSet();
Resource resource = resourceSet.createResource(URI
.createURI("Test.xbase"));
try {
resource.load(new StringInputStream("false"), null);
} catch (IOException e) {
e.printStackTrace();
}
EcoreUtil.resolveAll(resource);
XExpression exp = (XExpression) resource.getContents().get(0);
Object temp = evaluate(exp, null);
System.out.println("Result: " + temp);
return null;
}
}
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.xtext.xbase;bundle-version="2.0.0",
com.google.inject;bundle-version="2.0.0",
org.eclipse.emf;bundle-version="2.5.0",
org.eclipse.xtext;bundle-version="2.0.0",
org.eclipse.xtext.xbase.lib;bundle-version="2.0.0";visibility:=reexport,
org.eclipse.ui.ide,
org.eclipse.core.filesystem,
org.eclipse.xtext.xbase.ui;bundle-version="2.2.1",
org.eclipse.xtext.purexbase;bundle-version="2.2.1",
org.eclipse.xtext.purexbase.ui;bundle-version="2.2.1"
The following exception is thrown when the handler is called.
java.lang.IllegalArgumentException: The given class java.lang.SuppressWarnings is not an annotation type.
at org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder.toAnnotation(JvmTypesBuilder.java:467)
at org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder.toAnnotation(JvmTypesBuilder.java:450)
at org.eclipse.xtext.purexbase.jvmmodel.PureXbaseJvmModelInferrer$1.apply(PureXbaseJvmModelInferrer.java:64)
at org.eclipse.xtext.purexbase.jvmmodel.PureXbaseJvmModelInferrer$1.apply(PureXbaseJvmModelInferrer.java:1)
at org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder.toClass(JvmTypesBuilder.java:170)
at org.eclipse.xtext.purexbase.jvmmodel.PureXbaseJvmModelInferrer._infer(PureXbaseJvmModelInferrer.java:146)
at org.eclipse.xtext.purexbase.jvmmodel.PureXbaseJvmModelInferrer.infer(PureXbaseJvmModelInferrer.java:185)
at org.eclipse.xtext.xbase.jvmmodel.JvmModelAssociator.installDerivedState(JvmModelAssociator.java:203)
at org.eclipse.xtext.resource.DerivedStateAwareResource.installDerivedState(DerivedStateAwareResource.java:125)
at org.eclipse.xtext.resource.DerivedStateAwareResource.getContents(DerivedStateAwareResource.java:48)
at org.eclipse.emf.ecore.util.EcoreUtil.resolveAll(EcoreUtil.java:285)
at testxbase.ui.EvaluateAction.execute(EvaluateAction.java:53)
at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:293)
at org.eclipse.core.commands.Command.executeWithChecks(Command.java:476)
at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:508)
at org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:169)
at org.eclipse.ui.internal.handlers.SlaveHandlerService.executeCommand(SlaveHandlerService.java:241)
at org.eclipse.ui.menus.CommandContributionItem.handleWidgetSelection(CommandContributionItem.java:829)
at org.eclipse.ui.menus.CommandContributionItem.access$19(CommandContributionItem.java:815)
at org.eclipse.ui.menus.CommandContributionItem$5.handleEvent(CommandContributionItem.java:805)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4165)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3754)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2696)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2660)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2494)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:674)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:667)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at testxbase.Application.start(Application.java:20)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
Basically the model is loaded but if it is accessed it tries to resolve "java.lang.SuppressWarnings". Has anyone an idea how to solve this?
Cheers, Björn
[Updated on: Mon, 26 March 2012 12:01] Report message to a moderator
|
|
|
Re: Exception while loading a xbase resource [message #834254 is a reply to message #829522] |
Sun, 01 April 2012 17:16 |
Sebastian Zarnekow Messages: 3118 Registered: July 2009 |
Senior Member |
|
|
Hi Björn,
you should use the XtextResourceSetProvider to obtain a working
XtextResourceSet.
Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Am 26.03.12 14:01, schrieb Björn Beyreuther:
> Hi,
> i tried to make use of the plain xbase implementation, but i have some
> trouble to load/access a xbase resource.
>
> Basically the text code looks like this:
>
>
> package testxbase.ui;
>
> import java.io.IOException;
>
> import org.eclipse.core.commands.ExecutionEvent;
> import org.eclipse.core.commands.ExecutionException;
> import org.eclipse.emf.common.util.URI;
> import org.eclipse.emf.ecore.resource.Resource;
> import org.eclipse.emf.ecore.util.EcoreUtil;
> import org.eclipse.xtext.resource.XtextResourceSet;
> import org.eclipse.xtext.util.CancelIndicator;
> import org.eclipse.xtext.util.StringInputStream;
> import org.eclipse.xtext.xbase.XExpression;
> import org.eclipse.xtext.xbase.interpreter.IEvaluationContext;
> import org.eclipse.xtext.xbase.interpreter.IEvaluationResult;
> import org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter;
>
> import com.google.inject.Inject;
> import com.google.inject.Provider;
>
> @SuppressWarnings("restriction")
> public class EvaluateAction extends
> org.eclipse.core.commands.AbstractHandler {
>
> @Inject
> private XbaseInterpreter xbaseInterpreter;
>
> @Inject
> private Provider<IEvaluationContext> contextProvider;
>
> public Object evaluate(XExpression expression, Object thisElement) {
> IEvaluationContext evaluationContext = contextProvider.get();
> IEvaluationResult result = xbaseInterpreter.evaluate(expression,
> evaluationContext, CancelIndicator.NullImpl);
> if (result.getException() != null) {
> // handle exception
> }
> return result.getResult();
> }
>
> @Override
> public Object execute(ExecutionEvent event) throws ExecutionException {
>
> XtextResourceSet resourceSet = new XtextResourceSet();
> Resource resource = resourceSet.createResource(URI
> .createURI("Test.xbase"));
>
> try {
> resource.load(new StringInputStream("false"), null);
> } catch (IOException e) {
> e.printStackTrace();
> }
>
> EcoreUtil.resolveAll(resource);
>
> XExpression exp = (XExpression) resource.getContents().get(0);
> Object temp = evaluate(exp, null);
>
> System.out.println("Result: " + temp);
>
> return null;
> }
> }
>
>
> Require-Bundle: org.eclipse.ui,
> org.eclipse.core.runtime,
> org.eclipse.xtext.xbase;bundle-version="2.0.0",
> com.google.inject;bundle-version="2.0.0",
> org.eclipse.emf;bundle-version="2.5.0",
> org.eclipse.xtext;bundle-version="2.0.0",
> org.eclipse.xtext.xbase.lib;bundle-version="2.0.0";visibility:=reexport,
> org.eclipse.ui.ide,
> org.eclipse.core.filesystem,
> org.eclipse.xtext.xbase.ui;bundle-version="2.2.1",
> org.eclipse.xtext.purexbase;bundle-version="2.2.1",
> org.eclipse.xtext.purexbase.ui;bundle-version="2.2.1"
>
>
> The following exception is thrown when the handler is called.
>
>
> java.lang.IllegalArgumentException: The given class
> java.lang.SuppressWarnings is not an annotation type.
> at
> org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder.toAnnotation(JvmTypesBuilder.java:467)
>
> at
> org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder.toAnnotation(JvmTypesBuilder.java:450)
>
> at
> org.eclipse.xtext.purexbase.jvmmodel.PureXbaseJvmModelInferrer$1.apply(PureXbaseJvmModelInferrer.java:64)
>
> at
> org.eclipse.xtext.purexbase.jvmmodel.PureXbaseJvmModelInferrer$1.apply(PureXbaseJvmModelInferrer.java:1)
>
> at
> org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder.toClass(JvmTypesBuilder.java:170)
>
> at
> org.eclipse.xtext.purexbase.jvmmodel.PureXbaseJvmModelInferrer._infer(PureXbaseJvmModelInferrer.java:146)
>
> at
> org.eclipse.xtext.purexbase.jvmmodel.PureXbaseJvmModelInferrer.infer(PureXbaseJvmModelInferrer.java:185)
>
> at
> org.eclipse.xtext.xbase.jvmmodel.JvmModelAssociator.installDerivedState(JvmModelAssociator.java:203)
>
> at
> org.eclipse.xtext.resource.DerivedStateAwareResource.installDerivedState(DerivedStateAwareResource.java:125)
>
> at
> org.eclipse.xtext.resource.DerivedStateAwareResource.getContents(DerivedStateAwareResource.java:48)
>
> at org.eclipse.emf.ecore.util.EcoreUtil.resolveAll(EcoreUtil.java:285)
> at testxbase.ui.EvaluateAction.execute(EvaluateAction.java:53)
> at
> org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:293)
>
> at org.eclipse.core.commands.Command.executeWithChecks(Command.java:476)
> at
> org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:508)
>
> at
> org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:169)
>
> at
> org.eclipse.ui.internal.handlers.SlaveHandlerService.executeCommand(SlaveHandlerService.java:241)
>
> at
> org.eclipse.ui.menus.CommandContributionItem.handleWidgetSelection(CommandContributionItem.java:829)
>
> at
> org.eclipse.ui.menus.CommandContributionItem.access$19(CommandContributionItem.java:815)
>
> at
> org.eclipse.ui.menus.CommandContributionItem$5.handleEvent(CommandContributionItem.java:805)
>
> at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
> at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
> at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4165)
> at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3754)
> at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2696)
> at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2660)
> at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2494)
> at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:674)
> at
> org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
>
> at
> org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:667)
> at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
> at testxbase.Application.start(Application.java:20)
> at
> org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
>
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
>
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
>
> at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
>
> at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
>
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> at java.lang.reflect.Method.invoke(Unknown Source)
> at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
> at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
> at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
> at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
>
>
>
> Basically the model is loaded but if it is accessed it tries to resolve
> "java.lang.SuppressWarnings". Has anyone an idea how to solve this?
>
> Cheers, Björn
|
|
|
Goto Forum:
Current Time: Mon May 13 09:57:10 GMT 2024
Powered by FUDForum. Page generated in 0.02915 seconds
|