Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IrritantSet needs unsigned right shift for GROUP4 and higher #2029

Merged
merged 2 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading