Skip to content

Commit

Permalink
Replace matcher with pattern declaration in type definitions and files
Browse files Browse the repository at this point in the history
  • Loading branch information
biboudis committed Mar 5, 2024
1 parent c9448f2 commit cf06130
Show file tree
Hide file tree
Showing 39 changed files with 131 additions and 185 deletions.
43 changes: 4 additions & 39 deletions src/java.base/share/classes/java/lang/classfile/Attribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,44 +24,9 @@
*/
package java.lang.classfile;

import java.lang.classfile.attribute.AnnotationDefaultAttribute;
import java.lang.classfile.attribute.BootstrapMethodsAttribute;
import java.lang.classfile.attribute.CharacterRangeTableAttribute;
import java.lang.classfile.attribute.CodeAttribute;
import java.lang.classfile.attribute.CompilationIDAttribute;
import java.lang.classfile.attribute.ConstantValueAttribute;
import java.lang.classfile.attribute.DeprecatedAttribute;
import java.lang.classfile.attribute.EnclosingMethodAttribute;
import java.lang.classfile.attribute.ExceptionsAttribute;
import java.lang.classfile.attribute.InnerClassesAttribute;
import java.lang.classfile.attribute.LineNumberTableAttribute;
import java.lang.classfile.attribute.LocalVariableTableAttribute;
import java.lang.classfile.attribute.LocalVariableTypeTableAttribute;
import java.lang.classfile.attribute.MatcherAttribute;
import java.lang.classfile.attribute.MethodParametersAttribute;
import java.lang.classfile.attribute.ModuleAttribute;
import java.lang.classfile.attribute.ModuleHashesAttribute;
import java.lang.classfile.attribute.ModuleMainClassAttribute;
import java.lang.classfile.attribute.ModulePackagesAttribute;
import java.lang.classfile.attribute.ModuleResolutionAttribute;
import java.lang.classfile.attribute.ModuleTargetAttribute;
import java.lang.classfile.attribute.NestHostAttribute;
import java.lang.classfile.attribute.NestMembersAttribute;
import java.lang.classfile.attribute.PermittedSubclassesAttribute;
import java.lang.classfile.attribute.RecordAttribute;
import java.lang.classfile.attribute.RuntimeInvisibleAnnotationsAttribute;
import java.lang.classfile.attribute.RuntimeInvisibleParameterAnnotationsAttribute;
import java.lang.classfile.attribute.RuntimeInvisibleTypeAnnotationsAttribute;
import java.lang.classfile.attribute.RuntimeVisibleAnnotationsAttribute;
import java.lang.classfile.attribute.RuntimeVisibleParameterAnnotationsAttribute;
import java.lang.classfile.attribute.RuntimeVisibleTypeAnnotationsAttribute;
import java.lang.classfile.attribute.SignatureAttribute;
import java.lang.classfile.attribute.SourceDebugExtensionAttribute;
import java.lang.classfile.attribute.SourceFileAttribute;
import java.lang.classfile.attribute.SourceIDAttribute;
import java.lang.classfile.attribute.StackMapTableAttribute;
import java.lang.classfile.attribute.SyntheticAttribute;
import java.lang.classfile.attribute.UnknownAttribute;
import java.lang.classfile.attribute.*;
import java.lang.classfile.attribute.PatternAttribute;

import jdk.internal.classfile.impl.BoundAttribute;
import jdk.internal.classfile.impl.UnboundAttribute;
import jdk.internal.javac.PreviewFeature;
Expand All @@ -87,7 +52,7 @@ public sealed interface Attribute<A extends Attribute<A>>
ConstantValueAttribute, DeprecatedAttribute, EnclosingMethodAttribute,
ExceptionsAttribute, InnerClassesAttribute, LineNumberTableAttribute,
LocalVariableTableAttribute, LocalVariableTypeTableAttribute,
MatcherAttribute, MethodParametersAttribute, ModuleAttribute, ModuleHashesAttribute,
PatternAttribute, MethodParametersAttribute, ModuleAttribute, ModuleHashesAttribute,
ModuleMainClassAttribute, ModulePackagesAttribute, ModuleResolutionAttribute,
ModuleTargetAttribute, NestHostAttribute, NestMembersAttribute,
PermittedSubclassesAttribute,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
*/
package java.lang.classfile;

