Java class methods do not auto complete in Jython using Eclipse Pydev - java

I'm using PyDev 2.5 with Eclipse Indigo and Jython 2.5.3b1 . I have a JAR file that contains certain classes which I'm importing to a PyDev (Jython ) project. They seem to work seamlessly except for Auto completion. The member functions of Java Classes do not auto-complete e.g. pressing the dot '.' operator does not bring up the list for class member functions. The jar file is added to the PyDev-PYTHONPATH external libraries of the PyDev project.
Screenshot of PYTHONPATH external libs
Auto completion does not work for the code below, but it compiles and runs perfectly fine.
from my.testpackage import MyClass
myVar = MyClass("Monkey")
print myVar.getName()
Typing "myVar." does not auto complete
Worth noting that auto completion works if I imported a non custom jar
e.g.
from java.lang import Math
print Math.max(3,5)
Typing "Math." will auto complete
I'm not sure if this functionality even supported in the current version of PyDev. Does anyone actually have this working in their PyDev and Eclipse setup?
Any suggestion would be appreciated.
Thank you,
DM

It may be some issue in your PYTHONPATH configuration. Have you read: http://pydev.org/manual_101_project_conf2.html (most specifically the end of the page: "Project reference for Jython users").
If that doesn't help you, can you explain how are you referencing things? (a screenshot with the config would be nice)

Related

How do I resolve "the type is not accessible" error in Eclipse when using an external JAR? JAR in question is algs4 from Princeton [duplicate]

I'm new to the whole programming stuff but here's my problem:
I used to add my JUnit test cases in Eclipse by right clicking on the project, and just add New > JUnit Test Case.
Currently, I am not able to implement any test methods because Eclipse tells me on the line
import static org.junit.jupiter.api.Assertions.*;
the error message
The type org.junit.jupiter.api.Assertions is not accessible.
Error I get in the IDE:
I tried the following:
Reinstalling Eclipse, using a fresh workplace.
Adding the JUnit to Build path
Nothing helped.
It worked and works in older projects just fine.
Here is how the Package Explorer looks:
What am I missing?
You use the Java Platform Module System (JPMS) by having a module-info.java file in the default package probably without the required requires <module>; statement. JPMS was introduced in Java 9.
Do one of the following:
Delete the module-info.java file (if needed, you can recreate it via right-clicking the project folder and choosing Configure > Create module-info.java)
In module-info.java add the corresponding requires statement, e.g. by going to the line with the import statement and using the corresponding Quick Fix (Ctrl+1)

Using Jsoup library on eclipse [duplicate]

I have just recently started using Eclipse and am running into problems trying to install external libraries. Following online tutorials, I add the .jar file to the classpath and I see it in the referenced libraries folder. Despite this, when trying to import, I get the error:
The package org.apache.commons is not accessible
For reference, I am trying to install the apache math commons library.
Your code probably has two issues.
First, the import statement is wrong since in Java you cannot add a package itself, but all classes of a package as follows (note .*; at the end):
import org.apache.commons.math4.linear.*;
or a specific class, e.g.
import org.apache.commons.math4.linear.FieldMatrix;
Second, you use the Java Platform Module System (JPMS) by having a module-info.java file in the default package probably without the required requires <module>; statement. JPMS was introduced in Java 9 and you have Java 12.
Do one of the following:
Delete the module-info.java file (if needed, you can recreate it via right-clicking the project folder and choosing Configure > Create module-info.java)
In module-info.java add the corresponding requires statement, e.g. by going to the line with the import statement and using the corresponding Quick Fix (Ctrl+1)

Integrating a Java Class into a PyDev Project (Jython) in Eclipse

