예제 #1
0
        public static ImmutableModel Import(string uri, DiagnosticBag diagnostics = null)
        {
            SoalImporter importer = new SoalImporter(diagnostics);

            importer.ImportFile(uri);
            if (importer.Diagnostics.HasAnyErrors())
            {
                return(importer.Model.ToImmutable());
            }
            LoadImportedFiles(importer);
            if (importer.Diagnostics.HasAnyErrors())
            {
                return(importer.Model.ToImmutable());
            }
            importer.Model.EvaluateLazyValues();
            RemoveTypes(importer);
            foreach (var fileUri in importer.readers.Keys)
            {
                if (!importer.Diagnostics.AsEnumerable().Any(d => d.Location.GetLineSpan().Path == fileUri && d.Severity == DiagnosticSeverity.Error))
                {
                    importer.AddInfo("File successfully imported.", fileUri, default);
                }
                else
                {
                    importer.AddError("Could not import file.", fileUri, default);
                }
            }
            return(importer.Model.ToImmutable());
        }
예제 #2
0
 private static void RemoveTypes(SoalImporter importer)
 {
     foreach (var type in importer.typesToRemove)
     {
         DeclarationBuilder decl = type as DeclarationBuilder;
         if (decl != null)
         {
             int count = 0;
             importer.referenceCounter.TryGetValue(type, out count);
             if (count <= 0)
             {
                 decl.Namespace = null;
                 importer.Model.RemoveSymbol(decl);
             }
         }
     }
 }
예제 #3
0
        private void CheckXsdTypes()
        {
            var types = this.Model.Symbols.OfType <StructBuilder>().ToList();

            foreach (var type in types)
            {
                foreach (var prop in type.Properties)
                {
                    if (prop.Type == null || prop.Type.GetCoreType() == null)
                    {
                        XElement elem = this.XsdTypes.GetX(type);
                        string   uri  = "";
                        if (elem != null)
                        {
                            uri = elem.BaseUri;
                        }
                        this.AddError("The property '" + type.Name + "." + prop.Name + "' has no type.", uri, SoalImporter.GetLinePositionSpan(elem));
                    }
                    else
                    {
                        SoalTypeBuilder originalType = null;
                        if (this.originalTypes.TryGetValue((ISymbol)prop, out originalType))
                        {
                            if (originalType is AnnotatedElementBuilder && ((AnnotatedElementBuilder)originalType).HasAnnotation(SoalAnnotations.Restriction))
                            {
                                SoalImporter.CopyAnnotation(SoalAnnotations.Restriction, ((AnnotatedElementBuilder)originalType), prop);
                            }
                            if (originalType is StructBuilder)
                            {
                                object wrapped = ((StructBuilder)originalType).GetAnnotationPropertyValue(SoalAnnotations.Type, SoalAnnotationProperties.Wrapped) ?? false;
                                if ((bool)wrapped)
                                {
                                    SoalImporter.CopyAnnotationProperty(SoalAnnotations.Type, SoalAnnotationProperties.Wrapped, ((AnnotatedElementBuilder)originalType), SoalAnnotations.Element, SoalAnnotationProperties.Wrapped, prop);
                                    SoalImporter.CopyAnnotationProperty(SoalAnnotations.Type, SoalAnnotationProperties.Items, ((AnnotatedElementBuilder)originalType), SoalAnnotations.Element, SoalAnnotationProperties.Items, prop);
                                    SoalImporter.CopyAnnotationProperty(SoalAnnotations.Type, SoalAnnotationProperties.Sap, ((AnnotatedElementBuilder)originalType), SoalAnnotations.Element, SoalAnnotationProperties.Sap, prop);
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #4
0
 private static void LoadImportedFiles(SoalImporter importer)
 {
     for (int i = 0; i < XsdReader.PhaseCount; i++)
     {
         foreach (var reader in importer.readers)
         {
             foreach (var r in reader.Value)
             {
                 r.LoadXsdFile(i);
             }
         }
     }
     importer.CheckXsdTypes();
     for (int i = 0; i < WsdlReader.PhaseCount; i++)
     {
         foreach (var reader in importer.readers)
         {
             foreach (var r in reader.Value)
             {
                 r.LoadWsdlFile(i);
             }
         }
     }
 }
예제 #5
0
        internal TObject Register(Importer.XmlReader reader, XName xname, TXObject xobj, TObject obj, bool allowReverse = true)
        {
            TObject oldObject = null;

            if (this.objectsByName.TryGetValue(xname, out oldObject))
            {
                TXObject oldElem = this.elementsByObject[oldObject];
                this.importer.AddError("The " + this.name + " '" + xname + "' is already imported from '" + oldElem.BaseUri + "' at '" + SoalImporter.GetLinePositionSpan(oldElem) + "'.", reader.Uri, SoalImporter.GetLinePositionSpan(xobj));
                return(null);
            }
            if (this.objectsByElement.TryGetValue(xobj, out oldObject))
            {
                TXObject oldElem = this.elementsByObject[oldObject];
                this.importer.AddError("The " + this.name + " '" + xname + "' has already an object assigned to it.", reader.Uri, SoalImporter.GetLinePositionSpan(xobj));
                return(null);
            }
            TXObject oldXObject = null;

            if (this.elementsByName.TryGetValue(xname, out oldXObject))
            {
                this.importer.AddError("The " + this.name + " '" + xname + "' is already registered to '" + oldXObject.BaseUri + "' at '" + SoalImporter.GetLinePositionSpan(oldXObject) + "'.", reader.Uri, SoalImporter.GetLinePositionSpan(xobj));
                return(null);
            }
            this.objectsByName.Add(xname, obj);
            this.objectsByElement.Add(xobj, obj);
            this.elementsByName.Add(xname, xobj);
            if (allowReverse)
            {
                if (this.elementsByObject.TryGetValue(obj, out oldXObject))
                {
                    this.importer.AddError("The object is alredy registered to " + this.name + " in '" + oldXObject.BaseUri + "' at '" + SoalImporter.GetLinePositionSpan(oldXObject) + "'.", reader.Uri, SoalImporter.GetLinePositionSpan(xobj));
                    return(null);
                }
                if (!this.elementsByObject.ContainsKey(obj))
                {
                    this.elementsByObject.Add(obj, xobj);
                }
            }
            return(obj);
        }
예제 #6
0
 public ObjectStorage(string name, SoalImporter importer)
 {
     this.name     = name;
     this.importer = importer;
 }