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

Jandex - Follow-up on Marko's work #621

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
HV-644 Filter out synthetic methods
We will probably need to ask the Jandex guys to add a proper method.

Same for the constructor thing.
  • Loading branch information
gsmet committed Jan 6, 2017
commit d7a437a6bc1a058c6894c1fabe1743ad1873adf2
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@
* Builder for constrained methods that uses Jandex index.
*
* @author Marko Bekhta
* @author Guillaume Smet
*/
public class ConstrainedMethodJandexBuilder extends AbstractConstrainedElementJandexBuilder {

private static final int SYNTHETIC = 0x1000;
private static final int BRIDGE = 0x0040;

protected final ExecutableParameterNameProvider parameterNameProvider;

public ConstrainedMethodJandexBuilder(ConstraintHelper constraintHelper, JandexHelper jandexHelper,
Expand All @@ -61,11 +65,9 @@ public ConstrainedMethodJandexBuilder(ConstraintHelper constraintHelper, JandexH
public Stream<ConstrainedElement> getConstrainedExecutables(ClassInfo classInfo, Class<?> beanClass) {
// HV-172; ignoring synthetic methods (inserted by the compiler), as they can't have any constraints
// anyway and possibly hide the actual method with the same signature in the built meta model
//TODO: check for synthetic somehow ?
// void <init>() - such method is included in the method list but how to filter it out ?

return classInfo.methods().stream()
.filter( methodInfo -> !Modifier.isStatic( methodInfo.flags() ) /*&& !Modifier.isSynthetic( methodInfo.flags() )*/ )
.filter( methodInfo -> !Modifier.isStatic( methodInfo.flags() ) && !isSynthetic( methodInfo ) )
.map( methodInfo -> toConstrainedExecutable( beanClass, methodInfo ) );
}

Expand All @@ -78,16 +80,10 @@ public Stream<ConstrainedElement> getConstrainedExecutables(ClassInfo classInfo,
* @return {@link ConstrainedExecutable} representation of a given method
*/
private ConstrainedExecutable toConstrainedExecutable(Class<?> beanClass, MethodInfo methodInfo) {
Executable executable = null;
//TODO: this try/catch should be removed once filtering of methods is fixed.
try {
executable = findExecutable( beanClass, methodInfo );
}
catch (IllegalArgumentException e) {
e.printStackTrace();
return null;
}
Executable executable = findExecutable( beanClass, methodInfo );

Stream<ConstrainedParameter> parameterConstraints = getParameterMetaData( beanClass, executable, methodInfo );

Set<MetaConstraint<?>> crossParameterConstraints;
Map<ConstraintDescriptorImpl.ConstraintType, Set<MetaConstraint<?>>> executableConstraints =
findMetaConstraints( methodInfo.annotations(), executable )
Expand Down Expand Up @@ -271,8 +267,7 @@ private Stream<MetaConstraint<?>> findMetaConstraints(ParameterInformation param
*/
private Executable findExecutable(Class<?> beanClass, MethodInfo methodInfo) {
try {
if ( "<init>".equals( methodInfo.name() ) ) {
// it means it is a constructor:
if ( isConstructor( methodInfo ) ) {
return beanClass.getDeclaredConstructor( methodInfo.parameters().stream()
.map( type -> jandexHelper.getClassForName( type.name().toString() ) )
.toArray( size -> new Class<?>[size] ) );
Expand All @@ -296,6 +291,16 @@ private Executable findExecutable(Class<?> beanClass, MethodInfo methodInfo) {
}
}

private boolean isConstructor(MethodInfo methodInfo) {
// currently, Jandex does not expose this in a practical way
return "<init>".equals( methodInfo.name() );
}

private boolean isSynthetic(MethodInfo methodInfo) {
// currently, Jandex does not expose this in a practical way
return ( methodInfo.flags() & ( SYNTHETIC | BRIDGE ) ) != 0;
}

/**
* Simple POJO that contains {@link Type}, name and index of a method parameter.
*/
Expand Down