import java.lang.classfile.attribute.PatternAttribute;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import java.lang.classfile.attribute.MatcherAttribute;
import java.lang.classfile.attribute.RecordComponentInfo;
import jdk.internal.classfile.impl.AbstractUnboundModel;
import jdk.internal.javac.PreviewFeature;
Expand All @@ -42,7 +42,7 @@
*/
@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API)
public sealed interface AttributedElement extends ClassFileElement
permits ClassModel, CodeModel, FieldModel, MethodModel, MatcherAttribute,
permits ClassModel, CodeModel, FieldModel, MethodModel, PatternAttribute,
RecordComponentInfo, AbstractUnboundModel {

/**
Expand Down
16 changes: 8 additions & 8 deletions src/java.base/share/classes/java/lang/classfile/Attributes.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import java.lang.classfile.attribute.LocalVariableTableAttribute;
import java.lang.classfile.attribute.LocalVariableTypeInfo;
import java.lang.classfile.attribute.LocalVariableTypeTableAttribute;
import java.lang.classfile.attribute.MatcherAttribute;
import java.lang.classfile.attribute.PatternAttribute;
import java.lang.classfile.attribute.MethodParameterInfo;
import java.lang.classfile.attribute.MethodParametersAttribute;
import java.lang.classfile.attribute.ModuleAttribute;
Expand Down Expand Up @@ -497,18 +497,18 @@ public AttributeMapper.AttributeStability stability() {
};

/** Attribute mapper for the {@code Matcher} attribute */
public static final AttributeMapper<MatcherAttribute>
public static final AttributeMapper<PatternAttribute>
MATCHER = new AbstractAttributeMapper<>(NAME_MATCHER) {
@Override
public MatcherAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
return new BoundAttribute.BoundMatcherAttribute(cf, this, p);
public PatternAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
return new BoundAttribute.BoundPatternAttribute(cf, this, p);
}

@Override
protected void writeBody(BufWriter buf, MatcherAttribute attr) {
buf.writeIndex(attr.matcherName());
buf.writeU2(attr.matcherFlagsMask());
buf.writeIndex(attr.matcherMethodType());
protected void writeBody(BufWriter buf, PatternAttribute attr) {
buf.writeIndex(attr.patternName());
buf.writeU2(attr.patternFlagsMask());
buf.writeIndex(attr.patternMethodType());
buf.writeList(attr.attributes());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import java.lang.classfile.attribute.AnnotationDefaultAttribute;
import java.lang.classfile.attribute.DeprecatedAttribute;
import java.lang.classfile.attribute.ExceptionsAttribute;
import java.lang.classfile.attribute.MatcherAttribute;
import java.lang.classfile.attribute.PatternAttribute;
import java.lang.classfile.attribute.MethodParametersAttribute;
import java.lang.classfile.attribute.RuntimeInvisibleAnnotationsAttribute;
import java.lang.classfile.attribute.RuntimeInvisibleParameterAnnotationsAttribute;
Expand All @@ -52,7 +52,7 @@ public sealed interface MethodElement
extends ClassFileElement
permits AccessFlags, CodeModel, CustomAttribute,
AnnotationDefaultAttribute, DeprecatedAttribute,
ExceptionsAttribute, MatcherAttribute, MethodParametersAttribute,
ExceptionsAttribute, PatternAttribute, MethodParametersAttribute,
RuntimeInvisibleAnnotationsAttribute, RuntimeInvisibleParameterAnnotationsAttribute,
RuntimeInvisibleTypeAnnotationsAttribute, RuntimeVisibleAnnotationsAttribute,
RuntimeVisibleParameterAnnotationsAttribute, RuntimeVisibleTypeAnnotationsAttribute,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@

package java.lang.classfile.attribute;

import java.lang.classfile.AccessFlags;
import java.lang.classfile.Attribute;
import java.lang.classfile.AttributedElement;
import java.lang.classfile.MethodElement;
import java.lang.classfile.constantpool.IntegerEntry;
import java.lang.classfile.constantpool.Utf8Entry;
import jdk.internal.classfile.impl.BoundAttribute;
import jdk.internal.classfile.impl.TemporaryConstantPool;
Expand All @@ -49,32 +47,32 @@
* Delivered as a {@link MethodElement} when
* traversing the elements of a {@link java.lang.classfile.MethodModel}.
*/
public sealed interface MatcherAttribute
extends Attribute<MatcherAttribute>, MethodElement, AttributedElement
permits BoundAttribute.BoundMatcherAttribute,
public sealed interface PatternAttribute
extends Attribute<PatternAttribute>, MethodElement, AttributedElement
permits BoundAttribute.BoundPatternAttribute,
UnboundAttribute.UnboundMatcherAttribute {

/**
* {@return the the module flags of the module, as a bit mask}
*/
int matcherFlagsMask();
int patternFlagsMask();

/**
* {@return the the module flags of the module, as a set of enum constants}
*/
default Set<AccessFlag> matcherFlags() {
return AccessFlag.maskToAccessFlags(matcherFlagsMask(), AccessFlag.Location.MATCHER);
default Set<AccessFlag> patternFlags() {
return AccessFlag.maskToAccessFlags(patternFlagsMask(), AccessFlag.Location.MATCHER);
}

/** {@return the name of this method} */
Utf8Entry matcherName();
Utf8Entry patternName();

/** {@return the method descriptor of this method} */
Utf8Entry matcherMethodType();
Utf8Entry patternMethodType();

/** {@return the method descriptor of this method, as a symbolic descriptor} */
default MethodTypeDesc matcherTypeSymbol() {
return MethodTypeDesc.ofDescriptor(matcherMethodType().stringValue());
default MethodTypeDesc patternTypeSymbol() {
return MethodTypeDesc.ofDescriptor(patternMethodType().stringValue());
}

/**
Expand All @@ -84,7 +82,7 @@ default MethodTypeDesc matcherTypeSymbol() {
* @param matcherDescriptor the descriptor of the matcher
* @param matcherAttributes the list of attributes of the matcher
*/
static MatcherAttribute of(String matcherName,
static PatternAttribute of(String matcherName,
int matcherFlags,
MethodTypeDesc matcherDescriptor,
List<Attribute<?>> matcherAttributes) {
Expand All @@ -102,7 +100,7 @@ static MatcherAttribute of(String matcherName,
* @param matcherDescriptor the descriptor of the matcher
* @param matcherAttributes the list of attributes of the matcher
*/
static MatcherAttribute of(Utf8Entry matcherName,
static PatternAttribute of(Utf8Entry matcherName,
int matcherFlags,
Utf8Entry matcherDescriptor,
List<Attribute<?>> matcherAttributes) {
Expand Down
10 changes: 5 additions & 5 deletions src/java.base/share/classes/java/lang/reflect/AccessFlag.java
Original file line number Diff line number Diff line change
Expand Up @@ -377,25 +377,25 @@ public Set<Location> apply(ClassFileFormatVersion cffv) {
* The access flag {@code DECONSTRUCTOR} with a mask value of {@code
* 0x3000}.
*/
DECONSTRUCTOR(0x3000, false, Location.SET_MATCHER,
DECONSTRUCTOR(0x3000, false, Location.SET_PATTERN,
new Function<ClassFileFormatVersion, Set<Location>>() {
@Override
public Set<Location> apply(ClassFileFormatVersion cffv) {
return (cffv.compareTo(ClassFileFormatVersion.RELEASE_22) >= 0 ) ?
Location.SET_MATCHER:
Location.SET_PATTERN :
Location.EMPTY_SET;}
}),

/**
* The access flag {@code TOTAL} with a mask value of {@code
* 0x4000}.
*/
TOTAL(0x4000, false, Location.SET_MATCHER,
TOTAL(0x4000, false, Location.SET_PATTERN,
new Function<ClassFileFormatVersion, Set<Location>>() {
@Override
public Set<Location> apply(ClassFileFormatVersion cffv) {
return (cffv.compareTo(ClassFileFormatVersion.RELEASE_22) >= 0 ) ?
Location.SET_MATCHER:
Location.SET_PATTERN :
Location.EMPTY_SET;}
}),

Expand Down Expand Up @@ -615,7 +615,7 @@ public enum Location {
Set.of(FIELD, METHOD);
private static final Set<Location> SET_FIELD_METHOD_INNER_CLASS =
Set.of(FIELD, METHOD, INNER_CLASS);
private static final Set<Location> SET_MATCHER = Set.of(MATCHER);
private static final Set<Location> SET_PATTERN = Set.of(MATCHER);

private static final Set<Location> SET_METHOD = Set.of(METHOD);
private static final Set<Location> SET_METHOD_PARAM = Set.of(METHOD_PARAMETER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Function;

import java.lang.classfile.*;
Expand All @@ -45,8 +44,6 @@
import java.lang.classfile.constantpool.Utf8Entry;
import jdk.internal.access.SharedSecrets;

import static java.lang.classfile.Attributes.CONSTANT_VALUE;

public abstract sealed class BoundAttribute<T extends Attribute<T>>
extends AbstractElement
implements Attribute<T> {
Expand Down Expand Up @@ -333,34 +330,34 @@ public List<LocalVariableTypeInfo> localVariableTypes() {
}
}

public static final class BoundMatcherAttribute extends BoundAttribute<MatcherAttribute>
implements MatcherAttribute {
public static final class BoundPatternAttribute extends BoundAttribute<PatternAttribute>
implements PatternAttribute {
private MethodTypeDesc mDesc;
private List<Attribute<?>> attributes;

public BoundMatcherAttribute(ClassReader cf, AttributeMapper<MatcherAttribute> mapper, int pos) {
public BoundPatternAttribute(ClassReader cf, AttributeMapper<PatternAttribute> mapper, int pos) {
super(cf, mapper, pos);
}

@Override
public Utf8Entry matcherName() {
public Utf8Entry patternName() {
return classReader.readUtf8Entry(payloadStart);
}

@Override
public int matcherFlagsMask() {
public int patternFlagsMask() {
return classReader.readU2(payloadStart + 2);
}

@Override
public Utf8Entry matcherMethodType() {
public Utf8Entry patternMethodType() {
return classReader.readUtf8Entry(payloadStart + 4);
}

@Override
public MethodTypeDesc matcherTypeSymbol() {
public MethodTypeDesc patternTypeSymbol() {
if (mDesc == null) {
mDesc = MethodTypeDesc.ofDescriptor(matcherMethodType().stringValue());
mDesc = MethodTypeDesc.ofDescriptor(patternMethodType().stringValue());
}
return mDesc;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
import java.lang.classfile.attribute.ExceptionsAttribute;
import java.lang.classfile.attribute.InnerClassInfo;
import java.lang.classfile.attribute.InnerClassesAttribute;
import java.lang.classfile.attribute.MatcherAttribute;
import java.lang.classfile.attribute.PatternAttribute;
import java.lang.classfile.attribute.MethodParametersAttribute;
import java.lang.classfile.attribute.MethodParameterInfo;
import java.lang.classfile.attribute.ModuleAttribute;
Expand Down Expand Up @@ -225,12 +225,12 @@ public MethodTransform asMethodTransform() {
case RuntimeInvisibleTypeAnnotationsAttribute aa ->
mb.with(RuntimeInvisibleTypeAnnotationsAttribute.of(
mapTypeAnnotations(aa.annotations())));
case MatcherAttribute ma -> {
case PatternAttribute ma -> {
List<Attribute<?>> matcherAttrs = ma.attributes().stream().<Attribute<?>>map(this::mapMatcherAttributes).toList();
mb.with(MatcherAttribute.of(
ma.matcherName().stringValue(),
ma.matcherFlagsMask(),
ma.matcherTypeSymbol(),
mb.with(PatternAttribute.of(
ma.patternName().stringValue(),
ma.patternFlagsMask(),
ma.patternTypeSymbol(),
matcherAttrs));
}
default ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import java.lang.classfile.AnnotationElement;
import java.lang.classfile.AnnotationValue;
import java.lang.classfile.Attribute;
import java.lang.classfile.AccessFlags;
import java.lang.classfile.AttributeMapper;
import java.lang.classfile.Attributes;
import java.lang.classfile.BootstrapMethodEntry;
Expand All @@ -57,7 +56,7 @@
import java.lang.classfile.attribute.LocalVariableTableAttribute;
import java.lang.classfile.attribute.LocalVariableTypeInfo;
import java.lang.classfile.attribute.LocalVariableTypeTableAttribute;
import java.lang.classfile.attribute.MatcherAttribute;
import java.lang.classfile.attribute.PatternAttribute;
import java.lang.classfile.attribute.MethodParameterInfo;
import java.lang.classfile.attribute.MethodParametersAttribute;
import java.lang.classfile.attribute.ModuleAttribute;
Expand Down Expand Up @@ -313,8 +312,8 @@ public Optional<NameAndTypeEntry> enclosingMethod() {
}

public static final class UnboundMatcherAttribute
extends UnboundAttribute<MatcherAttribute>
implements MatcherAttribute {
extends UnboundAttribute<PatternAttribute>
implements PatternAttribute {
private final int matcherFlags;
private final Utf8Entry matcherName;
private final Utf8Entry matcherMethodType;
Expand All @@ -329,17 +328,17 @@ public UnboundMatcherAttribute(Utf8Entry matcherName, int matcherFlags, Utf8Entr
}

@Override
public int matcherFlagsMask() {
public int patternFlagsMask() {
return matcherFlags;
}

@Override
public Utf8Entry matcherName() {
public Utf8Entry patternName() {
return matcherName;
}

@Override
public Utf8Entry matcherMethodType() {
public Utf8Entry patternMethodType() {
return matcherMethodType;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public enum Modifier {
* The modifier {@code default}
* @since 23
*/
MATCHER,
PATTERN,
/** The modifier {@code static} */ STATIC,

/**
Expand Down
Loading

0 comments on commit cf06130

Please sign in to comment.