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


Java ASTParser.setEnvironment方法代碼示例

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


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

示例1: parseAST

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
private static void parseAST(String[] srcFiles, Charset srcCharset,
        String[] classPathEntries, FileASTRequestor requestor) {
    ASTParser parser = ASTParser.newParser(AST.JLS8);
    Map<String, String> options = JavaCore.getOptions();
    JavaCore.setComplianceOptions(JavaCore.VERSION_1_8, options);
    parser.setCompilerOptions(options);
    parser.setKind(ASTParser.K_COMPILATION_UNIT);
    parser.setResolveBindings(true);
    parser.setBindingsRecovery(true);
    parser.setEnvironment(classPathEntries, null, null, true);
    String[] srcEncodings = new String[srcFiles.length];
    for (int i = 0; i < srcEncodings.length; i++) {
        srcEncodings[i] = srcCharset.name();
    }
    parser.createASTs(
            srcFiles, srcEncodings, new String[]{}, requestor, null);
}
 
開發者ID:SahaginOrg,項目名稱:sahagin-java,代碼行數:18,代碼來源:SrcTreeGenerator.java

示例2: parse

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
public void parse() throws ParseException {
    ASTParser parser = ASTParser.newParser(AST.JLS8);
    parser.setSource(source.toCharArray());
    Map<String, String> options = JavaCore.getOptions();
    options.put("org.eclipse.jdt.core.compiler.source", "1.8");
    parser.setCompilerOptions(options);
    parser.setKind(ASTParser.K_COMPILATION_UNIT);
    parser.setUnitName("Program.java");
    parser.setEnvironment(new String[] { classpath != null? classpath : "" },
            new String[] { "" }, new String[] { "UTF-8" }, true);
    parser.setResolveBindings(true);
    cu = (CompilationUnit) parser.createAST(null);

    List<IProblem> problems = Arrays.stream(cu.getProblems()).filter(p ->
                                        p.isError() &&
                                        p.getID() != IProblem.PublicClassMustMatchFileName && // we use "Program.java"
                                        p.getID() != IProblem.ParameterMismatch // Evidence varargs
                                    ).collect(Collectors.toList());
    if (problems.size() > 0)
        throw new ParseException(problems);
}
 
開發者ID:capergroup,項目名稱:bayou,代碼行數:22,代碼來源:Parser.java

示例3: prepareAST

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
private CompilationUnit prepareAST(String javaFile) throws IOException {
	File projectRoot = new File(VALIDATION_EXAMPLES_ROOT).getAbsoluteFile();
	File sourceFile = new File(projectRoot.getCanonicalPath() + VALIDATION_EXAMPLES_PACKAGE + javaFile);

	ASTParser parser = ASTParser.newParser(AST.JLS8);
	char[] content = SharedUtils.getFileContents(sourceFile);

	String[] classpath = {};
	String[] sourcepath = { projectRoot.getCanonicalPath(), new File(API_SRC_LOC).getCanonicalPath() };
	String[] encodings = { "UTF-8", "UTF-8" };

	parser.setSource(content);

	parser.setResolveBindings(true);
	parser.setBindingsRecovery(true);
	parser.setUnitName(sourceFile.getName());
	parser.setKind(ASTParser.K_COMPILATION_UNIT);
	parser.setEnvironment(classpath, sourcepath, encodings, true);

	return (CompilationUnit) parser.createAST(null);
}
 
開發者ID:ELTE-Soft,項目名稱:txtUML,代碼行數:22,代碼來源:ModelTest.java

示例4: parseAndResolveSource

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
/**
 * Parse a source file, attempting to resolve references in the AST. Valid Java files will usually
 * have errors in the CompilationUnit returned by this method, because classes, imports and
 * methods will be undefined (because we're only looking at a single file from a whole project).
 * Consequently, do not assume the returned object's getProblems() is an empty list. On the other
 * hand, {@link @parseSource} returns a CompilationUnit fit for syntax checking purposes.
 */
private static CompilationUnit parseAndResolveSource(String source) {
  ASTParser parser = createCompilationUnitParser();
  parser.setSource(source.toCharArray());
  parser.setResolveBindings(true);
  parser.setBindingsRecovery(true);
  parser.setEnvironment(
      EMPTY_STRING_ARRAY,
      EMPTY_STRING_ARRAY,
      EMPTY_STRING_ARRAY,
      true /* includeRunningVMBootclasspath */);
  parser.setUnitName("dontCare");

  return (CompilationUnit) parser.createAST(null);
}
 
