1

On a giving solution in C# (Visual Studio), I need to detect classes that follows some template and extract that template for later code generation.

In other words, I need to compare 2 classes (files) and extract a common template from them. This template will be used for a later code-generation, when the programmer will have to write less code.

Is there any body who can give me an idea on how to do this ?

One more question, is there possible to get the syntactic/semantic tree made by Visual Studio ?

Tnx

mihai.ciorobea
  • 741
  • 5
  • 12

2 Answers2

0

For the first question, I think you should look into diff algorithms to find common parts of 2 text files, e.g. here.

For the second question I would suggest to take a look at Roslyn

dead_ant
  • 124
  • 4
  • Thank you, but what I need is more a Plagiarism Detection like [Moss](http://theory.stanford.edu/~aiken/moss/). The code doesn't need to be exactly identical. – mihai.ciorobea Feb 15 '13 at 13:46
  • Roslyn is ended a good tool, but is only for VS 2012, with no support for VS 2010. Tnx – mihai.ciorobea Feb 15 '13 at 13:47
  • Ah, ok. Perhaps you can compile those files and then load assemblies for analysis via reflection, if you want to do it manually. Or you can use some [tools (link)](http://stackoverflow.com/questions/38635/what-static-analysis-tools-are-available-for-c). And Roslyn has binaries available in [NuGet (link)](http://nuget.org/packages/Roslyn), so it might be used with free Express version of VS 2012 – dead_ant Feb 15 '13 at 14:39
0

Finally I user

  • NRefactory for compiling code and I obtained the AST.
  • rewrite the code using custom labels (eq: for --> loop_start )
  • flatten the tree obtaining a long label array (eq: class_start, method_start,...end, end )
    this was for 2 files
  • I compared the 2 arrays using "greedy string tiling algorithm"
  • and from here I already had the templates files.
mihai.ciorobea
  • 741
  • 5
  • 12