~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/Main/Base/Project/Src/Services/ParserService/Doozer/ParserDescriptor.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
 
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
 
3
 
 
4
using System;
 
5
using System.IO;
 
6
using ICSharpCode.Core;
 
7
using ICSharpCode.SharpDevelop.Dom;
 
8
using ICSharpCode.SharpDevelop.Project;
 
9
 
 
10
namespace ICSharpCode.SharpDevelop
 
11
{
 
12
        public sealed class ParserDescriptor
 
13
        {
 
14
                Codon codon;
 
15
                Type parserType;
 
16
                
 
17
                public IParser CreateParser()
 
18
                {
 
19
                        if (codon != null)
 
20
                                return (IParser)codon.AddIn.CreateObject(codon.Properties["class"]);
 
21
                        else
 
22
                                return (IParser)Activator.CreateInstance(parserType);
 
23
                }
 
24
 
 
25
                public string Language { get; private set; }
 
26
 
 
27
                public string[] Supportedextensions { get; private set; }
 
28
 
 
29
                public bool CanParse(string fileName)
 
30
                {
 
31
                        string fileExtension = Path.GetExtension(fileName);
 
32
                        foreach (string ext in Supportedextensions) {
 
33
                                if (string.Equals(fileExtension, ext, StringComparison.OrdinalIgnoreCase)) {
 
34
                                        return true;
 
35
                                }
 
36
                        }
 
37
                        return false;
 
38
                }
 
39
 
 
40
                public ParserDescriptor(Codon codon)
 
41
                {
 
42
                        if (codon == null)
 
43
                                throw new ArgumentNullException("codon");
 
44
                        this.codon = codon;
 
45
                        this.Language = codon.Id;
 
46
                        this.Supportedextensions = codon.Properties["supportedextensions"].Split(';');
 
47
                }
 
48
                
 
49
                public ParserDescriptor(Type parserType, string language, string[] supportedExtensions)
 
50
                {
 
51
                        if (parserType == null)
 
52
                                throw new ArgumentNullException("parserType");
 
53
                        if (language == null)
 
54
                                throw new ArgumentNullException("language");
 
55
                        if (supportedExtensions == null)
 
56
                                throw new ArgumentNullException("supportedExtensions");
 
57
                        this.parserType = parserType;
 
58
                        this.Language = language;
 
59
                        this.Supportedextensions = supportedExtensions;
 
60
                }
 
61
        }
 
62
}