開發者ID:bazelbuild,項目名稱:BUILD_file_generator,代碼行數:22,代碼來源:ReferencedClassesParser.java

示例5: parse

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
/**
 * @param compilationUnit
 * @param progressMonitor
 * @return
 * @throws JavaModelException
 */

public static CompilationUnit parse(final ICompilationUnit cu) {
	ASTParser parser = ASTParser.newParser(AST.JLS8);
	parser.setKind(ASTParser.K_COMPILATION_UNIT);
	parser.setSource(cu);
	parser.setResolveBindings(true);
	parser.setEnvironment(null, null, null, true);
	parser.setBindingsRecovery(true);
	final CompilationUnit ast = (CompilationUnit) parser.createAST(new NullProgressMonitor());

	return ast;
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:19,代碼來源:JDTManager.java

示例6: createCompilationUnit

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
private CompilationUnit createCompilationUnit(String classpath) throws IOException {
    ASTParser parser = ASTParser.newParser(AST.JLS8);
    File input = new File(options.cmdLine.getOptionValue("input-file"));

    parser.setSource(FileUtils.readFileToString(input, "utf-8").toCharArray());
    parser.setKind(ASTParser.K_COMPILATION_UNIT);
    parser.setUnitName("Program.java");
    parser.setEnvironment(new String[] { classpath != null? classpath : "" },
            new String[] { "" }, new String[] { "UTF-8" }, true);
    parser.setResolveBindings(true);

    return (CompilationUnit) parser.createAST(null);
}
 
開發者ID:capergroup,項目名稱:bayou,代碼行數:14,代碼來源:Driver.java

示例7: buildAstParser

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
private static ASTParser buildAstParser(String[] sourceFolders) {
	ASTParser parser = ASTParser.newParser(AST.JLS8);
	parser.setKind(ASTParser.K_COMPILATION_UNIT);
	Map options = JavaCore.getOptions();
	JavaCore.setComplianceOptions(JavaCore.VERSION_1_8, options);
	parser.setCompilerOptions(options);
	parser.setResolveBindings(true);
	parser.setBindingsRecovery(true);
	parser.setEnvironment(new String[0], sourceFolders, null, true);
	// parser.setEnvironment(new String[0], new String[]{"tmp\\refactoring-toy-example\\src"}, null, false);
	return parser;
}
 
開發者ID:aserg-ufmg,項目名稱:RefDiff,代碼行數:13,代碼來源:SDModelBuilder.java

示例8: buildAstParser

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
private static ASTParser buildAstParser(String[] sourceFolders) {
	ASTParser parser = ASTParser.newParser(AST.JLS8);
	parser.setKind(ASTParser.K_COMPILATION_UNIT);
	Map options = JavaCore.getOptions();
	JavaCore.setComplianceOptions(JavaCore.VERSION_1_8, options);
	parser.setCompilerOptions(options);
	parser.setResolveBindings(true);
	parser.setBindingsRecovery(true);
	parser.setEnvironment(new String[0], sourceFolders, null, true);
	//parser.setEnvironment(new String[0], new String[]{"tmp\\refactoring-toy-example\\src"}, null, false);
	return parser;
}
 
開發者ID:aserg-ufmg,項目名稱:RefDiff,代碼行數:13,代碼來源:SDModelBuilder.java

示例9: generateExamples

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
private Set<Slice> generateExamples() {
	Set<Slice> slices = new HashSet<>();

	File srcFile = new File(srcPath);
	String[] testPaths = getTestFiles(srcFile).parallelStream().map(File::getAbsolutePath).toArray(String[]::new);
	String[] folderPaths = getAllFiles(srcFile).parallelStream().map(File::getParentFile).map(File::getAbsolutePath).toArray(String[]::new);

	ASTParser parser = ASTParser.newParser(AST.JLS8);
	parser.setKind(ASTParser.K_COMPILATION_UNIT);
	parser.setEnvironment(null, folderPaths, null, true);
	parser.setResolveBindings(true);
	Map<String, String> options = new Hashtable<>();
	options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_8);
	options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_8);
	options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED);
	parser.setCompilerOptions(options);
	parser.setBindingsRecovery(true);
	parser.createASTs(testPaths, null, new String[]{}, new FileASTRequestor() {
		@Override
		public void acceptAST(String sourceFilePath, CompilationUnit javaUnit) {
			APIMethodVisitor visitor = new APIMethodVisitor();
			javaUnit.accept(visitor);
			slices.addAll(visitor.getSlices());
		}
	}, null);
	return slices;
}
 
