Fix source code using Java

Any idea how to detect the source code (Java, C #, SQL, etc.) in a Java text file without looking at the file extension or using an unusual long, self-made regular expression?

Perhaps there are some tools that are already doing this work?

+5
source share
4 answers

Linguist

We use this library on GitHub to detect blob languages, highlight code, ignore binary files, suppress generated files in diff and generate graphs for splitting the language.

Unfortunately, this is written in Ruby, maybe JRuby can handle this?

+2
source

, ( ), . , , .

+1

. , , , . , , (SourceCode = true , , SourceCode = false , ). , , , , .

+1

There is an old library, http://sourceforge.net/projects/jmimemagic/ try it, I hope it can give satisfactory results.

+1
source

All Articles