Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup Script Editor #51

Merged
merged 27 commits into from
Aug 20, 2015
Merged

Cleanup Script Editor #51

merged 27 commits into from
Aug 20, 2015

Conversation

Squareys
Copy link
Contributor

Hello everybody,

as part of #40, I cleaned up the existing script editor code, extracted some classes for readability and added a bunch of javadoc. This involved code formatting, which I tried to keep in separate commits. Everything is done in small and (hopefully) clear steps.

In general this is all refactoring and should not result in any visible changes for the user, but does break the API every now and then (changing member access to private and providing a getter for example).

Greetings,
Squareys

Add javadoc, enhance variable naming, add some `final` modifiers where
possible and format code.

Signed-off-by: squareys <squareys@googlemail.com>
Add javadoc, reorder if clause for more clarity, add final modifier.

Signed-off-by: squareys <squareys@googlemail.com>
Now accepts `Collection` instead of `Vector`, add Javadoc.

Signed-off-by: squareys <squareys@googlemail.com>
Signed-off-by: squareys <squareys@googlemail.com>
Signed-off-by: squareys <squareys@googlemail.com>
Both of the afformentioned methods were able to return null (and did
exactly one when the TextEditor is first instanciated). To avoid
NullPointerExceptions, their return values were checked against null if
needed in exactly that case (all undocumented, though). In all other
cases the nullcheck is missing.

There was two ways to go about this, either adding all the nullchecks
(est. > 30 additional nullchecks) or make `getTab` and `getEditorPane`
nullsafe, hence never return null and remove all existing nullchecks.

Signed-off-by: squareys <squareys@googlemail.com>
Avoid some nullchecks and make sure the constructor argument is allways
not null.

Signed-off-by: squareys <squareys@googlemail.com>
New name is more descriptive and avoids shadowing in some EditorPane
methods.

Signed-off-by: squareys <squareys@googlemail.com>
Provide access to the required one via getters.

Signed-off-by: squareys <squareys@googlemail.com>
@ctrueden
Copy link
Member

I'm curious about the rationale for 5ee745f. Would be good to write into the commit message why you are making the change—e.g., does it avoid a race condition or something? If so, would be good to paste the relevant stack trace(s) into the commit message, so the problem being solved is more clear.

@Squareys
Copy link
Contributor Author

I'm curious about the rationale for 5ee745f. Would be good to write into the commit message why you are making the change—e.g., does it avoid a race condition or something? If so, would be good to paste the relevant stack trace(s) into the commit message, so the problem being solved is more clear.

Actually I just thought it might be better style. As I mentioned, creating an Editor in a Scripting Window (TextEditor class) which is null does not actually make sense. Especially, since there is no way to move the editor into a later.

I'm having the feeling you might have missed that that code was synchronized before via a synchronized method. I just inlined it, since it was merely one method call. (I therefore did not change synchronization. But the inlining in the end was pretty unnecessary, because of the synchronized blocks.)

@ctrueden
Copy link
Member

OK, I see what you mean.

I disagree that inlining is better style. Quite the contrary. If you have code in multiple places that does the same thing, it should be a dedicated method. That is the DRY principle: "Don't Repeat Yourself."

So I definitely think the setTitle method should not be removed.

@Squareys
Copy link
Contributor Author

What if the setTitle does frame.setTitle()? It cannot be considered good stlye to have a method for that. Since it was synchronized, that is different though. I just realized later, the synchronized stamements were ammended to that commit.

(I never meant to say inlining is good style in general.)

@ctrueden
Copy link
Member

The setTitle method performs the following actions:

  1. Synchronizes, so it cannot be called concurrently.
  2. Verifies that the frame is not null.
  3. Sets the frame's title if so.

That is three separate steps, which are always performed together like that. So it should be a method.

I understand that it bothers you that a method called setTitle also calls another method called setTitle, but that does not change the fact that it is more DRY to do it this way. If you want to feel better, you could rename the setTitle method to setFrameTitle (or even setFrameTitleAsNeeded or something even more Germanverbose 😉) since it would be more accurate declaration of that method's purpose.