開發者ID:linzeqipku,項目名稱:SnowGraph,代碼行數:28,代碼來源:APIUsageExtractor.java

示例10: newASTParser

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
private ASTParser newASTParser() {
  ASTParser parser = ASTParser.newParser(AST.JLS4);
  parser.setCompilerOptions(compilerOptions);
  parser.setResolveBindings(true);
  parser.setEnvironment(
      toArray(classpathEntries), toArray(sourcepathEntries),
      getEncodings(sourcepathEntries.size()), includeRunningVMBootclasspath);
  return parser;
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:10,代碼來源:JdtParser.java

示例11: Main

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
public Main(File javaFile, File infoFile) throws IOException {
	ASTParser parser = ASTParser.newParser(AST.JLS4);
	parser.setResolveBindings(true);
	parser.setKind(ASTParser.K_COMPILATION_UNIT);

	Map options = JavaCore.getOptions();
	options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_6);
	options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_6);
	options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_6);
	parser.setCompilerOptions(options);

	parser.setEnvironment(classpathEntries, srcpathEntries, null, true);

	String canonicalPath = javaFile.getCanonicalPath();
	System.out.println(canonicalPath);
	parser.setUnitName(canonicalPath);
	parser.setSource(toCharArray(canonicalPath));

	CompilationUnit cu = (CompilationUnit) parser.createAST(null);

	infoFile.getParentFile().mkdirs();
	/*
	PetabloxAdapterNew visitor = new PetabloxAdapterNew(cu);
	cu.accept(visitor);
	visitor.writeXml(infoFile);
	*/
}
 
開發者ID:petablox-project,項目名稱:petablox,代碼行數:28,代碼來源:Main.java

示例12: generate

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
@Override
public AST generate(String filename, String source, String[] srcFolders) {
	AST ast = new AST();
	ast.setName(filename);
	ast.setSource(source);

	ASTParser parser = ASTParser.newParser(org.eclipse.jdt.core.dom.AST.JLS8);
	parser.setResolveBindings(true);
	parser.setKind(ASTParser.K_COMPILATION_UNIT);
	parser.setBindingsRecovery(true);
	parser.setCompilerOptions(JavaCore.getOptions());
	parser.setUnitName(filename);
	parser.setSource(source.toCharArray());

	parser.setEnvironment(null, srcFolders, null, true);
	
	CompilationUnit cu = (CompilationUnit) parser.createAST(null);

	FileVisitor visitor = new FileVisitor();
	cu.accept(visitor);

	ast.setImports(visitor.getImports());
	ast.setPackageDeclaration(visitor.getPackageName());
	ast.setTypes(visitor.getTypes());

	return ast;
}
 
開發者ID:visminer,項目名稱:repositoryminer,代碼行數:28,代碼來源:JavaParser.java

示例13: createCompilationUnitsForJavaFiles

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
private void createCompilationUnitsForJavaFiles(final File inputFolder) {
    // first process input folder to find java file
    processFolderToFindJavaClass(inputFolder);

    // now prepare ASTParser to process al java file found
    ASTParser parser = ASTParser.newParser(AST.JLS8);
    parser.setKind(ASTParser.K_COMPILATION_UNIT);
    parser.setResolveBindings(true);
    parser.setBindingsRecovery(true);
    parser.setStatementsRecovery(true);
    parser.setEnvironment(new String[] {
                                        inputFolder.getAbsolutePath()
    }, new String[] {
                     inputFolder.getAbsolutePath()
    }, new String[] {
                     "UTF-8"
    }, true);

    // add compiler compliance rules to convert enums
    @SuppressWarnings("unchecked")
    Hashtable<String, String> options = JavaCore.getOptions();
    options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_8);
    options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_8);
    options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_8);

    parser.setCompilerOptions(options);
    FileASTRequestor requestor = new CustomFileASTRequestor(getLog(), inputFolder.getAbsolutePath(),
                                                            sourcePathEntry);
    parser.createASTs(sourcePathEntry.keySet().toArray(new String[0]),
                      charsetEntry.toArray(new String[0]), new String[] {
                                                                         ""
                      }, requestor, null);
}
 