I have a Java class that i would like to import into my Jython script. Unfortunately, eclipse won't let me create a Java class inside my Jython project.In the window, where you create and name your Java class, I get a message at the top (alongside a red cross) saying, "Source folder is not a Java project" when I type the name of the would be class. How do I rectify this? I need the Java Class to call C code using the JNI (declaring the native method,loading and then calling it). Thank You !!!!!!!
What you can do is to create second module which would be java project. Anyhow, logically it should be that way. Please check out other similar question - PyDev: Jython modules & Java classes in the same project.
Other links that might help - http://pydev.org/manual_101_project_conf2.html
So what nefo_x suggested is correct. You need to create a new Java project that will contain your Java class. Then import the Java package as you would a python module. But there are a few things to watch out for in eclipse to make it work. I list the whole process below:
Your Java class (or classes) should not be in the default package. You need to create a new package and make/put your java class files there.
Export the package as a jar file to some place on your computer.
Add the jar file (located at some place on your computer) to your python path.
Import the package by writing "import PackageName".
The problem for me was that I had my java class in the default package. That does not work due to some naming issues. Anyhow, hope that this helps.

SelendroidDriver not in jar file

I have recently written a Selenium program in Java that works perfectly with the FireFoxDriver(). My step 2 is to be able to run this program on my Android device with Selendroid. I went on their website here and have been able to download the jar and connect to their localhost with port:4444.
However, when I try their example, Eclipse doesn't recognize the SelendroidDriver() and suggests me to go back to WebDriver().
Here is their code:
SelendroidCapabilities capa = new SelendroidCapabilities("io.selendroid.testapp:0.10.0");
// My error appears when I create the new SelendroidDriver().
WebDriver driver = new SelendroidDriver(capa);
WebElement inputField = driver.findElement(By.id("my_text_field"));
Assert.assertEquals("true", inputField.getAttribute("enabled"));
inputField.sendKeys("Selendroid");
Assert.assertEquals("Selendroid", inputField.getText());
driver.quit();
I have also noticed that the SelendroidDriver class does not appear in my files although I downloaded the Selendroid jar file, version 0.10.0.
For those of you who are curious about how I fixed my problem, here is what I did:
I went to this site to get the selendroid-client jar file corresponding to the standalone version I had.
Downloading the standalone jar file was somehow not enough.
I was facing the same problem till I found the SelendroidDriver class here. Import this and change the package name according to your project.
SelendroidDriver.java has classes implementing interface methods, which in Java 1.6 can be annotated with #Override. However, in Java 1.5, #override could only be applied to methods overriding a superclass method.
Go to your project preferences and set the "Java compiler level" to 1.6 and also make sure you select JRE 1.6 to execute your program from Eclipse.
After adding this class, you would still see multiple dependency errors, but now in the SelendroidDriver.java file. You can import these classes now to counter these errors. Ensure that the package hierarchies are maintained correctly, in accordance with the GitHub directories and your working project.
After importing all these classes, the constant fields SWITCH_TO_CONTEXT, GET_CONTEXT_HANDLES and GET_CURRENT_CONTEXT_HANDLE were not being resolved. I used a poor workaround of changing them to some other available constant field for testing this sample.
I struggled a lot with this error and finally came to know that the paths have been changed in the latest releases. Use these paths and it shall work:
import io.selendroid.common.SelendroidCapabilities;
import io.selendroid.client.SelendroidDriver;
Tested this for versions 0.15.0 & 0.17.0

Eclipse 3.5+ - Annotation processor: Generated classes cannot be imported

