Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java "this"-keyword marked as static in eclipse content assist

Does anybody know the reason why the this keyword (Java) is marked as static final in the content assist in Eclipse? final makes sense to me, but why static?

Screenshot Eclipse

The screenshot was made with Eclipse 2020-03, but I'm observing this behavior since many years.

like image 376
user7291698 Avatar asked May 05 '20 18:05

user7291698


People also ask

How do I fix content assist in Eclipse?

Solution. Go to Window -> Preferences -> Editor -> Content Assist -> Advanced and enable Parsing-based Proposals. Click Apply. Content assist should start working immediately.

How do I enable content assist in Eclipse?

To enable the Content Assist window to open automatically, go to the Content Assist Preferences page, accessed from Window | Preferences | PHP | Editor | Content Assist and mark the 'Enable auto-activation' checkbox.

How do I turn off auto suggestion in Eclipse?

Open menu Window, then Preferences. Follow path Java -> Editor -> Content assist. Now mess around with the settings to find your ideal setup. I believe what you'll want is to deactivate Insert single proposals automatically.


1 Answers

The code doing this is in org.eclipse.jdt.internal.ui.text.java.ParameterGuesser

// add 'this'
if (currentType != null && !(fEnclosingElement instanceof IMethod && Flags.isStatic(((IMethod) fEnclosingElement).getFlags()))) {
  String fullyQualifiedName= currentType.getFullyQualifiedName('.');
  if (fullyQualifiedName.equals(expectedType)) {
    ImageDescriptor desc= new JavaElementImageDescriptor(JavaPluginImages.DESC_FIELD_PUBLIC, JavaElementImageDescriptor.FINAL | JavaElementImageDescriptor.STATIC, JavaElementImageProvider.SMALL_SIZE);
    res.add(new Variable(fullyQualifiedName, "this", Variable.LITERALS, false, res.size(), new char[] {'.'}, desc));  //$NON-NLS-1$
  }
}

The key thing in that code is

JavaElementImageDescriptor.FINAL | JavaElementImageDescriptor.STATIC

as the flags to JavaElementImageDescriptor which is hard coding the display of the static and final overlay images. So these are always displayed for this.

As to why that was chosen the code doesn't give any reason.

like image 63
greg-449 Avatar answered Oct 15 '22 02:10

greg-449