public SrcField type( Class type ) { _type = new SrcType( type ); return this; }
private boolean isClassType( SrcType srcType ) { return !srcType.isPrimitive() && !srcType.isArray() && !"?".equals( srcType.getName() ); }
private SrcType( TypeNameParser.Type simpleType ) { _fqn = simpleType._fqn; _isDiamond = simpleType._diamond; _arrayDims = simpleType._arrayDim; _componentType = _arrayDims > 0 ? new SrcType( simpleType.getComponentType() ) : null; _typeParams = new ArrayList<>(); if( !simpleType._params.isEmpty() ) { _typeParams = new ArrayList<>(); for( TypeNameParser.Type param: simpleType._params ) { addTypeParam( new SrcType( param ) ); } } if( simpleType._bound != null ) { _superOrExtends = simpleType._superOrExtends; _bound = simpleType._bound.stream().map( SrcType::new ).collect( Collectors.toList() ); } else { _bound = Collections.emptyList(); } }
if( srcType.isArray() ) SrcType componentType = srcType.getComponentType(); addAnnotation( componentType, attr ); java.util.List<SrcType> typeArguments = srcType.getTypeParams(); for( int i = 0; i < typeArguments.size(); i++ ) else if( "?".equals( srcType.getName() ) && !srcType.getBounds().isEmpty() ) annotateType( srcType.getBounds().get( 0 ), Collections.singletonList( new Attribute.TypeCompound( attr.type, attr.values, posCopy ) ) );
private SrcType makeNestedType( Type type ) { String fqn = type.toString(); Type enclosingType = type.getEnclosingType(); SrcType srcType; if( enclosingType != null && !(enclosingType instanceof NoType) && fqn.length() > enclosingType.toString().length() ) { String simpleName = fqn.substring( enclosingType.toString().length() + 1 ); srcType = new SrcType( simpleName ); srcType.setEnclosingType( makeNestedType( enclosingType ) ); } else { srcType = new SrcType( fqn ); } return srcType; }
if( !param.getType().equals( p.getType() ) ) if( superClass != null && superClass.getName().equals( Object.class.getName() ) ) SrcClass superSrcClass = ClassSymbols.instance( getModule() ).makeSrcClassStub( superClass.getName(), null ); duplicate = findMethod( method, superSrcClass ); SrcClass superIface = ClassSymbols.instance( getModule() ).makeSrcClassStub( iface.getName(), null ); duplicate = findMethod( method, superIface ); if( duplicate != null )
private void addAnnotation( SrcType srcType, Attribute.TypeCompound attr ) { String fqn = attr.type.toString(); if( fqn.equals( "jdk.internal.HotSpotIntrinsicCandidate" ) ) { // Since java 10 we have to keep these out of stubbed java source return; } SrcAnnotationExpression annoExpr = new SrcAnnotationExpression( fqn ); for( Pair<Symbol.MethodSymbol, Attribute> value: attr.values ) { annoExpr.addArgument( value.fst.flatName().toString(), new SrcType( value.snd.type.toString() ), value.snd.getValue() ); } srcType.addAnnotation( annoExpr ); }
if( String.class.getName().equals( type.getName() ) || String.class.getSimpleName().equals( type.getName() ) ) else if( type.isEnum() ) result = type.getName() + '.' + value; else if( type.getName().equals( char.class.getName() ) ) sb.append( i > 0 ? ", " : "" ).append( makeCompileTimeConstantValue( type.getComponentType(), v ) );
public String getFqName() { return _enclosingType != null ? _enclosingType.getName() + '.' + _fqn : _fqn; }
_enclosingType.render( sb, indent ); sb.append( '.' ); if( !getAnnotations().isEmpty() ) renderAnnotations( sbFqn, 1, true ); sbFqn.append( ' ' ).append( _fqn.substring( iDot+1 ) ); fqn = sbFqn.toString(); _bound.get( i ).render( sb, 0 ); param.render( sb, 0 );
if( !param.getType().equals( p.getType() ) ) if( superClass != null && superClass.getName().equals( Object.class.getName() ) ) SrcClass superSrcClass = ClassSymbols.instance( getModule() ).makeSrcClassStub( superClass.getName(), null ); duplicate = findMethod( method, superSrcClass ); SrcClass superIface = ClassSymbols.instance( getModule() ).makeSrcClassStub( iface.getName(), null ); duplicate = findMethod( method, superIface ); if( duplicate != null )
private boolean hasThisAnnotation( AbstractSrcMethod method, SrcClass extendedType ) { List params = method.getParameters(); if( params.size() == 0 ) { return false; } SrcParameter param = (SrcParameter)params.get( 0 ); if( !param.hasAnnotation( This.class ) ) { return false; } // checking only for simple name for cases where the name cannot be resolved yet e.g., extension method on another source producer type return param.getType().getName().endsWith( extendedType.getSimpleName() ); }
public SrcClass superClass( Class superClass ) { _superClass = new SrcType( superClass ); return this; }
private boolean hasThisAnnotation( AbstractSrcMethod method, SrcClass extendedType ) { List params = method.getParameters(); if( params.size() == 0 ) { return false; } SrcParameter param = (SrcParameter)params.get( 0 ); if( !param.hasAnnotation( This.class ) ) { return false; } // checking only for simple name for cases where the name cannot be resolved yet e.g., extension method on another source producer type return param.getType().getName().endsWith( extendedType.getSimpleName() ); }
public SrcClass superClass( String superClass ) { _superClass = new SrcType( superClass ); return this; }
private void delegateCall( AbstractSrcMethod method, boolean isInstanceExtensionMethod, SrcMethod srcMethod ) { StringBuilder call = new StringBuilder(); SrcType returnType = srcMethod.getReturnType(); if( returnType != null && !returnType.getName().equals( void.class.getName() ) ) { call.append( "return " ); } String extClassName = ((SrcClass)method.getOwner()).getName(); call.append( extClassName ).append( '.' ).append( srcMethod.getSimpleName() ).append( '(' ); if( isInstanceExtensionMethod ) { call.append( "this" ); } for( SrcParameter param : srcMethod.getParameters() ) { if( call.charAt( call.length()-1 ) != '(' ) { call.append( ", " ); } call.append( param.getSimpleName() ); } call.append( ");\n" ); srcMethod.body( new SrcStatementBlock() .addStatement( new SrcRawStatement() .rawText( call.toString() ) ) ); }
public T returns( Class returns ) { _returns = new SrcType( returns ); return (T)this; }
private void delegateCall( AbstractSrcMethod method, boolean isInstanceExtensionMethod, SrcMethod srcMethod ) { StringBuilder call = new StringBuilder(); SrcType returnType = srcMethod.getReturnType(); if( returnType != null && !returnType.getName().equals( void.class.getName() ) ) { call.append( "return " ); } String extClassName = ((SrcClass)method.getOwner()).getName(); call.append( extClassName ).append( '.' ).append( srcMethod.getSimpleName() ).append( '(' ); if( isInstanceExtensionMethod ) { call.append( "this" ); } for( SrcParameter param : srcMethod.getParameters() ) { if( call.charAt( call.length()-1 ) != '(' ) { call.append( ", " ); } call.append( param.getSimpleName() ); } call.append( ");\n" ); srcMethod.body( new SrcStatementBlock() .addStatement( new SrcRawStatement() .rawText( call.toString() ) ) ); }