I am using a 3rd party annotation processor for generating meta-data code (.java files) from the annotated classes in my project.
I have successfully configured the processor through Eclipse (Properties -> Java Compiler -> Annotation Processing) and the code generation works fine (code is automatically created and generated). Also, Eclipse successfully auto-completes the generated classes and their fields, without any errors. Let's say that I have a class "some.package.Foo" and that the generated meta-data class is "some.package.Foo_". By the help of auto-completion, I can get the following code in the Eclipse editor, without any errors:
import some.package.Foo_;
...
public class Test {
void test() {
Foo_.someField = null; // try to access a field from the generated class Foo_
}
}
However, as soon as I actually build the project (or just save the file since Build automatically is enabled), I get the error which tells that "some.package.Foo_" cannot be resolved.
It seems like Eclipse is generating and compiling the some.package.Foo_ at the same time, or more likely.
I found two temporary solutions (which are practically hindering the use of the annotation processor in the first place):
Before each build of that generated classes, right click on every generated file go to Properties and uncheck the "Derived" tick. After that, I do the cleanup of the project and the imports are fine - there are no more errors. However, if I do the cleanup one more time, the errors again show up, because the generation of the files causes the "Derived" tick to be checked again (automatically). So this is really annoying and time-consuming.
I also uncheck the "Derived" tick
from all those files, and this time
I uncheck the "Derived" tick from
the source folder and packages which
contain those files. Then I disable
the annotation processor, and then
do the cleanup. There are no more
import errors, even if I do another
cleanup, but there is no benefit of
using the annotation processor,
because if I was to change something
which would update the model, I need
to turn the annotation processor
back on, and repeat this tedious
procedure to turn it off, after it
has generated the new version of
those files.
Is this a bug in Eclipse? If yes, is there a better workaround or quick-fix than the two I have stated above? If not, what should I try to solve the problem?
I also tried rearranging the order of the libraries on the build path and it doesn't help.
I assume that you are generating sources in the last processor round. This is not recommended way and leads exactly to the problem that you had.
Explanation is here: http://code.google.com/p/acris/wiki/CodeGenerationPlatform_Pitfall_Rounds
So the my advise is to generate sources in regular processing rounds and final round should be used just for notification that processing is over or something like that.
Hopefully this helps you.
I have a similar problem, and the only thing I've found is that it's the imports specifically that don't work, but the references in the class itself do work. The workaround I've used is to use the FQCN in all cases where the generated class is needed (except when the generated class is in the same package, since then the import is obviously not needed).
So to use your example, I'd do:
public class Test {
void test() {
some.package.Foo_.someField = null; // try to access a field from the generated class Foo_
}
}
My only guess then is that the eclipse compiler is processing the imports before doing the annotation processing, which imho must be a bug in eclipse.
I know this question is over a year old, so I'd be interested to know if you've found any other way to fix it.
We were experiencing a similar problem and apparently just solved it, so thought of sharing it at SO, in case it helps someone.
We are using:
Eclipse Indigo (Build id: 20120216-1857)
m2e Connector for maven
openJPA for static metamodel class generation
Our problem:
Say, we have a package named com.abc.xyz and an entity class in there named OurEntity. When we build the projects (JPA, EJB, EAR etc. all together with an mvn clean at the beginning) the metamodel classes get generated. And also get appropriately packaged within the PU jar. But when we try to import the generated metamodel class com.abc.xyz.OurEntity_, Eclipse cannot resolve it. OP apparently got past this point:-). Maven build failed, saying it could not resolve that class. Not much help from google except for a few bug reports such as this one: https://bugs.eclipse.org/bugs/show_bug.cgi?id=350378
That bug report said importing the whole package as opposed to the single class helped. So, tried that, but with no benefit. It also said (and so did David Heitzman) that using the fully qualified class name worked for them. That did not work either.
The solution:
Added the PU jar to Eclipse build path for the project that needed to use the metamodel classes. All of a sudden all the red underlines went away (not a surprise). But the fear was there might be two PUs in the same ear. But maven automagically took care of that.
As this rather old question got some attention without pointing to the very probable eclipse bug the OP was specifically asking for, I'd like to complement the above answers with a pointer to the eclipse bug tracker:
Cannot resolve import for generated class IF processing annotations with parameters referencing constants
The workarounds include
doing a wildcard import of the package defining the generated classes (i.e. import some.package.*;)
using the fully qualified name of your generated class, i.e. referring to some.package.Foo in your code and not using an import
switch to a newer Eclipse. This specific eclipse bug is resolved with Eclipse version 4.4 (aka Luna).

Categories