@Squareys
Copy link
Contributor Author

@ctrueden I worked hard to decouple EditorPane from TextEditor, which means those setTitle() calls moved into TextEditor now anyway. (https://github.com/Squareys/imagej-ui-swing/commit/58b3cb17ac9d7aa5f5b9e4ecb50586b95f19994b)

The decoupling is very important for us to be able to reuse EditorPane in the KNIP ScirptEditor, as you originally suggested.

As for the discussion we had about inlining: We were talking past each other. If we ever meet in person on a hackathon again, I'd be glad to explain.

I was not able to address imagej/scijava-issue-shuttle#1 just yet. I will do so in a separate pullrequest. As soon as you merge this, I can file a pullrequest for the codeassist/autocomplete.

Greetings, Squareys.

Signed-off-by: squareys <squareys@googlemail.com>
More clear formatting and apply eclipse "Code Cleanup".

Signed-off-by: squareys <squareys@googlemail.com>
Signed-off-by: squareys <squareys@googlemail.com>
Signed-off-by: squareys <squareys@googlemail.com>
Signed-off-by: squareys <squareys@googlemail.com>
They are not used outside of that package.

Signed-off-by: squareys <squareys@googlemail.com>
Signed-off-by: squareys <squareys@googlemail.com>
Original fix fa4cb46  was not good
enough, since it did not work for multiple new unsaved files.

This commit fixes the source instead of the symptom:

Avoid using `SwingUtils.invokeLater` for light-weight code in two places
to prevent accessing tabs when they are all closed for application
shutdown.

Signed-off-by: squareys <squareys@googlemail.com>
Signed-off-by: squareys <squareys@googlemail.com>
Signed-off-by: squareys <squareys@googlemail.com>
This is step one for decoupling `EditorPane` from `TextEditor` for
potential use in other applications.

Also this avoids the necessity of having the synchronized blocks in
EditorPane and halves the `setTitle` calls on file open and ScriptEditor
startup.

Signed-off-by: squareys <squareys@googlemail.com>
Signed-off-by: squareys <squareys@googlemail.com>
Signed-off-by: squareys <squareys@googlemail.com>
Signed-off-by: squareys <squareys@googlemail.com>
…ditor

Signed-off-by: squareys <squareys@googlemail.com>
The `updateGitDirectory() call in `setLanguage()` is not required, since
the file it is updated for always resides in the same directoy as the file
before which means that git directory will not change.

Signed-off-by: squareys <squareys@googlemail.com>
@Squareys
Copy link
Contributor Author

@ctrueden I merged the "Remove obsolete TODO" commit with the one where it was fixed (and created).

The synchronization issue turned obsolete after I refactored to decouple EditorPane from TextEditor. As I mentioned above, If you are still curious about why I thought inlining was a good idea, we may discuss that in person at some hackathon. As I said: We were talking past each other.

All together, toggling bookmarks doesn't seem to work, but it turns out, they don't work on master either. You might want to double check, though.

All in all, This is ready for merge, and I already finished the autocompletion/codeassist, so I'd be glad, if this PR could be concluded soon, since that will depend on this one.

Greetings, Squareys.

Important if EditorPane should be used outside of the TextEditor.

Signed-off-by: squareys <squareys@googlemail.com>
hinerm added a commit that referenced this pull request Aug 20, 2015
Overhaul the script editor with cleaned up style, javadoc, and better separation of concerns via decoupling the TextEditor and EditorPane.
@hinerm hinerm merged commit ff874bd into imagej:master Aug 20, 2015
@hinerm
Copy link
Member

hinerm commented Aug 20, 2015

Thanks @Squareys
All of these changes are great, and it makes my heart especially happy when I see new javadoc on previously undocumented code. It's much appreciated.

@ctrueden
Copy link
Member

👍! And just in time for the ImageJ conference too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants