Make eclipse remove unused imports but keep unresolved - eclipse

Is there a way to make Eclipse keep used but unresolved imports?
I'm using Eclipse's save actions to remove unused imports. Unfortunately it also removes imports that are used, but not unresolved.
In the example below, eclipse will remove GeneratedClass, if I save MyClass before generating the GeneratedClass. When I late generate the code, MyClass will be missing the import.
import a.b.GeneratedClass;
public class MyClass extend GeneratedClass {}

Thanks to Bananeweizen and Krispy for their contributions, but so far it seems that the answer to this question is No.
The most efficient work around for me, is just to hit ctrl+z every time I save a file with unresolved imports.
I have submitted a bug to Eclipse's bugtracker: https://bugs.eclipse.org/bugs/show_bug.cgi?id=395538
This Eclipse bug tracks this issue: https://bugs.eclipse.org/bugs/show_bug.cgi?id=357795

Don't use the save macros and instead hit Ctrl-Shift-O which will give you more explicit control over when the imports should be tidied up.

You can disable the clean up action and instead remove the unwanted imports manually one by one using Ctrl1 to invoke the quick fix for that.
Nevertheless you are just trying to hide the real problem. The real problem is that your generated code is not generated at the right time. You should fix that. If you don't know how to automatically involve actions in Eclipse during every project build, please look at this example (which automatically creates a jar file with a custom script during every build). You can have those builders applied to the project in any order that you want, so you can always have your code generation invoked automatically before the Java compiler, on saving your Java files.

Related

Unknown Type Errors when using functionblocks from my own library project

So I have a library project where I defined a couple of functionblocks and interfaces.
Now I want to use this library in a plc project (in the same twincat solution). So I do the whole save all, rebuild, save and install as a library spiel. If I try to declare a VAR in my MAIN it will result in unknown type errors. I have fiddled around a bit, and when I declare an interface withouth any properties or methods (in the lib) then I it does show up and can be used in the MAIN. But as soon as I add a property or method the class/FB/POU dissapears in the eyes of my MAIN...
I feel like I'm overlooking some option / atribute to help the PLC project to use the lib properly...
What am I missing here?
EDIT:
as you can see in the images, empty blocks are found, adding anything magically makes it dissapear
error
available classes
EDIT 2:
I solved my problem by copying the lib to a new solution. Something in the original project made it be broken. Why it did that is still a mystery...
Try following steps:
clean the solution where you programmed the library.
right click on the project and click check all objects
if this is successfull, install the library again, remove it from the reference section and re-add it.
Then clean again and build all.

Groovy debugger out of sync

I am having a difficulty while attempting to debug some code in grails. It is difficult to put into text, so I have posted a screencast showing exactly what the problem is here. In short, while I am debugging the debugger starts jumping from place to place and not following the program logic I have in place. The only other similar question I have found is a year old, had no solution, and can be found here.
The best guess I have so far is that the debugger is displaying the text I have typed in, but is actually executing an older version of the class file which it has cached somewhere. Therefore, I tried:
cleaning the project
manually deleting all of the class files from the target folder and from the target-eclipse folder
Searching my entire hdd for additional files with similar names
removing my project from the workspace and re-adding it
closing and reopening the IDE
grails refresh-dependencies
Importing the project into a new IDE (I was using GGTS, I switched to IntelliJ)
None of those solutions had any effect. I realized that the issue was in a .groovy file, and I was writing almost pure Java, so I deleted the .groovy file, and re-created the class in a .java file. That solved my problem. Unfortunately I am having the problem again, and this time it is in a controller that heavily relies on the grails framework, so that solution is not an option. Other than also being in a .groovy file, another similarity is that the code breaks on an if statement.
My next steps:
Verify that the application is not executing the code I see by using print functions to monitor actual execution flow.
comment out the entire function and re-add functionality one line at a time to see if I can see what breaks it.
Delete the .groovy file, and re-create it as another .groovy file.
Any help is appreciated, and since I can't find any answers online I will continue to update this question as I learn more.
See my comment on the jira issue that you raised. You have found a problem with the groovy compiler and how it calculates line numbers. This is not a problem with executing the wrong class files or using a broken debugger. The debugger is doing exactly what it is expected to do. It is the compiler that is providing erroneous line number information.
The next step, as described in the issue, is to provide a simple project that recreates the bug. I tried to do so myself, but could not. So, please supply something that we can work with. Then we can notify the groovy compiler team.

