@Override public boolean isValid() { for( IType type : _types ) { if( !type.isValid() ) { return false; } } return true; }
@Override public boolean isValid() { for( IType type : _types ) { if( !type.isValid() ) { return false; } } return true; }
private Throwable getCompileError(IType type) { if (type instanceof IGosuClass) { type.isValid(); // just in case there has been a typesystem refresh, to ensure there is a PRE return ((IGosuClass)type).getParseResultsException(); } else { return new IllegalStateException("Test type " + type + " is not valid."); } }
public static ParseResultsException defnCompileAndGetClassErrors( IType type ) { assert type instanceof IGosuClass; try { type.isValid(); // ensures type is defn compiled } catch( Exception ex ) { // ignore } return ((IGosuClass)type).getParseResultsException(); } }
public static MarshalInfo addType( IType type, LocalElement element, WsiServiceInfo serviceInfo ) throws Exception { MarshalInfo marshalInfo = getMarshalInfo( type, false, serviceInfo ); if ( ! type.isValid() ) { throw new RuntimeException( "Type " + type + " is not valid" ); } else if (marshalInfo == null) { throw new IllegalStateException( "XmlMarshaller doesn't know how to handle " + type.getName() ); } else { marshalInfo.addType( element, serviceInfo ); } return marshalInfo; }
private static void ensureTypeIsValid( IType type ) { if( !type.isValid() ) { if( type instanceof IGosuClass ) { //noinspection ThrowableResultOfMethodCallIgnored throw new IllegalArgumentException( "The type " + type.getName() + " is invalid", ((IGosuClass)type).getParseResultsException() ); } else { throw new IllegalArgumentException( "The type " + type.getName() + " is invalid" ); } } }
/** This will create an object from the xml element. There are several marshalling * attributes that will affect this behavior. * * @param type the type desired * @param parameterElement the element to unmarshal * @param context the context for this unmarshalling * @return the create and populated object */ public Object unmarshal(IType type, XmlElement parameterElement, UnmarshalContext context) { if ( parameterElement == null ) { // null return null; } else { // not null MarshalInfo marshalInfo = XmlMarshaller.getMarshalInfo( type, null ); if (marshalInfo == null) { throw new RuntimeException("Could not get a marshal for " + type); } else if (!type.isValid()) { throw new RuntimeException("Type " + type + " is not valid"); } else { return marshalInfo.unmarshal( parameterElement, context ); } } }
private static void ensureTypeIsValid( IType type ) { if( !type.isValid() ) { if( type instanceof IGosuClass ) { //noinspection ThrowableResultOfMethodCallIgnored throw new IllegalArgumentException( "The type " + type.getName() + " is invalid", ((IGosuClass)type).getParseResultsException() ); } else { throw new IllegalArgumentException( "The type " + type.getName() + " is invalid" ); } } }
/** This will create elements for the type in the target. * * @param parameterElement where to write the value * @param type the expected type of the object (e.g., may be an interface) * @param obj the actual object * @param context the context for this marshalling */ public void marshal(XmlElement parameterElement, IType type, Object obj, MarshalContext context) { MarshalInfo marshalInfo = XmlMarshaller.getMarshalInfo( type, null ); if ( marshalInfo == null ) { throw new IllegalArgumentException( "Marshal/unmarshal of " + type.getName() + " is not supported" ); } else if (!type.isValid()) { throw new RuntimeException("Type " + type + " is not valid"); } marshalInfo.marshal( parameterElement, type, obj, context); }
@Override public void checkType(Marshaller marshaller, IParsedElement parsedElement, String label, IType type, Map<String, Object> seenNamespaces) { if (!type.isValid() && !type.equals(_type)) { parsedElement.addParseException(Res.WS_ERR_Can_Not_Marshal, type.getDisplayName(), label ); } else { for (Map.Entry<String,IPropertyInfo> prop : getProperties(type).entrySet()) { String newLabel = label + (label.equals("") ? "" : ".") + prop.getKey(); IType partType = prop.getValue().getFeatureType(); if (!_type.equals(partType) && isExportable(partType)) { // do not recurse } else if (_type.equals(getComponentType(partType))) { // test this before recursing into checkType parsedElement.addParseWarning(Res.WS_ERR_Export_Recursive, newLabel ); } else { MarshalInfo marshalInfo = marshaller.checkType(parsedElement, newLabel, prop.getValue().getFeatureType(), seenNamespaces); checkMarshalInfoType(parsedElement, prop, newLabel, marshalInfo); } } } }
@Override public void checkType(Marshaller marshaller, IParsedElement parsedElement, String label, IType type, Map<String, Object> seenNamespaces) { if (!type.isValid() && !type.equals(_type)) { parsedElement.addParseException(Res.WS_ERR_Can_Not_Marshal, type.getDisplayName(), label ); } else { for (Map.Entry<String,IPropertyInfo> prop : getProperties(type).entrySet()) { String newLabel = label + (label.equals("") ? "" : ".") + prop.getKey(); IType partType = prop.getValue().getFeatureType(); if (!_type.equals(partType) && isExportable(partType)) { // do not recurse } else if (_type.equals(getComponentType(partType))) { // test this before recursing into checkType parsedElement.addParseWarning(Res.WS_ERR_Export_Recursive, newLabel ); } else { MarshalInfo marshalInfo = marshaller.checkType(parsedElement, newLabel, prop.getValue().getFeatureType(), seenNamespaces); checkMarshalInfoType(parsedElement, prop, newLabel, marshalInfo); } } } }
private void addImplicitCapturedSymbolParamTypes( IType owningType, List<IRType> paramTypes ) { // Captured symbols // Don't attempt to get captured symbols if the type isn't valid; it'll just throw and result in a cascading break if( owningType instanceof IGosuClassInternal && owningType.isValid() ) //&& ((IGosuClassInternal)type).isAnonymous() ) { Map<String, ICapturedSymbol> capturedSymbols = ((IGosuClassInternal)owningType).getCapturedSymbols(); if( capturedSymbols != null ) { for( ICapturedSymbol sym : capturedSymbols.values() ) { paramTypes.add( IRTypeResolver.getDescriptor( sym.getType().getArrayType() ) ); } } } // The external symbols are always treated as captured if (AbstractElementTransformer.requiresExternalSymbolCapture( owningType ) ) { paramTypes.add( IRTypeResolver.getDescriptor( IExternalSymbolMap.class ) ); } }
private void addImplicitCapturedSymbolParamTypes( IType owningType, List<IRType> paramTypes ) { // Captured symbols // Don't attempt to get captured symbols if the type isn't valid; it'll just throw and result in a cascading break if( owningType instanceof IGosuClassInternal && owningType.isValid() ) //&& ((IGosuClassInternal)type).isAnonymous() ) { Map<String, ICapturedSymbol> capturedSymbols = ((IGosuClassInternal)owningType).getCapturedSymbols(); if( capturedSymbols != null ) { for( ICapturedSymbol sym : capturedSymbols.values() ) { paramTypes.add( IRTypeResolver.getDescriptor( sym.getType().getArrayType() ) ); } } } // The external symbols are always treated as captured if (AbstractElementTransformer.requiresExternalSymbolCapture( owningType ) ) { paramTypes.add( IRTypeResolver.getDescriptor( IExternalSymbolMap.class ) ); } }
private static void verifyType( boolean includeWarnings, ArrayList<IVerificationResults> errors, Object o, CharSequence typeName ) { try { IType type = TypeSystem.getByFullNameIfValid( o.toString() ); if( type instanceof ITemplateType ) { ITemplateGenerator generator = ((ITemplateType) type).getTemplateGenerator(); try { generator.verify(GosuParserFactory.createParser(null)); } catch ( ParseResultsException e) { errors.add( new GosuTypeVerificationResults( typeName.toString(), e.getParseIssues() ) ); } } else if( type instanceof IGosuClass ) { boolean valid = type.isValid(); List<IParseIssue> parseIssues = ((IGosuClass)type).getClassStatement().getParseIssues(); if( parseIssues.size() > 0 && (!valid || includeWarnings) ) { errors.add( new GosuTypeVerificationResults( typeName.toString(), parseIssues ) ); } } } catch( Throwable e ) { errors.add( new ExceptionTypeVerificationResults( typeName.toString(), e.getMessage() ) ); } }
public static String checkWebServiceForErrors( IType type ) { if ( type == null ) { return "Null webservice type"; } ITypeInfo typeInfo = type.getTypeInfo(); if ( !( type instanceof IGosuClass ) ) { return "Type is not a Gosu class"; } if ( !( typeInfo.hasAnnotation( _wsiWebServiceAnnotationType.get() ) ) ) { return "Type does not have @WsiWebService annotation"; } if ( !type.isValid() ) { IGosuClass clazz = (IGosuClass) type; //noinspection ThrowableResultOfMethodCallIgnored return "Type is not valid." + ( clazz.getParseResultsException() == null ? "" : ( "\n\n" + GosuExceptionUtil.getStackTraceAsString( clazz.getParseResultsException() ) ) ); } return null; }
protected List<IGosuAnnotation> getGosuAnnotations() { ReducedDynamicFunctionSymbol dfs = getDfs(); if( dfs instanceof ReducedDelegateFunctionSymbol ) { IMethodInfo miTarget = ((ReducedDelegateFunctionSymbol)dfs).getTargetMethodInfo(); if( miTarget != this && miTarget instanceof AbstractGenericMethodInfo ) { if( getOwnersType().isCompiled() ) { // Ensure the delegate's owner is fully compiled, otherwise the annotations won't be fully formed (have NewExpressions, see PL-21981) miTarget.getOwnersType().isValid(); } return ((AbstractGenericMethodInfo)miTarget).getGosuAnnotations(); } } return super.getGosuAnnotations(); }
protected List<IGosuAnnotation> getGosuAnnotations() { ReducedDynamicFunctionSymbol dfs = getDfs(); if( dfs instanceof ReducedDelegateFunctionSymbol ) { IMethodInfo miTarget = ((ReducedDelegateFunctionSymbol)dfs).getTargetMethodInfo(); if( miTarget != this && miTarget instanceof AbstractGenericMethodInfo ) { if( getOwnersType().isCompiled() ) { // Ensure the delegate's owner is fully compiled, otherwise the annotations won't be fully formed (have NewExpressions, see PL-21981) miTarget.getOwnersType().isValid(); } return ((AbstractGenericMethodInfo)miTarget).getGosuAnnotations(); } } return super.getGosuAnnotations(); }
protected void pushCapturedSymbols( IType type, List<IRExpression> args, boolean ignoreExternalSymbols ) { if( type instanceof IGosuClassInternal && type.isValid() ) //&& ((IGosuClassInternal)type).isAnonymous() ) { Map<String, ICapturedSymbol> capturedSymbols = ((IGosuClassInternal)type).getCapturedSymbols(); if( capturedSymbols != null ) { for( ICapturedSymbol sym : capturedSymbols.values() ) { if( isCapturedOnEnclosingAnonymousClass( sym, (IGosuClassInternal)type ) ) { args.add( getInstanceField( getGosuClass(), CAPTURED_VAR_PREFIX + sym.getName(), getDescriptor( sym.getType().getArrayType() ), AccessibilityUtil.forSymbol((IReducedSymbol) sym), pushThis())); } else { args.add( identifier( _cc().getSymbol(sym.getName() ) ) ); } } } } if ( !ignoreExternalSymbols && requiresExternalSymbolCapture( type ) /* && !inStaticContext() */ ) { args.add( pushExternalSymbolsMap() ); } }
protected void pushCapturedSymbols( IType type, List<IRExpression> args, boolean ignoreExternalSymbols ) { if( type instanceof IGosuClassInternal && type.isValid() ) //&& ((IGosuClassInternal)type).isAnonymous() ) { Map<String, ICapturedSymbol> capturedSymbols = ((IGosuClassInternal)type).getCapturedSymbols(); if( capturedSymbols != null ) { for( ICapturedSymbol sym : capturedSymbols.values() ) { if( isCapturedOnEnclosingAnonymousClass( sym, (IGosuClassInternal)type ) ) { args.add( getInstanceField( getGosuClass(), CAPTURED_VAR_PREFIX + sym.getName(), getDescriptor( sym.getType().getArrayType() ), AccessibilityUtil.forSymbol((IReducedSymbol) sym), pushThis())); } else { args.add( identifier( _cc().getSymbol(sym.getName() ) ) ); } } } } if ( !ignoreExternalSymbols && requiresExternalSymbolCapture( type ) /* && !inStaticContext() */ ) { args.add( pushExternalSymbolsMap() ); } }
private TestCase makeTest(final IType type, String method) { try { TestClass test; if (type.isValid()) { ITypeInfo typeInfo = type.getTypeInfo(); IConstructorInfo noArgCons = typeInfo.getConstructor(); if (noArgCons != null) { test = (TestClass) noArgCons.getConstructor().newInstance(); } else { IConstructorInfo oneArgCons = typeInfo.getConstructor(JavaTypes.STRING()); if (oneArgCons != null) { test = (TestClass) oneArgCons.getConstructor().newInstance(method); } else { throw new IllegalStateException("Test type " + type + " does not have either a no-arg constructor or a one-arg constructor taking a String"); } } } else { test = new InvalidTestClass(_type); } test.setExecutionManager( _executionManager ); test.setName(method); test.setGosuTest(_type instanceof IGosuClass); test.initMetadata( method ); return test; } catch (final Exception e) { e.printStackTrace(); return new ExceptionTestClass(type, e.getMessage()); } }