當前位置: 首頁>>代碼示例>>Java>>正文


Java CompilationUnit.accept方法代碼示例

本文整理匯總了Java中com.github.javaparser.ast.CompilationUnit.accept方法的典型用法代碼示例。如果您正苦於以下問題:Java CompilationUnit.accept方法的具體用法?Java CompilationUnit.accept怎麽用?Java CompilationUnit.accept使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.github.javaparser.ast.CompilationUnit的用法示例。


在下文中一共展示了CompilationUnit.accept方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: analyze

import com.github.javaparser.ast.CompilationUnit; //導入方法依賴的package包/類
public List<EntityField> analyze(File source) throws IOException, ParseException {
    List<EntityField> entityFields = new ArrayList<>();
    CompilationUnit cu = JavaParser.parse(source);
    cu.accept(new VoidVisitorAdapter<List<EntityField>>() {
        @Override
        public void visit(FieldDeclaration fd, List<EntityField> f) {
            if (fd.getAnnotations().stream().anyMatch(anno -> anno.getName().getName().equals("Column"))) {
                Class<?> type = null;
                switch (fd.getType().toString()) {
                    case "String": type = String.class; break;
                    case "Long": type = Long.class; break;
                    case "Integer": type = Integer.class; break;
                    case "boolean": type = boolean.class; break;
                }
                if (type == null) return;
                f.add(new EntityField(
                        fd.getVariables().get(0).getId().getName(),
                        type,
                        fd.getAnnotations().stream().anyMatch(anno -> anno.getName().getName().equals("Id"))));
            }
        }
    }, entityFields);

    return entityFields;
}
 
開發者ID:kawasima,項目名稱:enkan,代碼行數:26,代碼來源:EntitySourceAnalyzer.java

示例2: testPackagelessEndpoint

import com.github.javaparser.ast.CompilationUnit; //導入方法依賴的package包/類
@Test
public void testPackagelessEndpoint() throws FileNotFoundException {
    String testFile = packageLessTestFile;

    CompilationUnit cu = generateCompilationUnitFromFile(testFile);

    logger.debug("Running visitors...");

    // Visit and print the methods' names
    cu.accept(new SpringAnnotationAnalyzer(), cu.getPackageDeclaration());

    // Get endpoints we've found
    ArrayList<Endpoint> endpoints = SpringAPIIdentifier.getEndpoints();

    //Just be sure we got something from the file....
    //public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) { ...
    assertEquals("name", endpoints.get(0).getParams().get(0).getHttpParameterName());
}
 
開發者ID:kevinfealey,項目名稱:API_Endpoint_Identifier,代碼行數:19,代碼來源:SpringAPIIdentifierTest.java

示例3: parseJavaDoc

import com.github.javaparser.ast.CompilationUnit; //導入方法依賴的package包/類
private static void parseJavaDoc(Path path, JavaDocParserVisitor visitor) {
    try {
        CompilationUnit cu = JavaParser.parse(path.toFile());
        cu.accept(visitor, null);
    } catch (FileNotFoundException e) {
        throw new IllegalStateException(e);
    }
}
 
開發者ID:sdaschner,項目名稱:jaxrs-analyzer,代碼行數:9,代碼來源:JavaDocAnalyzer.java

示例4: findEndpoints

import com.github.javaparser.ast.CompilationUnit; //導入方法依賴的package包/類
private static void findEndpoints(String file) throws FileNotFoundException {
    Logger logger = LoggerFactory.getLogger(SpringAPIIdentifier.class);

    // Assumes this file is part of this project
    FileInputStream in = new FileInputStream(file);

    // Parse it
    CompilationUnit cu = JavaParser.parse(in);

    // Visit and print the methods' names
    cu.accept(new SpringAnnotationAnalyzer(), cu.getPackageDeclaration());

    logger.debug("Printing Endpoint Info:");
    for (Endpoint endpoint : endpoints) {
        logger.info("=====================================================");
        logger.info("Name: " + (endpoint.getName() == null ? "<N/A>" : endpoint.getName()));
        logger.info("URL: " + endpoint.getUrl());
        logger.info("HTTP methods: " + endpoint.getMethods().toString());
        logger.info("Consumes: " + endpoint.getConsumes().toString());
        logger.info("Produces: " + endpoint.getProduces().toString());
        logger.info("Part of class: " + endpoint.getClazzName());

        logger.info("Headers:");
        for (Parameter header : endpoint.getHeaders()) {
            logger.info("\t\t" + header.getHttpParameterName() + " = " + header.getDefaultValue());
        }

        logger.info("Parameters:");
        for (Parameter param : endpoint.getParams()) {
            logger.info("\t\t" + param.getHttpParameterName() + " is a " + param.getAnnotation() + " of type " +
                    param.getType() + " and a default value of " +
                    (param.getDefaultValue().equals("") ? "<N/A>" : param.getDefaultValue()) + ". This input " +
                    (param.isRequired() ? "is" : "is not") + " required.");
        }
    }
}
 
