I'm trying to use Eclipse templates (in Juno) to generate statements for both regular and static imports and ran into something odd.
After consulting the docs my first attempt was this
${:import(org.junit.Test)} //ok
${:importStatic('org.junit.Assert.*')} //gives error
:import works fine, but :importStatic gives this error
Template variable '' has incompatible types
But the syntax above is exactly how it's presented in the docs, where :importStatic is identical to :import in the left-hand column.
I noticed the example in the right-hand column, which uses a namespace is in front of :importStatic
${is:importStatic(...
So I added that namespace, the error went away, and the template works
However I'm a little bugged by this magical unexplained is namespace - I can't find any explanation in the docs of where it comes from. In fact, playing around a little it seems there's nothing special about is at all - turns out any namespace in front of :importStatic will work.
${donkey:importStatic(... //works fine...
So, does anyone know why a namespace is necessary for :importStatic but not :import?
Is the error and the fact it won't save without a namespace just a bug in the template editor or am I missing something?
This is not a namespace, it is an id for the variable used in the template - except that import and importStatic should not need a variable.
I believe what you are see is Eclipse bug 336989 where leaving out the id on two statements causes this problem. As you have found the workaround is to specify an id even though it is not required.
Related
I am trying java binding to a Xamarin forms project and the jar contains class name having $ and also variable names with $. I am getting "Unexpected Character $" error. I am trying to solve it by editing the metadata.xml file. It seems that I am doing it wrong, please check the following entries,
For the class names containing $. I am using,
<attr path="/api/package[#name='com.wed.therace']/class[#name='CarDetails$']"
name="obfuscated">false</attr>
for the variables containing $,
<attr path="/api/package[#name='com.wed.therace']/class[#name='CarDetails$']/fie ld[#name='machineParts$']"
name="obfuscated">false</attr>
What is the correct way? I got this from https://developer.xamarin.com/guides/android/advanced_topics/binding-a-java-library/customizing-bindings/java-bindings-metadata
Thanks in advance,
The sample you tried disables obfuscation for certain types or members. But $ doesn't necessary mean the code has been obfuscated. Here's the common flow for you of what to do in such cases:
Navigate to the error source to see the generated output C# code. In your error message you'll most likely see something like Error: obj/Debug/src/234.cs (30, 50). Look into this file and see what happens in it on line 30. In your case you'll see a field containing $ in its name which leads to compilation error. Pay attention there is a generator comment line in this file starting with // Metadata.xml XPath ... path="/api/package[#name=...]", like this. You can just copy the path="..." part to use it for configurations in manifest.xml.
Look into generated api.xml file located in obj/Debug (or obj/Release depending or your current config). Try looking for the member definition you have issue in. You should be able to find your field, method or another member there with all its attributes like static, deprecated, obfuscated etc. That's what you can affect with metadata transformations.
Now depending on your situation try one of the following:
If you don't need this type or member in your code, just get rid of it by using remove-node metadata element. Get the path value from the generated sources as described above. Remember you can either remove the error member or the whole type if you don't need it.
If you do need this member, define a rename transformation in metadata like this: <attr path="<copied_from_sources>" name="managedName">ValidNameHere</attr>.
Sometimes you'll need to clean the obj folder to make changes applied. Usually it works correct though.
I'm trying to use JFlex to add custom language highlighting to RSyntaxTextArea. However, the moment I type a character I get an Index Out of Bounds Exception:
http://pastie.org/private/ygjyj4y5nludeu3dn1xug
This occurs even if I use the example JFlex code provided here: https://github.com/bobbylight/RSyntaxTextArea/wiki/Adding-Syntax-Highlighting-for-a-new-Language
I'm not sure what could be causing this. Could someone point me in the right direction?
I'm not quite sure why this works, but I appear to have fixed this problem by copying part of the yylex method from PythonTokenMaker.java to the Java class created by JFlex.
Specifically, I copied and replaced this section of the code: http://pastie.org/private/whjzfhbrzwm8qc88t1idq
It is from the defintion of the method to the line with the comment // store back cached position
Hopefully this will help someone stuck on the same problem!
So everything was going quite nicely, until just a while ago when R.java decided to have this error after adding an icon (5_content_new.png, to be exact).
I've tried cleaning the project and restarting eclipse, to no avail.
The problem code:
public static final class drawable {
public static final int 5_content_new=0x7f020000;
public static final int ic_launcher=0x7f020001;
...
}
The red line appears right under 5_, and the error says:
Underscores can only be used with source level 1.7 or greater
Has anyone encountered a problem like this before?
This is a combination of two things:
Java identifiers cannot start with a digit. The first character should be a letter.
In Java 7, they introduced alternative syntaxes for integer literals; e.g. 1_000 is the same as 1000.
So what is happening is that the compiler is parsing 5_content_new as 5_ content_new ... which is reasonable if the source level was Java 7, and then telling you that you are not using Java 7. If you HAD been using Java 7, that compilation error would have been replaced by an error that said that an integer literal (5_) was not legal at that point.
In short, the code contains something so "off the wall" that the compiler writer didn't anticipate it in the compiler diagnostic code.
The other point is that using ANY underscores in a variable, method, class or package name in Java is a style violation. Underscores should only be used in all-caps constant names like "MAX_VALUE".
I just now tried renaming an existing drawable in a compiling-fine Android project of mine and Eclipse threw this dialog up:
(If you can't see the image very well, the dialog box is saying The resource name must begin with a character.
The way that I produced this dialog was renaming a drawable file. The drawable's original name was button_blue_normal.9.png, renamed it to 5_button_blue_normal.9.png and pressed enter. Dialog popped up immediately after pressing enter.
I never knew this but apparently you'll need a letter-character, not a digit, at the very beginning of a drawable's file name.
I know I'm late to the party but I just ran into this myself when I started working with the ActionBar component.
ScootrNova's answer led me to the solution. The problem was the Android-recommended icon pack that I downloaded for use in the tutorials. All the filenames began with integers (1_xxx.png, etc). I removed the ones I wasn't using, renamed the others to something that began with a letter (I used "icon_xxx.png" as an example), and it compiled without error.
I had the same problem and I solved it after putting digit after text not at begining.
I had line 2_Activity and I changed it to Activity2. It was my solution. Hope that it will help someone.
I had the same problem.
Resolution: Look at the res files, drawlables or inside xml and rename files or strings that start with (number underscore string) 1_string to string_1.
Hope this helps to resolve the problem.
I'm working in a java project where a big part of the code was written with a formatting style that I don't like (and is also non standard), namely all method parameters are in uppercase (and also all local variables).
On IntellJ I am able to use "Analyze -> Inspect Code" and actually find all occurrences of uppercase method parameters (over 1000).
To fix one occurrence I can do "refactor > rename parameter" and it works fine (let's assume there is no overlapping).
Is there a way to automagically doing this refactor (e.g: rename method parameter starting with uppercase to same name starting with lowercase)?
Use a Source Parser
I think what you need to do is use a source code parser like javaparser to do this.
For every java source file, parse it to a CompilationUnit, create a Visitor, probably using ModifierVisitorAdapter as base class, and override (at least) visit(MethodDeclaration, arg). Then write the changed CompilationUnit to a new File and do a diff afterwards.
I would advise against changing the original source file, but creating a shadow file tree may me a good idea (e.g. old file: src/main/java/com/mycompany/MyClass.java, new file src/main/refactored/com/mycompany/MyClass.java, that way you can diff the entire directories).
I'd advise that you think about a few things before you do anything:
If this is a team effort, inform your team.
If this is for an employer, inform your boss.
If this is checked into a version control system, realize that you'll have diffs coming out the wazoo.
If it's not checked into a version control system, check it in.
Take a backup before you make any changes.
See if you have some tests to check before & after behavior hasn't changed.
This is a dangerous refactoring. Be careful.
I am not aware of any direct support for such refactoring out of the box in IDEs. As most IDEs would support name refactoring (which is regularly used). You may need to write some IDE plugin that could browse through source code (AST) and invoke rename refactoring behind the scene for such parameter names matching such format.
I have done a lot of such refactorings on a rather large scale of files, using TextPad or WildPad, and a bunch of reg-ex replace-all. Always worked for me!
I'm confident that if the code is first formatted using an IDE like Eclipse (if it is not properly formatted), and then a reg-ex involving the methods' signature (scope, return-type, name, bracket, arg list, bracket) can be devised, your job will be done in seconds with these tools. You might need more than one replace-all sets of reg-ex.
The only time-taking activity would be to come up with such a set of reg-ex.
Hope this helps!
I've been following the 'Netbeans E-Commerce tutorial', and have am currently on this step:
http://netbeans.org/kb/docs/javaee/ecommerce/entity-session.html
I have fully configured my Window 7 account as per that page, with NetBeans 6.9.1, Glassfish server and MySQL.
I'm getting an error 500 when executing 'Category' page (log extract below). The error manifests itself when I complete step 3 in the 'selected category' sub-section of the 'Accessing Data with EJBs' this page. The line in question is:
// get selected category
selectedCategory = categoryFacade.find(Short.parseShort(categoryId));
If I comment this line out, the bug goes away.
The log file snippet is here:
[#|2010-09-29T18:32:32.570+0100|WARNING|glassfish3.0.1|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=30;_ThreadName=http-thread-pool-8080-(2);|StandardWrapperValve[Controller]: PWC1406: Servlet.service() for servlet Controller threw exception
javax.ejb.EJBException
at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5119)
at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5017)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4805)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2004)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1955)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:198)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:84)
at $Proxy355.find(Unknown Source)
at session.__EJB31_Generated__CategoryFacade__Intf____Bean__.find(Unknown Source)
at controller.ControllerServlet.doGet(ControllerServlet.java:68)
Line 68 in the ControllerServlet code is the one identified above.
My experience with both Java and Netbeans is sufficiently light that I'm not even sure how to go about starting to debug this. I've followed the tutorial pretty closely, so it should not be something I've missed - but mistakes do happen.
I understand an outright solution based on the information contained would be difficult. If there is any further information required, please ask. Failing that, if anyone has any suggestions on how I can further investigate this on my own, I'd be very grateful.
I always think cracking problems is the best way to learn, but it is pretty frustrating as well.
Update:
I've been running through the NetBeans debugger. It appears that the problem is with the cast code (Short.parseShort(categoryId)). When I replace this with a simple numeral it works.
e.g. this code works
// get selected category
selectedCategory = categoryFacade.find(1);
Does anyone have any ideas why the cast is failing? categoryId is confirmed as a string with a value of "1" in the debugger...
Okay, I've cracked this. It was obviously my fault...
The table identity should have been set up as a short, instead I set it up as an integer. Therefore by casting the 'categoryId' string to short and passing it into the find method, I was passing in the wrong data type.
Replacing the 'Short.parseShort(categoryId)' argument with a 'Integer.parseInt(categoryId)' fixed the problem.
For those that took the time to read this; thank you.