I'm trying to use the class Pair from GWT:
com.google.gwt.dev.util.Pair
But I get the following error:
[ERROR] Line 126: No source code is available for type com.google.gwt.dev.util.Pair<L,R>; did you forget to inherit a required module?
In MyModule.gwt.xml I inherit the module com.google.gwt.user.User:
<inherits name="com.google.gwt.user.User" />
Which module do I need in order to use that class?
Code under the package com.google.gwt.dev only runs in the JVM.
If you want to reuse Pair, you have to copy it to a client side or shared namespace. But in this case you have to use different imports.
If you want to reuse it with the same namespace, you have to create your own .gwt.xml file that includes the com.google.gwt.dev namespace, but it is not an easy task since you might need a lot of exceptions in order to avoid other classes in this namespace using any kind of java code making gwt compiler fail.
Related
is it possible to use com.google.gwt.core.ext.typeinfo.TypeOracle within my code? I need this class to get an array of all subtypes of a specified class at runtime. Which module I have to inherit?
I get two errors during GWT compile:
[ERROR] Line 74: No source code is available for type com.google.gwt.core.ext.typeinfo.TypeOracle; did you forget to inherit a required module?
[ERROR] Line 75: No source code is available for type com.google.gwt.core.ext.typeinfo.JClassType; did you forget to inherit a required module?
What could be wrong?
Thank you
Andre
No, you cannot use it at runtime.
TypeOracle is used to infer type infos about classes used at compile-time. GWT generators often use TypeOracle as a source of such informations.
You may want to change your perspective and build a generator that infer all subtypes of a given annotated class, or use a library that allow you to use client-side reflection (never used, but they exists and, in the end they simply use the same idea: generators/deferred binding mechanism).
I'm a relative newbie to SystemVerilog.
I have a package with class A defined in it. This class uses a virtual interface, since
it's a driver (BFM) in a testbench. I'm using a package so I can use the same BFM in
other designs.
In my testbench, I import the A class and pass to it an instance of the virtual interface.
However, when a task in the class tries to assign a value to a signal in the interface, I'm getting a compilation error.
What am I doing wrong?
How can one package a BFM with a virtual interface?
Thanks,
Ran
SystemVerilog packages cannot include interfaces within the actual package. So your interface needs to be compiled along with you package source. The classes you define will reside in the package while the interface definition resides in the global scope where modules live.
Classes within packages can make references to virtual interfaces, but you need to make sure the interface is compiled and visible, apart from the package source.
Strictly according to the spec, I don't think this is possible since it adds an implicit external dependency:
Items within packages are generally type definitions, tasks, and
functions. Items within packages shall not have hierarchical
references to identifiers except those created within the package or
made visible by import of another package. A package shall not refer
to items defined in the compilation unit scope.
It doesn't say anything about the design element namespace, which is where interface declarations live, but accessing any member of an interface requires a hierarchical reference.
You should consider packages to be completely self-contained, other than pre-processor directives and import.
Generally the class declaration not present before its usage is resolved with the help of systemverilog typedef definition. For example "Class A uses Class B" and "Class B uses class A" then typedef is used to resolve the stalemate.
Now when you bring in the package with the above scenario then one needs to ensure both Class A and Class B have to be in same package. If they are not then the compile wont go through.
The reason being the SystemVerilog parser will need the definition of the classes indicated with the typedef at the end of the package parsing. This fails.
This issue needs to watched out that "typedef does not apply across package".
How can I get GWT to provide the same dependency insights as mvn dependency:analyze?
Maven can report about dependencies (Used undeclared dependencies and Unused declared dependencies). I'd like to get GWT to do the same because determining missing inherits in my gwt.xml proves difficult.
Is there a good way for the system to analyze dependency state?
Thanks
Peter
I'm not aware of any such tool, and while I think a utility to analyze and report on GWT dependencies could be interesting, I also think it would be difficult to define well.
Used, undeclared dependencies
Before trying to solve this, what is the problem? In maven, this category means that a Class is loaded from a dependency that isn't directly depended on, but instead is transitively loaded. This starts to get into the whole issue of transitive dependencies (which exist in GWT) and scopes (which don't). If A uses a class in C, but only depends on B, which depends on C, this will be listed in the 'used, undeclared dependencies' list.
In GWT however, we very rarely list every single dependency we use directly. Instead, we assume that transitive dependencies will stay transitive - we dont bother to inherit com.google.gwt.user.RemoteService for RPC as long as we already have com.google.gwt.user.User listed.
So how could we tell if we are using an undeclared dependency, the kind that warns when we do a gwt:compile? Perhaps such a tool could find every .gwt.xml file on the classpath, and read through its <source> and <super-source> rules to look for somewhere that a class we are using is declared? Or in the case of invoking GWT.create on something and getting back a non-concrete type, it could look for <replace-with> and <generate-with> rules. As long as your code already compiles in Java, the classes are on the classpath, but you still run the risk that while the class is there, the .java or .gwt.xml files might not be.
Unused, declared dependencies
This seems like an easier problem - analyze the modules we are inheriting, and look through them for any module that could be pruned out. Unfortunately, as the above discussion notes, we can't just look for the classes and which package they are in, which <source> and <super-source> elements are unused - we also would need to look for <replace-with> and <generate-with> rules - consider something like com.google.gwt.user.RemoteService, which only adds a rule and some configuration details, or even com.google.gwt.user.RemoteServiceObfuscateTypeNames, which modifies only a single setting of the RemoteService module. If RemoteServiceObfuscateTypeNames were removed, everything would still compile, but now there might be information about your RPC classes compiled into your app that you don't expect to be there.
With these in mind, perhaps such a tool could watch all possible rebind rules in the current build, and all configuration settings, properties, etc, and see if any of those rules were not using during a gwt:compile process. Then, indicate which modules had unused parts, and if any module (and all of its inherited modules) were unused, it could shown to the user as able to be removed.
One more important piece: order matters, when defining <inherits> statements. If I add a inherits for com.google.gwt.logging.Logging, then follow it with com.google.gwt.logging.LoggingDisabled, logging classes will be on the source path and will compile, but will have no effect. But if those are ordered the other way around, then they will not only be on the source path, but will all be functional. So any analysis of modules used and unused would need to also include transitive inherits statements, and their orders.
I want to build a simple 'rake' style command line tool that will allow me to define tasks in scala (that can optionally take additional command line arguments) that will be automatically loaded and accessible through a single main() method, to provide a single point of entry and minimize generating lots of wrapper scripts.
An example of what I'm looking for is Jersey, which will automatically load all annotated classes in a specified package and create REST endpoints. What's the right way to do this in scala? Basically, I just want to end up with a collection of instances of every class in a
package with a given annotation (which all have a Task trait or are a subclass of Trait, etc.)
I am new to GWT. i have below line of code.
SomeClientServiceAsync someService = GWT.create(SomeClientService.class);
what does above line means and why cannot i use any other alternatives to instantiate it?
Please help me!
Thanks.
GWT.create is used for deferred binding. This allows you to supply different implementations of the same service based on the user's browser. See the following question:
Why use GWT.create() instead of new?
If you do not need to have multiple implementations of your service, just create it via new!
GWT works by creating a service just like RMI does. Here you are creating the service SomeClientService which resides in the client package. It contains all the functions that can be called server-side.
GWT.create works in different ways:
It tries to see if in the gwt.xml files there is no declaration of which implementation to use depending on a GWT property. This GWT property can be the well known user agent which in this case will have the effect of selecting different implementations for each browser, but it can also be used for other things, for example to disable logging (the fact that logging is enabled or not has nothing to do with in which browser it runs)
Example:
<replace-with class="com.x.app.client.ui.base.button.CustomSlicedButtonCellAppearance">
<when-type-is class="com.x.app.client.ui.base.button.CustomButtonCellAppearance" />
<when-property-is name="gxt.css3.enabled" value="false"/>
<when-property-is name="gxt.theme" value="themeName" />
</replace-with>
In this case it will use CustomSlicedButtonCellAppearance for a call to GWT.create(CustomButtonCellAppearance.class) only if css3 is not supported and for the given theme. Notice that "when-property-is" is optional, and if not supplied it will always use that implementation for the given interface.
It also looks for generators, in which case a new class is generated during GWT compilation (or in devmode) usually based on annotation that are present in the interface passed to the create method.
Example:
<generate-with class="org.fusesource.restygwt.rebind.RestServiceGenerator">
<when-type-assignable class="org.fusesource.restygwt.client.RestService" />
</generate-with>
In this case the RestServiceGenerator will generate code to submit the request.
Another example is how UIBinder works: besides using the annotations in the interface it also generates code based on what is inside the ui.xml file.
If no declaration matches the class/interface passed to the GWT.create method, then it will try to do a new on that class (in case of an interface it will fail).
Declarations in gwt.xml files can be overwritten by other declarations that are processed afterwards, so if you are using a module which declares a rule you can change that rule by declaring a new rule after the inherits declaration of the module containing the original declaration.