Any way to disable syntax checking for a project?

I created a project "Sample Code"... here I just paste sample code... much of it is snippets that won't compile.
Is there some project-specific setting I can make so that Eclipse doesn't try to compile it?
I would prefer not to have the source code littered with red error markers.
Put your code in a non-java project, ie a general project.
Downside: you will have to create package directory structure (unless you can copy and paste from somewhere else).
Upside: it won't try to compile.
MY SOLUTION
ok, this is not an exact solution to my problem... but it is another way to do it and I kinda like it now...
I simply forget about using Eclipse to store the sample java files!
I found a good program CodeBox for Mac to store code snippets and I'm sure there exist such things for Windows, Linux too...
there interesting thing is that when I choose from this program to open the java snippet file (.java) in an external editor (Eclipse), it will open in Eclipse without any Syntax checking... wohoo! no squiggly lines
Because of this, it is not full blown code highlighting... classes and variables same color... but that's ok.. still quite readable. Much more than if it was in Eclipse with syntax highlighting running on it...
So basically, if you want to get rid of these red squiggles... one way to do it is don't keep sample .java (or other language) files in a project in Eclipse... simply keep them in the filesystem or code storage app and open them with Eclipse when you want to view them.
Depending on how you prefer to structure your project:
you could put your java files into a separate folder that is not configured as a source folder. There is an entry in the eclipse help on how to configure your build path.
or you can set exclusion-patterns in the build configuration, so that specific packages or files that follow a pattern you define don't get compiled.
Yet another way to handle your snippets could be to use a Scrapbook page.
Eclipse won't highlight anything in a scrapbook page but you can select code parts inside the page and execute them isolated. That's nice if you're experimenting and don't want to set up a whole class with imports and methods just to see if a specific snippet works as expected.

How do I force Eclipse to rebuild if files in another project change (any change)?

I've got an Eclipse (Galileo) project (called ProguardBuilder) that runs Proguard over a set of class files in other projects and produces a jar file.
I'd like to have the ProguardBuilder project get rebuilt any time any class file in the other projects changes. AutoBuild doesn't do that; presumably it's smart enough to recognize and ignore any changes that don't affect anything externally visible.
My problem is that I don't care whether or not the change is visible, since I need to completely rebuild ProguardBuilder any time the class files it depends on change at all.
How do I tell Eclipse to do this sort of rebuild?
You might have to use an external builder. Check the documentation, because I've never done this. But the place to start is the "Builders" section of the project properties dialogue.

Eclipse: On Save execute a program

I have recently come across the LESS Leaner CSS a template engine for CSS based on ruby. The idea sounded neat, but in practice we need to compile the program to get CSS. This is cumbersome as we make too many changes while working on CSS and for every edit we don't want to compile.
In Eclipse, there are "Save-Actions" but it handles only formatting changes.
Is there a way on saving the file in Eclipse, to call or trigger the compilation?
Its easy to do this in Vi or Emacs.
I think all you need is to define a custom Builder for your project. That way, you can run a program or an ant script whenever certain files change.
Right click on the project -> Properties -> Builders -> New
While the Builders are a good solution, keep in mind they only work when a build is issued - either using auto-build or using a manual build which is invoked, well, manually. If you are looking for something that will operate after a save, regardless of the auto-build state you will need to write a plugin which listens to resource changes in Eclipse.
You do that by creating a workspace change listener and installing it like that:
ResourcesPlugin.getWorkspace().addResourceChangeListener(
..., IResourceChangeEvent.POST_CHANGE);
I'm sure you can take it from here :-)