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

centralize modifier constants + add ClassInfo.isInterface() #188

Merged
merged 1 commit into from
Apr 19, 2022
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
20 changes: 14 additions & 6 deletions core/src/main/java/org/jboss/jandex/ClassInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.jboss.jandex;

import java.lang.reflect.Modifier;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -55,7 +56,6 @@
*/
public final class ClassInfo implements AnnotationTarget {

private static final int MODULE = 0x8000;
private static final int MAX_POSITIONS = 256;
private static final byte[] EMPTY_POSITIONS = new byte[0];

Expand Down Expand Up @@ -255,22 +255,30 @@ public final boolean isSynthetic() {

/**
*
* @return {@code true} if this class was declared as an enum
* @return {@code true} if this class object represents an interface type
*/
public final boolean isInterface() {
return Modifier.isInterface(flags);
}

/**
*
* @return {@code true} if this class object represents an enum type
*/
public final boolean isEnum() {
return (flags & Modifiers.ENUM) != 0 && DotName.ENUM_NAME.equals(superName());
return Modifiers.isEnum(flags) && DotName.ENUM_NAME.equals(superName());
}

/**
*
* @return {@code true} if this class object represents an annotation type
*/
public final boolean isAnnotation() {
return (flags & Modifiers.ANNOTATION) != 0;
return Modifiers.isAnnotation(flags);
}

/**
* @return {@code true} if this class was declared as a record
* @return {@code true} if this class object represents a record type
*/
public final boolean isRecord() {
// there's no flag for record classes, but extending java.lang.Record
Expand All @@ -282,7 +290,7 @@ public final boolean isRecord() {
* @return {@code true} if this class object represents a Java module descriptor
*/
public final boolean isModule() {
return (flags & MODULE) != 0;
return (flags & ModuleInfo.MODULE) != 0;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jboss/jandex/Indexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ private void processMethodParameters(DataInputStream data, MethodInfo target) th
byte[] parameterName = nameIndex == 0 ? null : decodeUtf8EntryAsBytes(nameIndex);
int flags = data.readUnsignedShort();
// skip synthetic/mandated params to get the same param name index as annotations/MethodParameter (which do not count them)
if ((flags & (MethodInternal.SYNTHETIC | MethodInternal.MANDATED)) != 0) {
if ((flags & (Modifiers.SYNTHETIC | Modifiers.MANDATED)) != 0) {
continue;
}

Expand Down Expand Up @@ -1089,7 +1089,7 @@ private boolean skipBridge(TypeAnnotationState typeAnnotationState, MethodInfo m
}

private boolean isBridge(MethodInfo methodInfo) {
int bridgeModifiers = Modifiers.SYNTHETIC | 0x40;
int bridgeModifiers = Modifiers.SYNTHETIC | Modifiers.BRIDGE;
return (methodInfo.flags() & bridgeModifiers) == bridgeModifiers;
}

Expand Down
6 changes: 2 additions & 4 deletions core/src/main/java/org/jboss/jandex/MethodInternal.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
* @author Jason T. Greene
*/
final class MethodInternal {
static final int SYNTHETIC = 0x1000;
static final int MANDATED = 0x8000;
static final int BRIDGE = 0x0040;
static final MethodInternal[] EMPTY_ARRAY = new MethodInternal[0];
static final NameAndParameterComponentComparator NAME_AND_PARAMETER_COMPONENT_COMPARATOR = new NameAndParameterComponentComparator();
static final byte[][] EMPTY_PARAMETER_NAMES = new byte[0][];
Expand Down Expand Up @@ -70,7 +67,8 @@ public int compare(MethodInternal instance, MethodInternal instance2) {
}

// Prefer non-synthetic methods when matching
return (instance.flags & (SYNTHETIC | BRIDGE)) - (instance2.flags & (SYNTHETIC | BRIDGE));
return (instance.flags & (Modifiers.SYNTHETIC | Modifiers.BRIDGE))
- (instance2.flags & (Modifiers.SYNTHETIC | Modifiers.BRIDGE));
}
}

Expand Down
17 changes: 15 additions & 2 deletions core/src/main/java/org/jboss/jandex/Modifiers.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,22 @@
*/
final class Modifiers {

static final int ENUM = 0x00004000;
static final int SYNTHETIC = 0x00001000;
// @formatter:off
static final int BRIDGE = 0x00000040;

static final int SYNTHETIC = 0x00001000;
static final int ANNOTATION = 0x00002000;
static final int ENUM = 0x00004000;
static final int MANDATED = 0x00008000;
// @formatter:on

static boolean isAnnotation(int mod) {
return (mod & ANNOTATION) != 0;
}

static boolean isEnum(int mod) {
return (mod & ENUM) != 0;
}

static boolean isSynthetic(int mod) {
return (mod & SYNTHETIC) != 0;
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/org/jboss/jandex/ModuleInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
*/
public final class ModuleInfo {

static final int MODULE = 0x8000;

private static final int OPEN = 0x0020;

private final ClassInfo moduleInfoClass;
Expand Down