2

Once I needed to enter a lot of text into console, so I changed the "sysout" template to be

System.out.println("${word_selection}${}");${cursor}

instead of

System.out.println(${word_selection}${});${cursor}

But now I don't want this anymore. However, every time I restart Eclipse after setting it to the normal template, it changes back and I get the quotes again.

I also tried additionally setting another setting to trigger the "Oomph preference recorder", but the template doesn't appear there.

I tried my best to attach my eclipse configuration, but even Pastebin times out from these >3MB of text. Here's at least a screenshot of the plugin list: enter image description here

Fabian Röling
  • 1,227
  • 1
  • 10
  • 28
  • I tried this using Eclipse Oxygen.2 Release (4.7.2) and everything worked properly. Which version of Eclipse are you running? Also, what happens if you modify the sysout template yet again, to something new (e.g. **System.out.print(${word_selection}${});${cursor}** ) and restart Eclipse? Is that most recent change to **sysout** picked up, do you still get your original modification to the template with the quotes? – skomisa Jan 24 '18 at 00:27
  • Also, when you amend the template it should be immediately effective, with no need to restart Eclipse. So to be clear, are you saying that if you revert the **sysout** template to its original value, it behaves correctly immediately after the change, and it is ONLY AFTER you restart Eclipse that you see the reversion of the sysout template to have the quotes included once again? – skomisa Jan 24 '18 at 00:33
  • With Eclipse Oxygen you can manually revert the template by clicking the **Edit...** button and regressing the **Pattern** value, or you can simply select the **sysout** template and click **Revert to Default**. Which approach are you using "for setting it to the normal template"? – skomisa Jan 24 '18 at 01:48
  • Re1: Mars. It would have been easier if I was able to just add the configuration output, but SE and pastebin decided to crash. I'll try what you said in about an hour. But I did try to change it to something else previously, it didn't help. Re2: Yes. Re3: Just editing. I don't know if Mars has the same button, I'll look. – Fabian Röling Jan 24 '18 at 07:11
  • OK. If that **Revert to Default** button exists on Mars it's worth trying. It worked for me on Oxygen (as did manual editing of the **Pattern**). – skomisa Jan 24 '18 at 07:18
  • 1. Revert button does exist. 2. It doesn't help. 3. Removing "ln", but keeping the quotation marks actually works! 4. Re-adding the "ln" and removing the quotation marks makes it stay at the version without "ln" and with quotation marks. 5. Apparently it keeps everything **except** the default. 6. SO just now showed me [this question](https://stackoverflow.com/questions/46501124). I guess I can live with "syso" being "System.out.println(", but that doesn't really answer why it behaves this way. The problem is that I can't even report it as an Eclipse bug, because I'll probably not be able to – Fabian Röling Jan 24 '18 at 08:23
  • ...reproduce it in a new installation. – Fabian Röling Jan 24 '18 at 08:24
  • Wow. It must be really annoying for you, but it's an interesting problem. What happens if you press **sout** (or **syso**) then **ctrl/space**. Does that work? Another easy thing to try is to restart Eclipse with the **-clean** parameter to see if that fixes it. See here if you haven't used it before: https://stackoverflow.com/questions/2030064/how-to-run-eclipse-in-clean-mode-and-what-happens-if-we-do-so – skomisa Jan 24 '18 at 08:51
  • 1. I always use "syso". "sysout" works, too. 2. Wow, `-clean` actually works! But only for that start. Using `-clean` at every launch would be an option, but it's probably slower, right? I don't notice it that much, because the PC is pretty fast. – Fabian Röling Jan 24 '18 at 09:33
  • Using **-clean** on every startup is fine, but it shouldn't really be necessary to use it on a continual basis. I have posted an answer for a possible solution for your problem. – skomisa Jan 24 '18 at 16:42

1 Answers1

2

I managed to reproduce your problem by using Oomph, and the way to solve the problem is to stop using Oomph! Since you had mentioned its use in the OP I went to Windows -> Preferences -> Oomph -> Preference Recorder and checked Record into User.

Next I changed the template for sysout to call print() instead of println(). The change was immediately effective, and (as expected) it was also effective after restarting Eclipse.

Then I reverted the template for sysout by clicking Revert to Default, and (as expected) it was immediately effective and sysout generated println(). However, after restarting Eclipse the change was undone, and sysout was once again generating print() instead of println()! That behavior is what you had also reported in the comments for the OP.

On reviewing the Preference Recorder settings again I noticed that the preference for custom_templates had been checked even though I had not explicitly done that:

oomph1

Apparently this is what was causing the user setting to be implemented on startup. I unchecked all the preferences, unchecked Record into User and restarted Eclipse, and sysout then correctly used the default value of println(). So I think the solution for you is uncheck that Record into checkbox for Preference Recorder.

One final point is that Oomph logs exactly what it is doing during Eclipse's startup to file \eclipse\configuration\org.eclipse.oomph.setup\setup.log under the Eclipse installation directory:

[2018-01-24 10:45:03] Workspace D:\OxygenWorkspace
[2018-01-24 10:45:03] Bundle org.eclipse.oomph.setup 1.9.0.v20171202-1121, build=3282, branch=f99b41819cc9f86beec6b54bf453173fc2d4acef
[2018-01-24 10:45:03] Bundle org.eclipse.oomph.setup.core 1.9.0.v20171202-1121, build=3282, branch=f99b41819cc9f86beec6b54bf453173fc2d4acef
[2018-01-24 10:45:03] Bundle org.eclipse.oomph.setup.p2 1.9.0.v20171202-1121, build=3282, branch=f99b41819cc9f86beec6b54bf453173fc2d4acef
[2018-01-24 10:45:03] Performing Preference /instance/org.eclipse.jdt.ui/org.eclipse.jdt.ui.text.custom_templates = <?xml version="1.0" encoding="UTF-8" standalone="no"?><templates><template autoinsert="true" context="java-statements" deleted="false" description="print to standard out" enabled="true" id="org.eclipse.jdt.ui.templates.sysout" name="sysout">System.out.print(${word_selection}${});${cursor}</template></templates>

Note that the final line above shows the user defined template being set.

skomisa
  • 16,436
  • 7
  • 61
  • 102
  • I'll try this tomorrow. Is this an Oomph bug that should be reported? – Fabian Röling Jan 24 '18 at 21:25
  • @Fabian I don't think so; instead it is a misunderstanding on our part of how Oomph works (although the documentation is tough to follow). My understanding is that Oomph will just blindly execute the preferences you have recorded when Eclipse starts until you tell it not to do that. Here's their basic tutorial if you haven't already seen it: https://eclipsesource.com/blogs/tutorials/oomph-basic-tutorial/ – skomisa Jan 24 '18 at 21:36
  • @Fabian Also, it doesn't really make sense for a single developer to be using Oomph; the benefit lies in using it to ensure that a team of developers are all working with the same preferences and settings in Eclipse. That can be done manually but it is a pain, and I guess the motivation for Oomph is to simplify that process. – skomisa Jan 24 '18 at 21:41
  • Well, I am in a team of developers, but we still do it manually. There's a prepared ZIP of Eclipse in the network storage and some sometimes updated preference files for formatting, etc. And getting started with the version management takes a day or two. – Fabian Röling Jan 25 '18 at 07:10
  • Yeah, it works! Thank you very much! Here, have 75 rep. – Fabian Röling Jan 25 '18 at 08:14
  • Cool - I've learned a lot about Oomph from your interesting problem. In particular, I think it's safest to create a separate instance of Eclipse for playing with Oomph so that it cannot impact unrelated development efforts. – skomisa Jan 25 '18 at 08:23