開發者ID:codejuicer,項目名稱:java2csharp,代碼行數:34,代碼來源:Java2CsharpMojo.java

示例14: parse

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
public static ElementInfoPool parse(String srcDir) {
    ElementInfoPool elementInfoPool = new ElementInfoPool(srcDir);

    Collection<File> javaFiles = FileUtils.listFiles(new File(srcDir), new String[]{"java"}, true);
    Set<String> srcPathSet = new HashSet<>();
    Set<String> srcFolderSet = new HashSet<>();
    for (File javaFile : javaFiles) {
        String srcPath = javaFile.getAbsolutePath();
        String srcFolderPath = javaFile.getParentFile().getAbsolutePath();
        srcPathSet.add(srcPath);
        srcFolderSet.add(srcFolderPath);
    }
    String[] srcPaths = new String[srcPathSet.size()];
    srcPathSet.toArray(srcPaths);
    NameResolver.setSrcPathSet(srcPathSet);
    String[] srcFolderPaths = new String[srcFolderSet.size()];
    srcFolderSet.toArray(srcFolderPaths);

    ASTParser parser = ASTParser.newParser(AST.JLS8);
    parser.setKind(ASTParser.K_COMPILATION_UNIT);
    parser.setEnvironment(null, srcFolderPaths, null, true);
    parser.setResolveBindings(true);
    Map<String, String> options = new Hashtable<>();
    options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_8);
    options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_8);
    options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED);
    parser.setCompilerOptions(options);
    parser.setBindingsRecovery(true);
    System.out.println(javaFiles.size());
    parser.createASTs(srcPaths, null, new String[]{}, new FileASTRequestor() {
        @Override
        public void acceptAST(String sourceFilePath, CompilationUnit javaUnit) {
            try {
                javaUnit.accept(new JavaASTVisitor(elementInfoPool, FileUtils.readFileToString(new File(sourceFilePath))));
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }, null);

    return elementInfoPool;
}
 
開發者ID:linzeqipku,項目名稱:SnowGraph,代碼行數:44,代碼來源:JavaParser.java

示例15: process

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
public static void process(String srcRootPath, File javaFile) throws IOException {
	String canonicalPath = javaFile.getCanonicalPath();
	String relSrcFilePath = canonicalPath.substring(srcRootPath.length()+1);
	File infoFile = new File(srcMapDir, relSrcFilePath.replace(".java", ".xml"));

	if(javaFile.lastModified() < infoFile.lastModified()) 
		return;

	infoFile.getParentFile().mkdirs();

	ASTParser parser = ASTParser.newParser(AST.JLS4);
	parser.setResolveBindings(true);
	parser.setKind(ASTParser.K_COMPILATION_UNIT);

	Map options = JavaCore.getOptions();
	options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_6);
	options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_6);
	options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_6);
	parser.setCompilerOptions(options);
	parser.setEnvironment(classpathEntries, srcpathEntries, null, true);
	parser.setUnitName(canonicalPath);		
	parser.setSource(toCharArray(canonicalPath));

	CompilationUnit cu = (CompilationUnit) parser.createAST(null);

	System.out.println("generating srcmap file for "+canonicalPath);
	PetabloxAdapterNew visitor = new PetabloxAdapterNew(cu);
	try {
		cu.accept(visitor);
		visitor.writeXML(infoFile);
	} catch(Exception e) {
		System.out.println("Failed to generate srcmap file for "+relSrcFilePath);
		e.printStackTrace();
		infoFile.delete();
	}
	
	/*
	try {
		XMLContainerObject object = visitor.getXMLObject();
		File objectFile = new File(srcMapDir, relSrcFilePath.replace(".java", ".obj"));
		System.out.println("PRINTING XML OBJECT FOR " + javaFile.getName() + " TO " + objectFile.getCanonicalPath());
		ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(objectFile));
		oos.writeObject(object);
		oos.close();
	} catch(IOException e) {
		System.out.println("FAILED TO PRINT XML OBJECT FOR " + javaFile.getName() + "!");
		e.printStackTrace();
	}
	*/

	AnnotationReader annotReader = new AnnotationReader(canonicalPath);		
	cu.accept(annotReader);	
}
 
開發者ID:petablox-project,項目名稱:petablox,代碼行數:54,代碼來源:Main.java


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