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


Java ASTParser.setCompilerOptions方法代碼示例

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


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

示例1: 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

示例2: toGroovyTypeModel

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
public TypeModel toGroovyTypeModel(String source) {
    source = source.replaceAll("//(?i)\\s*" + quote("given") + SEPARATOR, "givenBlockStart();");
    source = source.replaceAll("//(?i)\\s*" + quote("when") + SEPARATOR, "whenBlockStart();");
    source = source.replaceAll("//(?i)\\s*" + quote("then") + SEPARATOR, "thenBlockStart();");

    ASTParser parser = ASTParser.newParser(JLS8);
    parser.setSource(source.toCharArray());
    parser.setKind(K_COMPILATION_UNIT);
    parser.setCompilerOptions(compilerOptions());

    CompilationUnit cu = (CompilationUnit) parser.createAST(null);
    astProxy.setTarget(cu.getAST());

    TypeVisitor visitor = testClassVisitorSupplier.get();
    cu.accept(visitor);
    return visitor.typeModel();
}
 
開發者ID:opaluchlukasz,項目名稱:junit2spock,代碼行數:18,代碼來源:Spocker.java

示例3: dumpJava

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
protected static void dumpJava(final String content) {
final ASTParser parser = ASTParser.newParser(astLevel);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setSource(content.toCharArray());

final Map options = JavaCore.getOptions();
JavaCore.setComplianceOptions(javaVersion, options);
parser.setCompilerOptions(options);

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

      try {
          final UglyMathCommentsExtractor cex = new UglyMathCommentsExtractor(cu, content);
          final ASTDumper dumper = new ASTDumper(cex);
          dumper.dump(cu);
          cex.close();
      } catch (final Exception e) {}
  }
 
開發者ID:boalang,項目名稱:compiler,代碼行數:19,代碼來源:Java7BaseTest.java

示例4: parseJava

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
protected static String parseJava(final String content) {
	final ASTParser parser = ASTParser.newParser(astLevel);
	parser.setKind(ASTParser.K_COMPILATION_UNIT);
	parser.setSource(content.toCharArray());

	final Map options = JavaCore.getOptions();
	JavaCore.setComplianceOptions(javaVersion, options);
	parser.setCompilerOptions(options);

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

	final ASTRoot.Builder ast = ASTRoot.newBuilder();
	try {
		ast.addNamespaces(visitor.getNamespaces(cu));
		for (final String s : visitor.getImports())
			ast.addImports(s);
	} catch (final Exception e) {
		System.err.println(e);
		e.printStackTrace();
		return "";
	}

	return JsonFormat.printToString(ast.build());
}
 
開發者ID:boalang,項目名稱:compiler,代碼行數:25,代碼來源:Java7BaseTest.java

示例5: extractPackage

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
private void extractPackage(Repository _repo) throws MissingObjectException, IOException{
	ObjectLoader newFile = _repo.open(this.newObjId);
	String newData = readStream(newFile.openStream());

	
	ASTParser parser = ASTParser.newParser(AST.JLS3);
	parser.setSource(newData.toCharArray());
	parser.setKind(ASTParser.K_COMPILATION_UNIT);
	Hashtable<String, String> options = JavaCore.getOptions();
	options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.DISABLED);
	parser.setCompilerOptions(options);
	
	final CompilationUnit cu = (CompilationUnit) parser.createAST(null);

	cu.accept(new ASTVisitor() {
		
		public boolean visit(PackageDeclaration _package){
			packageName = _package.getName().getFullyQualifiedName();
			return false;
		}
	});
}
 
開發者ID:gems-uff,項目名稱:dominoes,代碼行數:23,代碼來源:FileNode.java

示例6: createAst

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
private CompilationUnit createAst(ICompilationUnit unit, Map<String, String> cleanUpOptions, IProgressMonitor monitor) {
	IJavaProject project= unit.getJavaProject();
	if (compatibleOptions(project, cleanUpOptions)) {
		CompilationUnit ast= SharedASTProvider.getAST(unit, SharedASTProvider.WAIT_NO, monitor);
		if (ast != null)
			return ast;
	}

	ASTParser parser= CleanUpRefactoring.createCleanUpASTParser();
	parser.setSource(unit);

	Map<String, String> compilerOptions= RefactoringASTParser.getCompilerOptions(unit.getJavaProject());
	compilerOptions.putAll(cleanUpOptions);
	parser.setCompilerOptions(compilerOptions);

	return (CompilationUnit)parser.createAST(monitor);
}
 
