Try to extract java public method

I think I need a program to extract java public methods at work, so I wrote it Try to implement using Java7's NewIO and Java8's Stream functions

JavaFileAnalyser.java



package triple;

import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public class JavaFileAnalyser {
	private static Pattern PATTERN ;
	public static void main(String args[]) throws Exception{
		PATTERN = Pattern.compile(".*public(.*)(?:\\s|\\t)(.*)\\((.*)\\).*");
		
		List<String> list = Files.newBufferedReader(
				Paths.get("C:/Java/jdk1.8.0_102/src/javax/script/AbstractScriptEngine.java"),
				Charset.forName("UTF-8"))
		.lines()
		.filter(JavaFileAnalyser::isMethod)
		.map(JavaFileAnalyser::parse)
		.collect(Collectors.toList());
		
		Files.write(Paths.get("C:/Users/****/workspace/FileOpe/result/result.txt"), 
				list, 
				Charset.forName("UTF8"),
                StandardOpenOption.CREATE);
	}
	
	public static boolean isMethod(String str){
		if(PATTERN.matcher(str).find()){
			return true;
		}
		return false;
	}
	
	public static String parse(String str){
		Matcher m = PATTERN.matcher(str); 
		if(m.find()){
			return String.format("Return signature: %s method name:%s argument:%s",m.group(1),m.group(2),m.group(3));
		}
		return "";
				
	}

}
Return signature:Method name:AbstractScriptEngine argument:
Return signature:AbstractScriptEngine method name:argument:Bindings n
Return signature:void method name:setContext argument:ScriptContext ctxt
Return signature:ScriptContext method name:getContext argument:
Return signature:Bindings method name:getBindings argument:int scope
Return signature:void method name:setBindings argument:Bindings bindings, int scope
Return signature:void method name:put argument:String key, Object value
Return signature:Object method name:get argument:String key
Return signature:Object method name:eval argument:Reader reader, Bindings bindings 
Return signature:Object method name:eval argument:String script, Bindings bindings
Return signature:Object method name:eval argument:Reader reader
Return signature:Object method name:eval argument:String script

It seems that the constructor information has also been acquired, but I will not care about the details (hey)

Recommended Posts

Try to extract java public method
Java method
java (method)
Java to extract PDF text content
[Java] How to use join method
Java method
[Java] Try to implement using generics
[Java] method
Try to implement Yubaba in Java
Try using IBM Java method tracing
[Java] method
Interface Try to make Java problem TypeScript 7-3
Try to solve Project Euler in Java
[Java] How to compare with equals method
Try to implement n-ary addition in Java
How to use submit method (Java Silver)
[Java] How to use the toString () method
Try Java 8 Stream
Method to search
Java8 method reference
[Java] Introduction to Java
Introduction to java
java8 method reference
Roughly try Java 9
[Java] Random method
[Java] split method
Try to build Java8 environment on Amazon Linux2
Try to create a bulletin board in Java
Increment behavior Try to make Java problem TypeScript 3-4
String operation Try to make Java problem TypeScript 9-3
How to use the replace () method (Java Silver)
Try to implement TCP / IP + NIO with JAVA
[Java] Try to solve the Fizz Buzz problem
[Java] How to use compareTo method of Date class
Changes from Java 8 to Java 11
Sum from Java_1 to 100
Try to release gem
JAVA DB connection method
Java learning 2 (learning calculation method)
Initialization of for Try to make Java problem TypeScript 5-4
Java learning memo (method)
[Java] How to extract the file name from the path
[Java] Connect to MySQL
About Java method binding
[Java ~ Method ~] Study memo (5)
About method splitting (Java)
Studying Java 8 (see method)
Java programming (class method)
From Java to Ruby !!
Try connecting to AzureCosmosDB Emulator for Docker with Java
Try to solve a restricted FizzBuzz problem in Java
Introduction to java command
Try to build a Java development environment using Docker
Java encapsulation private public
[Java] Basic method notes
Try using each_with_index method
16 Corresponds to method invocation
Try Java return value
How to get the class name / method name running in Java
Setting method to link Java of Eclipse and Github / September 2017
[Beginner] Try to make a simple RPG game with Java ①