本文整理汇总了C#中Analyzer类的典型用法代码示例。如果您正苦于以下问题:C# Analyzer类的具体用法?C# Analyzer怎么用?C# Analyzer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Analyzer类属于命名空间,在下文中一共展示了Analyzer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main(String[] args)
{
try
{
ITransformer transformer = new Transformer();
IReader reader = new ConsoleReader();
IAnalyzer analyzer = new Analyzer(reader, transformer);
AnalysisResult analysisResult = analyzer.Analyze();
IDumper fileDumper = new ConsoleDumper(analysisResult);
// A better way to inform about the result would be an Enum with some codes (error dumping, error reading, error connecting to db, etc)
bool operationFinished = fileDumper.Dump();
string message = "";
if (operationFinished) { message = ""; }
else { message = "The application encountered an error. Please check the logs. Press Enter to exit."; }
Console.WriteLine(message);
Console.ReadLine();
}
catch (Exception ex)
{
ex.Log("");
Console.WriteLine("The application encountered an error. Please check the logs. Press Enter to exit.");
Console.ReadLine();
}
}
示例2: IsArcValid
public static bool IsArcValid (Movement from, Analyzer.Node.Movement to) {
if (from == Movement.Unknown) {
return
to == Analyzer.Node.Movement.JustDown ||
to == Analyzer.Node.Movement.JustDownOrStayDown;
} else if (from == Movement.Tap) {
return
to == Analyzer.Node.Movement.JustDown ||
to == Analyzer.Node.Movement.JustDownOrStayDown;
} else if (from == Movement.ForceDownStart) {
return
to == Analyzer.Node.Movement.StayDown ||
to == Analyzer.Node.Movement.Relax;
} else if (from == Movement.ForceDown) {
return
to == Analyzer.Node.Movement.StayDown ||
to == Analyzer.Node.Movement.Relax;
} else if (from == Movement.PassiveDown) {
return
to == Analyzer.Node.Movement.JustDown ||
to == Analyzer.Node.Movement.JustDownOrStayDown;
} else {
throw new ArgumentException();
}
}
示例3: Analyze
internal override Evaluation Analyze(Analyzer/*!*/ analyzer, ExInfoFromParent info)
{
analyzer.AddCurrentRoutineProperty(RoutineProperties.ContainsLocalsWorker);
body.Analyze(analyzer);
return new Evaluation(this);
}
示例4: QueryTermVector
public QueryTermVector(System.String queryString, Analyzer analyzer)
{
if (analyzer != null)
{
TokenStream stream = analyzer.TokenStream("", new System.IO.StringReader(queryString));
if (stream != null)
{
IList<string> terms = new List<string>();
try
{
bool hasMoreTokens = false;
stream.Reset();
ITermAttribute termAtt = stream.AddAttribute<ITermAttribute>();
hasMoreTokens = stream.IncrementToken();
while (hasMoreTokens)
{
terms.Add(termAtt.Term);
hasMoreTokens = stream.IncrementToken();
}
ProcessTerms(terms.ToArray());
}
catch (System.IO.IOException)
{
}
}
}
}
示例5: IsArcValid
public static bool IsArcValid (Part from, Analyzer.Node.Part to) {
if (to == null) { return true; }
if (!MovementHelper.IsArcValid(from.movement, to.movement)) {
return false;
}
//Transition is valid if we consider movement only
//Consider hold notes
if (from.movement == Movement.ForceDownStart) {
if (to.movement == Analyzer.Node.Movement.StayDown) {
return from.panel == to.panel; //Continue hold note
} else if (to.movement == Analyzer.Node.Movement.Relax) {
return from.panel == to.panel; //End hold note
} else {
throw new ArgumentException();
}
} else if (from.movement == Movement.ForceDown) {
if (to.movement == Analyzer.Node.Movement.StayDown) {
return from.panel == to.panel; //Continue hold note
} else if (to.movement == Analyzer.Node.Movement.Relax) {
return from.panel == to.panel; //End continued hold note
} else {
throw new ArgumentException();
}
}
return true;
}
示例6: TransitionTo
public static Part TransitionTo (Part from, Analyzer.Node.Part to, float cur_second) {
if (!IsArcValid(from, to)) {
throw new ArgumentException();
}
if (to == null) {
throw new ArgumentException();
/*return new Part(
from.movement,
from.panel,
cur_second,
from.cur_moved_second,
from.prv_moved_second
);*/
} else {
Movement nxt_movement = MovementHelper.TransitionTo(from.movement, to.movement);
if (nxt_movement == Movement.PassiveDown) {
if (from.movement == Movement.PassiveDown) {
return new Part(nxt_movement, from.panel, cur_second, from.cur_moved_second, from.prv_moved_second);
} else {
return new Part(nxt_movement, from.panel, cur_second, cur_second, from.cur_moved_second);
}
} else {
return new Part(nxt_movement, to.panel, cur_second, cur_second, from.cur_moved_second);
}
}
}
示例7: Initialize
public override void Initialize(AnalysisContext analysisContext)
{
// this is stateless analyzer, can run concurrently
analysisContext.EnableConcurrentExecution();
// this has no meaning on running on generated code which user can't control
analysisContext.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
analysisContext.RegisterCompilationStartAction(c =>
{
INamedTypeSymbol @string = WellKnownTypes.String(c.Compilation);
INamedTypeSymbol uri = WellKnownTypes.Uri(c.Compilation);
if (@string == null || uri == null)
{
// we don't have required types
return;
}
var analyzer = new Analyzer(c.Compilation, @string, uri, GetInvocationExpression);
// REVIEW: I need to do this thing because OperationAnalysisContext doesn't give me OwningSymbol
c.RegisterOperationBlockStartAction(sc =>
{
sc.RegisterOperationAction(oc => analyzer.Analyze(oc, sc.OwningSymbol), OperationKind.InvocationExpression);
});
});
}
示例8: Main
public static void Main(string[] args)
{
string inputname = args[0];
string outputname = args[1];
string[] lines = File.ReadAllLines(inputname);
int ncases = int.Parse(lines[0]);
int nline = 0;
IList<string> results = new List<string>();
Analyzer analyzer = new Analyzer();
for (int k = 0; k < ncases; k++)
{
Console.WriteLine(string.Format("Solving Case #{0}", k + 1));
nline++;
string[] words = lines[nline].Split(' ');
string text = words[0];
int length = int.Parse(words[1]);
int count = analyzer.Count(text, length);
results.Add(string.Format("Case #{0}: {1}", k + 1, count));
}
File.WriteAllLines(outputname, results.ToArray());
}
示例9: NoReportItems
public void NoReportItems()
{
analyzer = new Analyzer(CreateMockParser(0));
Assert.AreEqual(0, analyzer.ActualReportItems.Count);
analyzer.Run();
Assert.AreEqual(0, analyzer.ExpectedReportItems.Count);
}
示例10: SetUp
/// <summary>
/// Set up a new index in RAM with three test phrases and the supplied Analyzer.
/// </summary>
/// <exception cref="Exception"> if an error occurs with index writer or searcher </exception>
public override void SetUp()
{
base.SetUp();
analyzer = new ShingleAnalyzerWrapper(new MockAnalyzer(Random(), MockTokenizer.WHITESPACE, false), 2);
directory = NewDirectory();
IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(TEST_VERSION_CURRENT, analyzer));
Document doc;
doc = new Document();
doc.Add(new TextField("content", "please divide this sentence into shingles", Field.Store.YES));
writer.AddDocument(doc);
doc = new Document();
doc.Add(new TextField("content", "just another test sentence", Field.Store.YES));
writer.AddDocument(doc);
doc = new Document();
doc.Add(new TextField("content", "a sentence which contains no test", Field.Store.YES));
writer.AddDocument(doc);
writer.Dispose();
reader = DirectoryReader.Open(directory);
searcher = NewSearcher(reader);
}
示例11: Analyze
internal override Evaluation Analyze(Analyzer/*!*/ analyzer, ExInfoFromParent info)
{
access = info.Access;
Evaluation cond_eval = condExpr.Analyze(analyzer, ExInfoFromParent.DefaultExInfo);
if (cond_eval.HasValue)
{
if (Convert.ObjectToBoolean(cond_eval.Value))
{
if (trueExpr != null)
return trueExpr.Analyze(analyzer, ExInfoFromParent.DefaultExInfo);
else
return cond_eval; // condExpr ?: falseExpr // ternary shortcut
}
else
return falseExpr.Analyze(analyzer, ExInfoFromParent.DefaultExInfo);
}
else
{
if (trueExpr != null)
{
analyzer.EnterConditionalCode();
trueExpr = trueExpr.Analyze(analyzer, ExInfoFromParent.DefaultExInfo).Literalize();
analyzer.LeaveConditionalCode();
}
analyzer.EnterConditionalCode();
falseExpr = falseExpr.Analyze(analyzer, ExInfoFromParent.DefaultExInfo).Literalize();
analyzer.LeaveConditionalCode();
return new Evaluation(this);
}
}
示例12: Analyze
/// <include file='Doc/Nodes.xml' path='doc/method[@name="Expression.Analyze"]/*'/>
internal override Evaluation Analyze(Analyzer/*!*/ analyzer, ExInfoFromParent info)
{
access = info.Access;
ExInfoFromParent operand_info = ExInfoFromParent.DefaultExInfo;
Evaluation left_eval = leftExpr.Analyze(analyzer, operand_info);
Evaluation right_eval;
// Boolean expression evaluation semantics:
if (operation == Operations.Or)
{
analyzer.EnterConditionalCode();
right_eval = rightExpr.Analyze(analyzer, operand_info);
analyzer.LeaveConditionalCode();
}
else
{
right_eval = rightExpr.Analyze(analyzer, operand_info);
}
Evaluation result = Evaluation.Evaluate(this, left_eval, out leftExpr, right_eval, out rightExpr);
// division by zero check:
if ((operation == Operations.Div || operation == Operations.Mod) && result.HasValue && result.Value is bool && (bool)result.Value == false)
{
analyzer.ErrorSink.Add(Warnings.DivisionByZero, analyzer.SourceUnit, rightExpr.Position);
}
else if ((operation == Operations.Div || operation == Operations.Mod) && right_eval.HasValue && right_eval.Value is int && (int)right_eval.Value == 0)
{
result = new Evaluation(this, false);
analyzer.ErrorSink.Add(Warnings.DivisionByZero, analyzer.SourceUnit, rightExpr.Position);
}
return result;
}
示例13: Analyze
internal override Evaluation Analyze(Analyzer/*!*/ analyzer, ExInfoFromParent info)
{
bool already_resolved = constant != null;
if (!already_resolved)
{
access = info.Access;
ResolveName(analyzer);
}
if (constant.IsUnknown)
return new Evaluation(this);
KnownConstant known_const = (KnownConstant)constant;
if (known_const.HasValue)
{
// constant value is known:
return new Evaluation(this, known_const.Value);
}
else if (already_resolved)
{
// circular definition:
constant.ReportCircularDefinition(analyzer.ErrorSink);
return new Evaluation(this);
}
else
{
// value is not known yet, try to resolve it:
if (known_const.Node != null)
known_const.Node.Analyze(analyzer);
return (known_const.HasValue) ? new Evaluation(this, known_const.Value) : new Evaluation(this);
}
}
示例14: GetAnalyzer
protected override Analyzer GetAnalyzer(CompilationStartAnalysisContext context, CompilationSecurityTypes types, Version targetFrameworkVersion)
{
Analyzer analyzer = new Analyzer(types, CSharpSyntaxNodeHelper.Default, targetFrameworkVersion);
context.RegisterSyntaxNodeAction(analyzer.AnalyzeNode, SyntaxKind.MethodDeclaration, SyntaxKind.ConstructorDeclaration);
return analyzer;
}
开发者ID:Anniepoh,项目名称:roslyn-analyzers,代码行数:7,代码来源:CSharpDoNotUseInsecureDtdProcessingInApiDesigner.cs
示例15: ShingleAnalyzerWrapper
/// <summary>
/// Creates a new ShingleAnalyzerWrapper
/// </summary>
/// <param name="delegate"> Analyzer whose TokenStream is to be filtered </param>
/// <param name="minShingleSize"> Min shingle (token ngram) size </param>
/// <param name="maxShingleSize"> Max shingle size </param>
/// <param name="tokenSeparator"> Used to separate input stream tokens in output shingles </param>
/// <param name="outputUnigrams"> Whether or not the filter shall pass the original
/// tokens to the output stream </param>
/// <param name="outputUnigramsIfNoShingles"> Overrides the behavior of outputUnigrams==false for those
/// times when no shingles are available (because there are fewer than
/// minShingleSize tokens in the input stream)?
/// Note that if outputUnigrams==true, then unigrams are always output,
/// regardless of whether any shingles are available. </param>
/// <param name="fillerToken"> filler token to use when positionIncrement is more than 1 </param>
public ShingleAnalyzerWrapper(Analyzer @delegate, int minShingleSize, int maxShingleSize,
string tokenSeparator, bool outputUnigrams, bool outputUnigramsIfNoShingles, string fillerToken)
: base(@delegate.Strategy)
{
[email protected] = @delegate;
if (maxShingleSize < 2)
{
throw new ArgumentOutOfRangeException("Max shingle size must be >= 2");
}
this.maxShingleSize = maxShingleSize;
if (minShingleSize < 2)
{
throw new ArgumentOutOfRangeException("Min shingle size must be >= 2");
}
if (minShingleSize > maxShingleSize)
{
throw new ArgumentOutOfRangeException("Min shingle size must be <= max shingle size");
}
this.minShingleSize = minShingleSize;
this.tokenSeparator = (tokenSeparator == null ? "" : tokenSeparator);
this.outputUnigrams = outputUnigrams;
this.outputUnigramsIfNoShingles = outputUnigramsIfNoShingles;
this.fillerToken = fillerToken;
}