Skip to content

Commit

Permalink
IrritantSet needs unsigned right shift for GROUP4 and higher (#2029)
Browse files Browse the repository at this point in the history
fixes #2006

* Apply the correct shift operator
* Add a test which will start running once IrritantSet.GROUP4 is enabled in JDT
  • Loading branch information
stephan-herrmann authored Feb 15, 2024
1 parent 3ef57ab commit 6eab603
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public boolean areAllSet() {
}

public IrritantSet clear(int singleGroupIrritants) {
int group = (singleGroupIrritants & GROUP_MASK) >> GROUP_SHIFT;
int group = (singleGroupIrritants & GROUP_MASK) >>> GROUP_SHIFT;
this.bits[group] &= ~singleGroupIrritants;
return this;
}
Expand All @@ -242,7 +242,7 @@ public IrritantSet clearAll() {
public void initialize(int singleGroupIrritants) {
if (singleGroupIrritants == 0)
return;
int group = (singleGroupIrritants & GROUP_MASK) >> GROUP_SHIFT;
int group = (singleGroupIrritants & GROUP_MASK) >>> GROUP_SHIFT;
this.bits[group] = singleGroupIrritants & ~GROUP_MASK; // erase group information
}

Expand Down Expand Up @@ -280,14 +280,14 @@ public boolean hasSameIrritants(IrritantSet irritantSet) {
}

public boolean isSet(int singleGroupIrritants) {
int group = (singleGroupIrritants & GROUP_MASK) >> GROUP_SHIFT;
int group = (singleGroupIrritants & GROUP_MASK) >>> GROUP_SHIFT;
return (this.bits[group] & singleGroupIrritants) != 0;
}
public int[] getBits() {
return this.bits;
}
public IrritantSet set(int singleGroupIrritants) {
int group = (singleGroupIrritants & GROUP_MASK) >> GROUP_SHIFT;
int group = (singleGroupIrritants & GROUP_MASK) >>> GROUP_SHIFT;
this.bits[group] |= (singleGroupIrritants & ~GROUP_MASK); // erase the group bits
return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*******************************************************************************
* Copyright (c) 2024 GK Software SE and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Stephan Herrmann - Initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.core.tests.compiler;

import org.eclipse.jdt.core.tests.junit.extension.TestCase;
import org.eclipse.jdt.internal.compiler.impl.IrritantSet;

import junit.framework.Test;
import junit.framework.TestSuite;

public class IrritantSetTest extends TestCase {

public IrritantSetTest(String name) {
super(name);
}

public static Test suite() {
TestSuite suite = new TestSuite(IrritantSetTest.class.getPackageName());
suite.addTest(new TestSuite(IrritantSetTest.class));
return suite;
}

public void testGroup4() {
if (IrritantSet.GROUP_MAX <= 4) {
System.out.println("IrritantSetTest.testGroup4 will trigger once IrritantSet.GROUP_MAX exceeds 4.");
return;
}
@SuppressWarnings("unused") // dead code as of now
int singleIrritant = ( 4 << IrritantSet.GROUP_SHIFT /* group4 */) + 42;
IrritantSet irritantSet = new IrritantSet(singleIrritant);
assertTrue(irritantSet.isSet(singleIrritant));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.eclipse.jdt.core.tests.compiler.CharDeduplicationTest;
import org.eclipse.jdt.core.tests.compiler.DeduplicationUtilTest;
import org.eclipse.jdt.core.tests.compiler.IrritantSetTest;
import org.eclipse.jdt.core.tests.compiler.map.CharArrayMapperTest;
import org.eclipse.jdt.core.tests.junit.extension.TestCase;

Expand Down Expand Up @@ -240,6 +241,8 @@ private static Class[] getAllTestClasses() {
DeduplicationUtilTest.class,

RecordsElementTests.class,

IrritantSetTest.class,
};

Class[] deprecatedClasses = getDeprecatedJDOMTestClasses();
Expand Down

0 comments on commit 6eab603

Please sign in to comment.