開發者ID:kevinfealey,項目名稱:API_Endpoint_Identifier,代碼行數:37,代碼來源:SpringAPIIdentifier.java

示例5: extract

import com.github.javaparser.ast.CompilationUnit; //導入方法依賴的package包/類
public SourceInfo extract() {
    CompilationUnit parseResult = null;
    try {
        parseResult = sourceReader.readSource();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    if (parseResult != null) {
        SourceTreeVisitor sourceTreeVisitor = new SourceTreeVisitor(sourceReader.getFilename());
        parseResult.accept(sourceTreeVisitor, null);
        return sourceTreeVisitor.getParseResult();
    }
    return null;
    
}
 
開發者ID:ragnraok,項目名稱:JParserUtil,代碼行數:16,代碼來源:SourceInfoExtracter.java

示例6: decorate

import com.github.javaparser.ast.CompilationUnit; //導入方法依賴的package包/類
public static String decorate(String src, ClassInstance cls, boolean mapped) {
	Context context = new Context(cls.getEnv(), mapped);

	if (cls.getOuterClass() != null) {
		// replace <outer>.<inner> with <outer>$<inner> since . is not a legal identifier within class names and thus gets rejected by JavaParser

		String name = context.getName(cls);
		int pos = name.indexOf('$');

		if (pos != -1) {
			int end = name.length();
			char c;

			while ((c = name.charAt(end - 1)) >= '0' && c <= '9' || c == '$') { // FIXME: CFR strips digits only sometimes
				end--;
			}

			if (end > pos) {
				if ((pos = name.lastIndexOf('/')) != -1) {
					name = name.substring(pos + 1, end);
				} else if (end != name.length()) {
					name = name.substring(0, end);
				}

				src = src.replace(name.replace('$', '.'), name);
			}
		}
	}

	CompilationUnit cu;

	try {
		cu = JavaParser.parse(src);
	} catch (ParseProblemException e) {
		throw new ParseException(src, e);
	}

	cu.accept(remapVisitor, context);

	PrettyPrintVisitor printer = new Printer(new PrettyPrinterConfiguration().setIndent("\t").setEndOfLineCharacter("\n"));
	cu.accept(printer, null);

	return printer.getSource();
}
 
開發者ID:sfPlayer1,項目名稱:Matcher,代碼行數:45,代碼來源:SrcRemapper.java

示例7: verifyFile

import com.github.javaparser.ast.CompilationUnit; //導入方法依賴的package包/類
private static void verifyFile(final File file, final AbstractVerifier verifier) throws ParseException, IOException {
    final CompilationUnit cu = JavaParser.parse(file);
    cu.accept(verifier, null);
    verifier.verify();
}
 
開發者ID:hashsdn,項目名稱:hashsdn-controller,代碼行數:6,代碼來源:JMXGeneratorTest.java

示例8: whenTheSecondCompilationUnitIsCloned

import com.github.javaparser.ast.CompilationUnit; //導入方法依賴的package包/類
@When("the CompilationUnit is cloned to the second CompilationUnit")
public void whenTheSecondCompilationUnitIsCloned() {
    CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
    CompilationUnit compilationUnit2 = (CompilationUnit)compilationUnit.accept(new CloneVisitor(), null);
    state.put("cu2", compilationUnit2);
}
 
開發者ID:plum-umd,項目名稱:java-sketch,代碼行數:7,代碼來源:VisitorSteps.java

示例9: whenTheCompilationUnitIsVisitedByThePositionTestVisitor

import com.github.javaparser.ast.CompilationUnit; //導入方法依賴的package包/類
@When("the CompilationUnit is visited by the PositionTestVisitor")
public void whenTheCompilationUnitIsVisitedByThePositionTestVisitor() {
    CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
    compilationUnit.accept(positionTestVisitor, null);
}
 
開發者ID:plum-umd,項目名稱:java-sketch,代碼行數:6,代碼來源:VisitorSteps.java

示例10: main

import com.github.javaparser.ast.CompilationUnit; //導入方法依賴的package包/類
public static void main(String[] args) throws FileNotFoundException, ParseException {
    TypeSolver typeSolver = new CombinedTypeSolver(new ReflectionTypeSolver(), new JavaParserTypeSolver(new File("java-symbol-solver-examples/src/main/resources/someproject")));

    CompilationUnit agendaCu = JavaParser.parse(new FileInputStream(new File("java-symbol-solver-examples/src/main/resources/someproject/me/tomassetti/Agenda.java")));

    agendaCu.accept(new TypeCalculatorVisitor(), JavaParserFacade.get(typeSolver));

}
 
開發者ID:javaparser,項目名稱:javasymbolsolver,代碼行數:9,代碼來源:PrintExpressionType.java


注:本文中的com.github.javaparser.ast.CompilationUnit.accept方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。