java parser_java parser

时间:2025-03-22 14:15:46

package .chapter2;

import ;

import ;

import ;

import ;

import ;

import ;

import ;

import ;

import ;

import ;

import ;

import .SSEBlend_SRC_OUTPeer;

import ;

import ;

import ;

import ;

import ;

import ;

import ;

import ;

public class VoidVisitorComplete {

static CompilationUnit cu;

public static void main(String[] args) throws Exception {

Collection files = (new File("C:\\Users\\mi\\code\\test-service\\src\\main"), new String[]{"java"}, true);

for(File f: files) {

// if(().equals("")) {

cu = (new FileInputStream(f));

VoidVisitor methodNameVisitor = new MethodNamePrinter();

(cu, f);

// }

}

}

private static class MethodNamePrinter extends VoidVisitorAdapter {

@Override

public void visit(ClassOrInterfaceDeclaration d, File file) {

(d, file);

if(!()) {

NodeList nodeList = ();

boolean hasSerializable = false;

for(ClassOrInterfaceType classOrInterfaceType: nodeList) {

// ("classOrInterfaceType:" + classOrInterfaceType);

if(().getIdentifier().equals("Serializable")) {

hasSerializable = true;

}

}

if(!hasSerializable) {

("!hasSerializable:" + ());

if((().getIdentifier()).isPresent()) {

(().getIdentifier()).get().addImplementedType();

PrettyPrinterConfiguration conf = new PrettyPrinterConfiguration();

// (1);

// ();

// (false);

PrettyPrinter prettyPrinter = new PrettyPrinter(conf);

String content = (cu);

("content:" + content);

try {

(file, content, "UTF-8");

} catch (IOException e) {

();

}

}

}

}

}

}

}