Skip to content

Use generics to eliminate casting #718

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 @@ -629,24 +629,24 @@ private void addExtensionMethod( AbstractSrcMethod<?> method, SrcClass extendedT

String name = method.getSimpleName();
srcMethod.name( name );
List typeParams = method.getTypeVariables();
List<SrcType> typeParams = method.getTypeVariables();

// extension method must reflect extended type's type vars before its own
int extendedTypeVarCount = extendedType.getTypeVariables().size();
for( int i = isInstanceExtensionMethod ? extendedTypeVarCount : 0; i < typeParams.size(); i++ )
{
SrcType typeVar = (SrcType) typeParams.get( i );
SrcType typeVar = typeParams.get( i );
srcMethod.addTypeVar( typeVar );
}

List params = method.getParameters();
List<SrcParameter> params = method.getParameters();

// exclude @This param
int firstParam = isInstanceExtensionMethod || hasThisClassAnnotation( method ) ? 1 : 0;

for( int i = firstParam; i < params.size(); i++ )
{
SrcParameter param = (SrcParameter) params.get( i );
SrcParameter param = params.get( i );
SrcParameter p = new SrcParameter( param.getSimpleName(), param.getType() );
for( SrcAnnotationExpression anno : param.getAnnotations() )
{
Expand All @@ -656,9 +656,9 @@ private void addExtensionMethod( AbstractSrcMethod<?> method, SrcClass extendedT
srcMethod.addParam( p );
}

for( Object throwType : method.getThrowTypes() )
for( SrcType throwType : method.getThrowTypes() )
{
srcMethod.addThrowType( (SrcType) throwType );
srcMethod.addThrowType( throwType );
}

if( delegateCalls )
Expand Down Expand Up @@ -732,9 +732,9 @@ else if( hasThisClassAnnotation( method ) )
.rawText( call.toString() ) ) );
}

private boolean warnIfDuplicate( AbstractSrcMethod method, SrcClass extendedType, DiagnosticListener<JavaFileObject> errorHandler )
private boolean warnIfDuplicate( AbstractSrcMethod<?> method, SrcClass extendedType, DiagnosticListener<JavaFileObject> errorHandler )
{
AbstractSrcMethod duplicate = findMethod( method, extendedType );
AbstractSrcMethod<?> duplicate = findMethod( method, extendedType );

if( duplicate == null )
{
Expand Down Expand Up @@ -778,16 +778,16 @@ private AbstractSrcMethod findMethod( AbstractSrcMethod<?> method, SrcClass exte
paramsToSubtract = firstParam.hasAnnotation( This.class ) || firstParam.hasAnnotation( ThisClass.class ) ? 1 : 0;
}
outer:
for( AbstractSrcMethod m: extendedType.getMethods() )
for( AbstractSrcMethod<?> m: extendedType.getMethods() )
{
if( m.getSimpleName().equals( method.getSimpleName() ) && m.getParameters().size() == method.getParameters().size()-paramsToSubtract )
{
List parameters = method.getParameters();
List params = m.getParameters();
List<SrcParameter> parameters = method.getParameters();
List<SrcParameter> params = m.getParameters();
for( int i = paramsToSubtract; i < parameters.size(); i++ )
{
SrcParameter param = (SrcParameter)parameters.get( i );
SrcParameter p = (SrcParameter)params.get( i-paramsToSubtract );
SrcParameter param = parameters.get( i );
SrcParameter p = params.get( i-paramsToSubtract );
if( !param.getType().equals( p.getType() ) )
{
continue outer;
Expand Down Expand Up @@ -826,7 +826,7 @@ private AbstractSrcMethod findMethod( AbstractSrcMethod<?> method, SrcClass exte
return duplicate;
}

private boolean isExtensionMethod( AbstractSrcMethod method, SrcClass extendedType )
private boolean isExtensionMethod( AbstractSrcMethod<?> method, SrcClass extendedType )
{
if( !Modifier.isStatic( (int)method.getModifiers() ) || Modifier.isPrivate( (int)method.getModifiers() ) )
{
Expand Down Expand Up @@ -860,14 +860,14 @@ private boolean isInstanceExtensionMethod( AbstractSrcMethod method, SrcClass ex
return hasThisAnnotation( method, extendedType );
}

private boolean hasThisAnnotation( AbstractSrcMethod method, SrcClass extendedType )
private boolean hasThisAnnotation( AbstractSrcMethod<?> method, SrcClass extendedType )
{
List params = method.getParameters();
List<SrcParameter> params = method.getParameters();
if( params.size() == 0 )
{
return false;
}
SrcParameter param = (SrcParameter)params.get( 0 );
SrcParameter param = params.get( 0 );
if( !param.hasAnnotation( This.class ) )
{
return false;
Expand All @@ -876,14 +876,14 @@ private boolean hasThisAnnotation( AbstractSrcMethod method, SrcClass extendedTy
return param.getType().getName().endsWith( extendedType.getSimpleName() ) ||
isArrayExtension( param, extendedType );
}
private boolean hasThisClassAnnotation( AbstractSrcMethod method )
private boolean hasThisClassAnnotation( AbstractSrcMethod<?> method )
{
List params = method.getParameters();
List<SrcParameter> params = method.getParameters();
if( params.size() == 0 )
{
return false;
}
SrcParameter param = (SrcParameter)params.get( 0 );
SrcParameter param = params.get( 0 );
if( !param.hasAnnotation( ThisClass.class ) )
{
return false;
Expand Down