Basically when i am converting an AAR to DLL there is same method name and variable name present in java code.
Means java class is implementing interface runnable, so default method of runnable is run. And also the class contain same name as run of boolean .
I think changing variable name is much more convenient than changing a method name which is implemented by interface.below is java code inside my jar:
public class Tailer
implements Runnable
{
.....
private volatile boolean run = true;
......
......
protected boolean getRun()
{
.....
....
return this.run;
}
public void run()
{
....
....
}
}
I have used following code and it is not working.
<attr path="/api/package[#name='org.apache.commons.io.input']/class[#name='Tailer']/field[#name='run']"
name="propertyName">runvariable</attr>
Related
Should I get the following error:
class.dart:11:11: Error: The getter '_privateID' isn't defined for the class 'Y'.
- 'Y' is from 'class.dart'.
Try correcting the name to the name of an existing getter, or defining a getter or field named '_privateID'.
From the following code?
mixin.dart:
class Mixin {
static int _nextID = 0;
int publicID = _nextID++; // I only need one of these lines
int _privateID = _nextID++; // but this variable is inaccessible
}
class.dart:
import 'mixin.dart';
class X with Mixin {
void run() {
print(publicID); // no error here
}
}
class Y with Mixin {
void run() {
print(_privateID); // Error: _privateID not defined
}
}
void main() {
Y().run();
}
Or is this a bug? If it's not a bug, I'd like to understand why this behavior is reasonable.
When I instead define the mixin in the same file as the above classes, I get no error.
(Dart SDK 2.4.1.)
It is not a bug.
The private field is inherited, but you cannot access it because its name is private to a different library.
Dart's notion of "privacy" is library private names.
The name _privateID in the mixin.dart library introduces a library private name. This name is special in that it can only be written inside the same library.
If someone writes _privateID in a different library, it is a different name, one unique to that library instead.
It is as if private names includes the library URI of the library it is written in, so what you really declare is a name _privateID#mixin.dart.
When you try to read that field in class.dart, you write ._privateID, but because it is in a different library, what you really write is ._privateID#class.dart, a completely different name, and the classs does not have any declarations with that name.
So, if one class needs to access a private member of another class (or mixin, or anything), then the two needs to be declared in the same library, because otherwise they cannot even write the name of that variable.
That is why the code works if you write the mixin in the same library.
If you want to move the mixin to a separate file, but not necessarily a separate library, you can use a part file.
I want to generate an interface with non-default methods. For this purpose I'm using the JvmTypesBuilder.
The code
meth.toMethod(meth.name, meth.returnType)[]
generates for example
public default int meth();
Trying it with
meth.toMethod(meth.name, meth.returnType)[
it.^default = false
]
doesn't change anything.
Setting it abstract works
meth.toMethod(meth.name, meth.returnType)[
it.abstract = true
]
but then I get a method like
public abstract int meth();
what I don't want either.
Is there any way using JvmTypesBuilder and generate a method without default or abstract keywords?
public int meth();
I'm using Eclipse 4.5.1 for DSL Developer
Please make sure that you put the method into an interface and not into a class. E.g. please set the interface flag on the JvmGenericType to true. That should do the trick.
What do you expect to be generated? A method can either have an implementation (default) or not (abstract). In fact, without any modifiers, an interface method is implicitly abstract.
interface MyInterface
{
public abstract void foo();
}
compiles to exactly the same bytecode as
interface MyInterface
{
public void foo();
}
I have a Maven plugin that I am attempting to test using a subclass of the AbstractMojoTestCase. The plugin Mojo defines an outputFolder parameter with a defaultValue. This parameter is not generally expected to be provided by the user in the POM.
#Parameter(defaultValue = "${project.build.directory}/someOutputFolder")
private File outputFolder;
And if I use the plugin in a real scenario then the outputFolder gets defaulted as expected.
But if I test the Mojo using the AbstractMojoTestCase then while parameters defined in the test POM are populated, parameters with a defaultValue that are not defined in the POM are not populated.
public class MyPluginTestCase extends AbstractMojoTestCase {
public void testAssembly() throws Exception {
final File pom = getTestFile( "src/test/resources/test-pom.xml");
assertNotNull(pom);
assertTrue(pom.exists());
final MyMojo myMojo = (BaselineAssemblyMojo) lookupMojo("assemble", pom);
assertNotNull(myMojo);
myMojo.execute(); // Dies due to NullPointerException on outputFolder.
}
}
Further: if I define the outputFolder parameter in the POM like so:
<outputFolder>${project.build.directory}/someOutputFolder</outputFolder>
then ${project.build.directory} is NOT resolved within the AbstractMojoTestCase.
So what do I need to do to get the defaultvalue populated when testing?
Or is this a fault in the AbstractMojoTestCase?
This is Maven-3.2.3, maven-plugin-plugin-3.2, JDK 8
You need to use lookupConfiguredMojo.
Here's what I ended up using:
public class MyPluginTest
{
#Rule
public MojoRule mojoRule = new MojoRule();
#Test
public void noSource() throws Exception
{
// Just give the location, where the pom.xml is located
MyPlugin plugin = (MyPlugin) mojoRule.lookupConfiguredMojo(getResourcesFile("basic-test"), "myGoal");
plugin.execute();
assertThat(plugin.getSomeInformation()).isEmpty();
}
public File getResourcesFile(String filename)
{
return new File("src/test/resources", filename);
}
}
Of course you need to replace myGoal with your plugin's goal. You also need to figure out how to assert that your plugin executed successfully.
For a more complete example, check out the tests I wrote for fmt-maven-plugin
I am following a simple Java EE 6 annotations video on youtube. I have created a repo on github. There is a servlet to start with that creates a greeting string using annotation.
#WebServlet(urlPatterns = {"/HelloServlet"})
public class HelloServlet extends HttpServlet {
#Inject #Formal
String greetingMessage;
...
}
The formal qualifier is defined as follows:
#Qualifier
#Retention(RUNTIME)
#Target({TYPE, METHOD, FIELD, PARAMETER})
public #interface Formal {}
And the producer is:
public class ProduceFormalGreeting {
#Produces
#Formal
public String GetFormalGreeting(){
return "Good morning !";
}
}
At compile time I get the following message from NetBeans:
Unsatisfied Dependency: No bean matches the inject point
At runtime, the string is null in the servlet.
You have to add beans.xml file to WEB-INF. Now You have bean.xml file.
In ProduceFormalGreeting u have to use javax.enterprise.inject.Produces (not javax.ws.rs.Produces)
Lets say I have a class called FooController in which I have a property called Bar of type IBar (interface). I need to initialize Bar via MEF. However I need MEF to create only one instance of IBar type for the duration of the application (despite multiple calls to initialize it due to multiple requests) and make it available to all requests concurrently. Note that IBar implementations can be assumed thread safe.
i.e.
public interface IBar
{
string Method();
}
[Export(typeof(IBar))]
public class MyBar: IBar
{
public string dateTimeCreated;
public MyBar()
{
System.Threading.Thread.Sleep(1000);
dateTimeCreated = DateTime.Now.ToLongTimeString() + " ";
}
public string Method()
{
return dateTimeCreated;
}
}
public class FooController : ApiController
{
[Import(typeof(IBar), RequiredCreationPolicy = CreationPolicy.Shared)]
public IBar Bar { get; set; }
public FooController()
{
//Assume CompositionContainer.ComposeParts call here
}
public string Get()
{
return Bar.Method();
}
}
The problem is each time I call Get() on FooController, the returned time value changes. This means the MyBar object is being reinstantiated for each call. I basically need it to return the same value meaning I need to tell MEF to create only one instance of IBar in my application despite multiple requests.
Thanks in advance.
You need to specify the PartCreationPolicy attribute on your MyBar export. Like this:
[Export(typeof(IBar))]
[PartCreationPolicy(CreationPolicy.Shared)]
public class MyBar : IBar
{
// ...
}
That also means that you don't need to specify the creation policy on your import:
[Import]
public IBar Bar { get; set; }
The ASP.NET MVC integration of MEF interprets CreationPolicy.Any and CreationPolicy.Shared as single instance per HTTP request. You need to apply the ApplicationShared attribute to the part to share it between HTTP requests.
Update:
The ApplicationSharedAttribute can be found in the System.ComponentModel.Composition.Web.Mvc assembly. Unfortunately this is not distributed with Framework 4.5. It can be found at the Using MEF with ASP.NET MVC 3 Sample Code example in the lib folder. The drawback is that you will have to reference the composition assemblies found it that sample and not the latest ones.
If you do not want to do that then start with this very simple approach:
Add a CompositionContainer in your MvcApplication class as a public property.
On the MvcApplication constructor create the container and add some catalogs.
On the controller get the application from the HttpContext and use one of the GetExport/GetExportedValue/GetExportedValues methods of the CompositionContainer. No need to call ComposeParts on the container.
There are a lot of other approaches that are more elaborate but this should get you started.