Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 143029 - [typing] Correct Indentation works incorrect after >> operator (bit shift right)
Summary: [typing] Correct Indentation works incorrect after >> operator (bit shift right)
Status: CLOSED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.1.2   Edit
Hardware: PC All
: P3 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: JDT-Text-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
: 243158 439757 512661 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-05-22 14:08 EDT by Olaf van Zon CLA
Modified: 2019-10-27 03:16 EDT (History)
8 users (show)

See Also:


Attachments
skipSkope fix (1.10 KB, patch)
2006-06-01 10:52 EDT, Olaf van Zon CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Olaf van Zon CLA 2006-05-22 14:08:05 EDT
Snippet:

	public void start() {
		int result;
		for (int i = 0; i < 3; i ++) {
			result = i >> 1;
		result ++; // Correct indentation is wrong here
		}
	}
Comment 1 Olaf van Zon CLA 2006-05-27 13:41:19 EDT
In the code above, the LESS token in the for statement seems to be part of the 
cause. Indentation is correct when other operators are used.

The following code shows the same indentation behavour:


	private int i = 3 << 1;

	public int start() {
		for (int j = 0; j == 0; j ++) {
			j = 3 >>> 1;
	i = 0; // wrong indentation
		}
		return 0;
	}
Comment 2 Dani Megert CLA 2006-05-29 03:48:36 EDT
Can be reproduced using 3.2 RC6.
Comment 3 Olaf van Zon CLA 2006-06-01 10:52:27 EDT
Created attachment 43251 [details]
skipSkope fix
Comment 4 Olaf van Zon CLA 2006-06-01 10:54:26 EDT
The error can be traced back to the class: JavaIndenter
From package: org.eclipse.jdt.internal.ui.text

Method: skipScope()

After finding a > token, preceeded
by a >, the code assumes that it is looking for a generic type
and tries to find the matching < for the preceeding >.

There are 3 problems with the code:
1) The assumption that it is looking for a generic type is not always correct.
   In the case of a bit shift right and an unsigned bit shift right,
   it should not be looking for a generic type.

2) The code tries to find the scope for the preceeding >
   To work as intended, it should to go back to its original position and 
   token, and then skip the scope.

3) A minor thing: nextToken() modifies:
   fToken, fPreviousPos, fPosition and fLine.
   However skipScope() resets only fPosition and fToken to
   their original values.

Proposal:
1) Remove the last TokenGREATERTHAN case.
2) Store and restore the values of fPreviousPos and fLine.
(see the attachment above)
Comment 5 Dani Megert CLA 2006-06-01 10:56:11 EDT
Tom, please give the patch a try.
Comment 6 Tom Hofmann CLA 2006-08-14 10:40:39 EDT
Released patch with the following changes > 20060814 - thanks!
- added copyright
- added test in JavaHeuristicScannerTest::testShiftOperator()
Comment 7 Olaf van Zon CLA 2007-05-19 08:01:40 EDT
Bug is still present in 3.3 RC1

BTW, the test case in testShiftOperator does not match the examples.
(i.e. '<' in the for expression)


Comment 8 Dani Megert CLA 2007-05-21 07:07:17 EDT
The test cases are wrong. I removed them.

You and Tom obviously didn't test the fix (your suggestion from comment 3 got applied - I reverted them for 3.3).
Comment 9 Hernan Soulages CLA 2007-11-06 20:23:04 EST
A friend bumped into this bug. This is the minimal code I got to that still has the incorrect indentation:
	long C = 1 << 2;
	void m() {
		long e = 1 >> 2;
	//wrong indentation
	}	

It seems that the problem is when there is left shift and after it a block of code that contains a right shift.
Comment 10 Dani Megert CLA 2008-08-05 09:03:34 EDT
*** Bug 243158 has been marked as a duplicate of this bug. ***
Comment 11 Yuping Liang CLA 2014-07-17 07:25:37 EDT
This bug is still there in 4.4. I can't imagine it's still not been fixed. Is there an official solution or patch for this ?
I tried wrapping the expression that contains >> with parentheses and it corrected the indentation. However it is not always a good solution to this.
Comment 12 Timo Kinnunen CLA 2014-07-17 19:11:53 EDT
Is this skipScope code the reason why this class declaration 

abstract class AbstractStream<T, E extends Exception, STREAM,
SELF extends AbstractStream<T, E, STREAM,
SELF,
IS, LS, DS, CONSUMER, PREDICATE, BINARY_OPERATOR, COMPARATOR, TO_IS, TO_LS, TO_DS, TO_INT, TO_LONG, TO_DOUBLE>,
IS, LS, DS, CONSUMER, PREDICATE, BINARY_OPERATOR, COMPARATOR, TO_IS, TO_LS, TO_DS, TO_INT, TO_LONG, TO_DOUBLE> { }

gets turned into a hugely over-long one line? And if so, is that code really necessary in the first place?
Comment 13 Martin Mathew CLA 2014-07-21 21:14:59 EDT
*** Bug 439757 has been marked as a duplicate of this bug. ***
Comment 14 Frank Benoit CLA 2016-12-01 09:01:37 EST
This is still present on Eclipse Neon 4.6.1
Comment 15 Stephan Herrmann CLA 2016-12-04 07:13:18 EST
From a quick glance I guess that the core of the solution would need to let JavaHeuristicScanner recognize combined tokens like LEFT_SHIFT, RIGHT_SHIFT etc.

Unfortunately, even ">>" doesn't necessarily mean RIGHT_SHIFT, it could be a pair of two closing type argument angle-brackets.

See grammar rules like

TypeArguments     ::= '<' TypeArgumentList1
TypeArgumentList1 -> TypeArgument1
TypeArgument1     -> ReferenceType1
ReferenceType1    ::= ClassOrInterface '<' TypeArgumentList2
TypeArgumentList2 -> TypeArgument2
TypeArgument2     -> ReferenceType2
ReferenceType2    ::= ReferenceType '>>'

OR: skipScope() would need to cancel its search when any content between '<' and '>' is illegal for a type argument.

=> either way not a trivial task ...
Comment 16 Noopur Gupta CLA 2017-02-27 06:20:39 EST
*** Bug 512661 has been marked as a duplicate of this bug. ***
Comment 17 Eclipse Genie CLA 2019-10-26 01:08:56 EDT
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.
Comment 18 Jaroslaw Kacerka CLA 2019-10-27 03:16:52 EDT
Bug is still present in 2019-09 R (4.13.0) (build: 20190917-1200)