Community
Participate
Working Groups
The following template (the default GridData template prefixed with its description as a comment) is indented incorrectly in the Content Assist preview popup // new GridData for a Control ${gridData:newType(org.eclipse.swt.layout.GridData)} ${layoutData:newName(org.eclipse.swt.layout.GridData)} = new ${gridData}(SWT.${horizontal:link(FILL, BEGINNING, CENTER, END)}, SWT.${vertical:link(FILL, TOP, CENTER, BOTTOM)}, ${hex:link(true, false)}, ${vex:link(false, true)}); ${layoutData}.widthHint= ${width:link(SWT.DEFAULT)}; ${layoutData}.heightHint= ${height:link(SWT.DEFAULT)}; ${parent:var(org.eclipse.swt.widgets.Control)}.setLayoutData(${layoutData}); ${imp:import(org.eclipse.swt.SWT)}${cursor} Here's what the preview looks like: // new GridData for a Control org.eclipse.swt.layout.GridData gridData = new org.eclipse.swt.layout.GridData( SWT.FILL, SWT.FILL, true, false); gridData.widthHint = SWT.DEFAULT; gridData.heightHint = SWT.DEFAULT; parent.setLayoutData(gridData); Interestingly, this bug only manifests itself for certain comments; neither the comment's length nor the comment's number of words alone triggers the bug. In particular, a leading comment of // 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 is totally fine, despite it being longer than "new GridData for a Control" and containing more "words". Anyway, I think the problem is located in the vicinity of org.eclipse.jdt.internal.ui.text.template.contentassist.TemplateProposal.getAdditionalProposalInfo(), but I haven't looked much closer than that yet.
Further analysis: Regardless of the comment's contents, the TemplateBuffer that goes into IndentUtil.indentLines(..) in TemplateProposal.getAdditionalProposalInfo() always has the same shape, i.e., leading whitespace: // comment \torg.eclipse.swt.layout.GridData gridData = new org.eclipse.swt.layout.GridData( \t\t\tSWT.FILL, SWT.FILL, true, false); \tgridData.widthHint = SWT.DEFAULT; \tgridData.heightHint = SWT.DEFAULT; \tparent.setLayoutData(gridData); In other words, the Document that goes into IndentUtil.indentLines(..) is the same. However, JavaIndenter.computeIndentation(..) computes, for a non-problematic comment like "new GridData", a result of null, "", "\t\t", "", "", "", and "" for the 7 lines of the template. For a problematic comment like "new GridData for a Control" it computes null, "", "\t\t", "\t\t", "\t\t", "\t\t", "\t\t" instead. As JavaIndenter is stateful it stands to reason that while indenting the first three lines its state diverges. As to why that is, I have no clue yet (but I hope this analysis helps in tracking down the problem).
This was already wrong in 3.8. The indentation is correct when inserting the proposal. Note that (the) wrong indentation can also be seen without adding a comment: org.eclipse.swt.layout.GridData gridData = new org.eclipse.swt.layout.GridData( SWT.FILL, SWT.FILL, true, false); gridData.widthHint = SWT.DEFAULT; gridData.heightHint = SWT.DEFAULT; text.setLayoutData(gridData);
(In reply to Dani Megert from comment #2) > This was already wrong in 3.8. The indentation is correct when inserting the > proposal. I know. It's just the preview popup where it looks awkward. > Note that (the) wrong indentation can also be seen without adding a comment: > > org.eclipse.swt.layout.GridData gridData = new > org.eclipse.swt.layout.GridData( > SWT.FILL, SWT.FILL, true, false); > gridData.widthHint = SWT.DEFAULT; > gridData.heightHint = SWT.DEFAULT; > text.setLayoutData(gridData); That is something I cannot reproduce *unless* you consider the third line to be incorrectly indented. All *other& lines like the ones starting with "gridData." are not indented in the preview but rather shown flushed left. *That* behavior changes only if I add the comment. FWIW, note that the bug also occurs if the first line is "new GridData for a Control"; rather than // new GridData for a Control so the bug is not tied to the "commentness" of the first line. Anyway, thanks for taking care of this.
Also effected by this issue: my template is as follows but using empty lines also breaks the indentation. ``` // // System.debug('}}}'); try { System.debug(JSON.serialize(${target})); } catch(Exception e) { System.debug('Couldn\'t JSON serialize: ' + ${target}); } System.debug('{{{'); // // ```
s/effected/affected
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie.