@Override protected Object evaluate(Iterator args) { Object[] argArray = new Object[_ci.getParameters().length]; if( _boundValues != null ) { args = Arrays.asList(_boundValues).iterator(); } for (int i = 0; i < argArray.length; i++) { argArray[i] = args.next(); } return _ci.getConstructor().newInstance(argArray); }
@Override protected Object evaluate(Iterator args) { Object[] argArray = new Object[_ci.getParameters().length]; if( _boundValues != null ) { args = Arrays.asList(_boundValues).iterator(); } for (int i = 0; i < argArray.length; i++) { argArray[i] = args.next(); } return _ci.getConstructor().newInstance(argArray); }
public static TestClass createTestClass(IType testType) { IConstructorInfo noArgConstructor = testType.getTypeInfo().getConstructor(); if (noArgConstructor != null) { return (TestClass) noArgConstructor.getConstructor().newInstance(); } else { IConstructorInfo oneArgConstructor = testType.getTypeInfo().getConstructor(JavaTypes.STRING()); if (oneArgConstructor != null) { return (TestClass) oneArgConstructor.getConstructor().newInstance("temp"); } else { throw new IllegalArgumentException("Type " + testType.getName() + " does not have either a no-arg constructor or a one-arg constructor that takes a String"); } } }
@Override public Object getInstance() { ITypeInfo autoinsertTypeInfo = JavaTypes.AUTOINSERT().getTypeInfo(); return autoinsertTypeInfo.getConstructor().getConstructor().newInstance(); }
@SuppressWarnings({"UnusedDeclaration"}) public static void maybeAutoInsert( Object obj, int index, IType typeToAutoCreate ) { List l = (List)obj; if( l.size() == index ) { if( typeToAutoCreate.isAbstract() || typeToAutoCreate.isInterface() ) { throw new IllegalStateException( "Type " + typeToAutoCreate.getName() + " is abstract or an interface and has no default implementation class to use" ); } final IConstructorInfo constructor = typeToAutoCreate.getTypeInfo().getConstructor(); if( constructor == null ) { throw new IllegalStateException( "Type " + typeToAutoCreate.getName() + " has no default constructor" ); } //noinspection unchecked l.add( constructor.getConstructor().newInstance() ); } }
@SuppressWarnings({"UnusedDeclaration"}) public static void maybeAutoInsert( Object obj, int index, IType typeToAutoCreate ) { List l = (List)obj; if( l.size() == index ) { if( typeToAutoCreate.isAbstract() || typeToAutoCreate.isInterface() ) { throw new IllegalStateException( "Type " + typeToAutoCreate.getName() + " is abstract or an interface and has no default implementation class to use" ); } final IConstructorInfo constructor = typeToAutoCreate.getTypeInfo().getConstructor(); if( constructor == null ) { throw new IllegalStateException( "Type " + typeToAutoCreate.getName() + " has no default constructor" ); } //noinspection unchecked l.add( constructor.getConstructor().newInstance() ); } } }
private IAnnotationInfo makeAutocreateAnnotation(Function0 function) { final IType autocreateType = TypeSystem.getByFullName("gw.lang.Autocreate"); List<? extends IConstructorInfo> constructors = autocreateType.getTypeInfo().getConstructors(); for (IConstructorInfo constructor : constructors) { if (constructor.getParameters().length == 1) { final Object val = constructor.getConstructor().newInstance(function); return new AutoCreateAnnotationInfo(autocreateType, val); } } throw new IllegalStateException("Could not find the block constructor for Autocreate"); }
private void create( String value, String typeName ) { TypeSystem.getByFullName( typeName ).getTypeInfo().getConstructor( JavaTypes.STRING() ).getConstructor().newInstance( value ); }
public static Object newInstance( IType type, Object ctx, Object[] args ) { ITypeInfo typeInfo = type.getTypeInfo(); IConstructorInfo method; IType[] runtimeTypes = ReflectUtil.extractRuntimeTypes( args ); method = typeInfo.getCallableConstructor( runtimeTypes ); args = ReflectUtil.coerceArgsIfNecessary( method.getParameters(), args ); args = maybeAddOuter( type, ctx, args ); return method.getConstructor().newInstance( args ); }
public static <T> T construct( String typeName, Object... args ) { IType type = TypeSystem.getByFullName( typeName ); ensureTypeIsValid( type ); IType[] runtimeTypes = extractRuntimeTypes( args ); IConstructorInfo constructorInfo = findCallableConstructor( type, runtimeTypes ); if( constructorInfo != null ) { return (T) constructorInfo.getConstructor().newInstance( coerceArgsIfNecessary( constructorInfo.getParameters(), args ) ); } else { throw new IllegalArgumentException( "Unable to find a constructor on " + type.getName() + " with parameters compatible with arg types [" + GosuStringUtil.join( runtimeTypes, "," ) + "]"); } }
public static <T> T construct( String typeName, Object... args ) { IType type = TypeSystem.getByFullName( typeName ); ensureTypeIsValid( type ); IType[] runtimeTypes = extractRuntimeTypes( args ); IConstructorInfo constructorInfo = findCallableConstructor( type, runtimeTypes ); if( constructorInfo != null ) { return (T) constructorInfo.getConstructor().newInstance( coerceArgsIfNecessary( constructorInfo.getParameters(), args ) ); } else { throw new IllegalArgumentException( "Unable to find a constructor on " + type.getName() + " with parameters compatible with arg types [" + GosuStringUtil.join( runtimeTypes, "," ) + "]"); } }
private void wrapParameter( XmlElement node, Pair<WsdlOperationParameterInfo, Boolean> paramInfo, Object arg ) { XmlElement parameterElement = (XmlElement) paramInfo.getFirst().getParameterElementType().getTypeInfo().getConstructor().getConstructor().newInstance(); parameterElement = paramInfo.getFirst().wrap( arg, parameterElement ); node.addChild( parameterElement ); }
@Override public Object getInstance() { ITypeInfo autocreateTypeInfo = GosuTypes.AUTOCREATE().getTypeInfo(); if ( _concreteType != null && JavaTypes.LIST().isAssignableFrom( _concreteType ) ) { for ( IConstructorInfo constructor : autocreateTypeInfo.getConstructors()) { IParameterInfo[] constructorParams = constructor.getParameters(); if (constructorParams.length > 0 && constructorParams[0].getFeatureType() instanceof IBlockType ) { try { IGosuParser parser = GosuParserFactory.createParser( "\\ -> new java.util.ArrayList()" ); IExpression expr = parser.parseExp( new TypelessScriptPartId( "Xml Schema autocreate block" ) ); Object block = expr.evaluate(); return constructor.getConstructor().newInstance(block); } catch (Exception e) { throw new RuntimeException(e); } } } } return autocreateTypeInfo.getConstructor().getConstructor().newInstance(); }
private WsdlFault createWsdlFault( Throwable cause, String message ) { final XmlElement detailElement = (XmlElement) _detailElementType.get().getTypeInfo().getConstructor().getConstructor().newInstance(); StaticallyTypedWsdlFaultImpl fault = new StaticallyTypedWsdlFaultImpl( message, cause, getType() ); fault.setCode( WsdlFault.FaultCode.Sender ); fault.setDetail( detailElement ); return fault; }
@Override public XmlElement wrap( Object obj, XmlElement listElement ) { IType componentElementType = _componentParamInfo.getParameterElementType(); @SuppressWarnings( {"unchecked"} ) List<Object> list = (List<Object>) obj; for ( Object child : list ) { XmlElement childElement = (XmlElement) componentElementType.getTypeInfo().getConstructor().getConstructor().newInstance(); if ( child == null ) { childElement.setNil( true ); } else { childElement = _componentParamInfo.wrap( child, childElement ); } listElement.addChild( childElement ); } return listElement; }
private Object constructPort( Object arg ) { QName serviceQName = _service.getQName(); QName portQName = _wsdlDefPort.getQName(); IWsdlConfig config = (IWsdlConfig) arg; if ( config == null ) { config = (IWsdlConfig) _wsdlConfigType.get().getTypeInfo().getConstructor().getConstructor().newInstance(); } configure( serviceQName, portQName, config ); return new WsdlPortImpl( getType(), _resourceFile, serviceQName, getWsdl(), portQName, config, _wsdlDefPort ); }
protected XmlElement( QName qname, IType type, IType schemaDefinedTypeInstanceType, XmlTypeInstance typeInstance ) { _type = type; XmlElementInternals.instance().validateQName( qname ); _schemaDefinedTypeInstanceType = XmlElementInternals.instance().isAnyType( schemaDefinedTypeInstanceType ) ? null : schemaDefinedTypeInstanceType; if ( typeInstance == null ) { if ( _schemaDefinedTypeInstanceType == null ) { typeInstance = new AnyType(); } else { typeInstance = (XmlTypeInstance) _schemaDefinedTypeInstanceType.getTypeInfo().getConstructor().getConstructor().newInstance(); } } _qname = qname; setTypeInstance( typeInstance ); }
private TestEnvironment createTestEnvironment(String[] pathComponents) { // TODO - AHK - Error handling // TODO - AHK - Validate that it's actually a TestEnvironment // TODO - AHK - Handle the case where there's no appropriate constructor String typeName = constructTypeName(pathComponents, 0, pathComponents.length - 2); String[] constructorArgs = splitArgs(pathComponents[pathComponents.length - 2]); IType testEnvironmentType = TypeSystem.getByFullName(typeName); TestEnvironment testEnvironment = null; for (IConstructorInfo cons : testEnvironmentType.getTypeInfo().getConstructors()) { if (cons.getParameters().length == constructorArgs.length) { Object[] convertedArgs = convertConstructorArgs(constructorArgs, cons.getParameters()); testEnvironment = (TestEnvironment) cons.getConstructor().newInstance(convertedArgs); break; } } return testEnvironment; }
private void addSimpleContent( Object newValue, XmlBase parentElement, XmlElement child, XmlSchemaPropertySpec prop ) { if ( child == null ) { IType xmlElementType = XmlSchemaIndex.getGosuTypeBySchemaObject( prop.getXmlSchemaObject() ); child = (XmlElement) xmlElementType.getTypeInfo().getConstructor().getConstructor().newInstance(); parentElement.addChild( child ); } final XmlSchemaTypeSchemaInfo schemaInfo = XmlSchemaIndex.getSchemaInfoByType( child.getTypeInstance().getIntrinsicType() ); XmlSimpleValue storageValue = gosuValueToStorageValue( prop, schemaInfo, newValue ); child.setSimpleValue( storageValue ); }
@Override public XmlElement wrap( Object array, XmlElement listElement ) { IType componentElementType = _componentParamInfo.getParameterElementType(); int size = _componentParamInfo.getType().getArrayLength( array ); for ( int i = 0; i < size; i++ ) { Object child = _componentParamInfo.getType().getArrayComponent( array, i ); XmlElement childElement = (XmlElement) componentElementType.getTypeInfo().getConstructor().getConstructor().newInstance(); if ( child == null ) { childElement.setNil( true ); } else { childElement = _componentParamInfo.wrap( child, childElement ); } listElement.addChild( childElement ); } return listElement; }