開發者ID:trylimits,項目名稱:Eclipse-Postfix-Code-Completion-Juno38,代碼行數:18,代碼來源:CleanUpPostSaveListener.java

示例7: createCompilationUnitParser

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
private static ASTParser createCompilationUnitParser() {
  ASTParser parser = ASTParser.newParser(AST.JLS8);
  Map options = JavaCore.getOptions();
  JavaCore.setComplianceOptions(JavaCore.VERSION_1_8, options);
  parser.setCompilerOptions(options);
  parser.setKind(ASTParser.K_COMPILATION_UNIT);
  return parser;
}
 
開發者ID:bazelbuild,項目名稱:BUILD_file_generator,代碼行數:9,代碼來源:ReferencedClassesParser.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: 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

示例10: 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

示例11: parseAst

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
protected CompilationUnit parseAst(char[] source) {
    ASTParser parser = ASTParser.newParser(AST.JLS8);
    parser.setSource(source);
    Map options = JavaCore.getOptions();
    JavaCore.setComplianceOptions(JavaCore.VERSION_1_5, options);
    parser.setCompilerOptions(options);
    CompilationUnit result = (CompilationUnit) parser.createAST(null);
    return result;
}
 
開發者ID:helospark,項目名稱:SparkBuilderGenerator,代碼行數:10,代碼來源:BaseBuilderGeneratorIT.java

示例12: createAST

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
private static CompilationUnit createAST(IJavaElement element, String cuSource) {
	ASTParser parser = ASTParser.newParser(IASTSharedValues.SHARED_AST_LEVEL);

	IJavaProject javaProject= element.getJavaProject();
	parser.setProject(javaProject);
	Map<String, String> options= javaProject.getOptions(true);
	options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED); // workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=212207
	parser.setCompilerOptions(options);

	parser.setSource(cuSource.toCharArray());
	return (CompilationUnit) parser.createAST(null);
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:13,代碼來源:JavadocContentAccess.java

示例13: 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

示例14: getCuNode

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
private static CompilationUnit getCuNode(WorkingCopyOwner workingCopyOwner, ICompilationUnit cu) {
  ASTParser p = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
  p.setSource(cu);
  p.setResolveBindings(true);
  p.setWorkingCopyOwner(workingCopyOwner);
  p.setCompilerOptions(RefactoringASTParser.getCompilerOptions(cu));
  return (CompilationUnit) p.createAST(null);
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:9,代碼來源:ASTCreator.java

示例15: parseSuperType

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
private static Type parseSuperType(String superType, boolean isInterface) {
  if (!superType.trim().equals(superType)) {
    return null;
  }

  StringBuffer cuBuff = new StringBuffer();
  if (isInterface) cuBuff.append("class __X__ implements "); // $NON-NLS-1$
  else cuBuff.append("class __X__ extends "); // $NON-NLS-1$
  int offset = cuBuff.length();
  cuBuff.append(superType).append(" {}"); // $NON-NLS-1$

  ASTParser p = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
  p.setSource(cuBuff.toString().toCharArray());
  Map<String, String> options = new HashMap<String, String>();
  JavaModelUtil.setComplianceOptions(options, JavaModelUtil.VERSION_LATEST);
  p.setCompilerOptions(options);
  CompilationUnit cu = (CompilationUnit) p.createAST(null);
  ASTNode selected = NodeFinder.perform(cu, offset, superType.length());
  if (selected instanceof Name) selected = selected.getParent();
  if (selected.getStartPosition() != offset
      || selected.getLength() != superType.length()
      || !(selected instanceof Type)
      || selected instanceof PrimitiveType) {
    return null;
  }
  Type type = (Type) selected;

  String typeNodeRange =
      cuBuff.substring(type.getStartPosition(), ASTNodes.getExclusiveEnd(type));
  if (!superType.equals(typeNodeRange)) {
    return null;
  }
  return type;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:35,代碼來源:TypeContextChecker.java


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