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


Java ASTParser.setKind方法代碼示例

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


在下文中一共展示了ASTParser.setKind方法的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: getField

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
/**
 * @param methodname
 * @return
 */
public FieldDeclaration getField(   ) {
	ASTParser parser = ASTParser.newParser(AST.JLS8);
	String s = getStaticVariable ( );
	if (s==null) return null;
	parser.setSource(s.toCharArray());
	parser.setKind(ASTParser.K_COMPILATION_UNIT);
	final  CompilationUnit cu = (CompilationUnit) parser.createAST(null);
	cu.accept(new ASTVisitor() {
		public boolean visit(FieldDeclaration node) {
			field = node;
			return true;
		}
	});		 
	return field;
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:20,代碼來源:ClassExtension.java

示例3: getGraphWalkerClassAnnotation

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
/**
 * @return
 */
public NormalAnnotation getGraphWalkerClassAnnotation() {
	String source = getSource ();
	if(source==null) return null;
	ASTParser parser = ASTParser.newParser(AST.JLS8);
	parser.setSource(source.toCharArray());
	parser.setKind(ASTParser.K_COMPILATION_UNIT);
	final CompilationUnit cu = (CompilationUnit) parser.createAST(null);
	cu.accept(new ASTVisitor() {
		public boolean visit(NormalAnnotation node) {
			annotation = node;
			return true;
		}
	});
	if (this.generateAnnotation) return annotation;
	return null;
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:20,代碼來源:ClassExtension.java

示例4: getGeneratedClassAnnotation

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
public NormalAnnotation getGeneratedClassAnnotation() {
	String source = getGeneratedAnnotationSource ();
	if(source==null) return null;
	ASTParser parser = ASTParser.newParser(AST.JLS8);
	parser.setSource(source.toCharArray());
	parser.setKind(ASTParser.K_COMPILATION_UNIT);
	final CompilationUnit cu = (CompilationUnit) parser.createAST(null);
	cu.accept(new ASTVisitor() {
		public boolean visit(NormalAnnotation node) {
			annotation = node;
			return true;
		}
	});
    return annotation;
	 
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:17,代碼來源:ClassExtension.java

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

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

示例7: Parse

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
private CompilationUnit Parse(String contentFile, String fileName) throws Exception
{
	File file = new File(fileName);
	IFile[] files = WorkspaceRoot.findFilesForLocationURI(file.toURI(), IResource.FILE);
	
	if (files.length > 1)
		throw new Exception("Ambigous parse request for file: " + fileName);
	else if (files.length == 0)
		throw new Exception("File is not part of the enlistment: " + fileName);
	
	ASTParser parser = ASTParser.newParser(AST.JLS8);
	parser.setKind(ASTParser.K_COMPILATION_UNIT);
	parser.setSource(contentFile.toCharArray());
	parser.setUnitName(files[0].getName());
	parser.setProject(JavaCore.create(files[0].getProject()));
	parser.setResolveBindings(true);
	
	CompilationUnit cu = (CompilationUnit)parser.createAST(null);
	return cu;
}
 
開發者ID:Microsoft,項目名稱:vsminecraft,代碼行數:21,代碼來源:JavaParser.java

示例8: createAst

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
private CompilationUnit createAst() {
   // advise the parser to parse the code following to the Java Language Specification, Fourth Edition
   @SuppressWarnings("deprecation")
   // TODO: remove warning 
final ASTParser parser = ASTParser.newParser(AST.JLS4);

   // tells the parser, that it has to expect an ICompilationUnit as input
   parser.setKind(ASTParser.K_COMPILATION_UNIT);

   parser.setSource(compilationUnit);

   // binding service has to be explicitly requested at parse times
   parser.setResolveBindings(true);

   return (CompilationUnit) parser.createAST(new NullProgressMonitor());
 }
 
開發者ID:sealuzh,項目名稱:PerformanceHat,代碼行數:17,代碼來源:AstCompilationUnitDecorator.java

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

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

示例11: parseAndFillModel

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
/**
 * Parse the routeFile given while building the instance and fill the model.
 * @param model The EIP Model to fill with parsed elements from routeFile.
 * @throws InvalidArgumentException if given file is not a valid Spring integration file
 */
public void parseAndFillModel(EIPModel model) throws Exception {
   // Read source content.
   routeSource = parseRouteClass();
   
   // Parse and get the compilation unit.
   ASTParser parser = ASTParser.newParser(AST.JLS8);
   parser.setKind(ASTParser.K_COMPILATION_UNIT);
   parser.setSource(routeSource.toCharArray());
   parser.setResolveBindings(false);
   routeCU = (CompilationUnit) parser.createAST(null);
   
   // Visit and build a comment map before parsing.
   for (Object comment : routeCU.getCommentList()) {
      ((Comment) comment).accept(this);
   }
   
   // Initialize and build a route.
   route = EipFactory.eINSTANCE.createRoute();
   model.getOwnedRoutes().add(route);
   
   // 
   routeCU.accept(this);
}
 
開發者ID:lbroudoux,項目名稱:eip-designer,代碼行數:29,代碼來源:CamelJavaFileParser.java

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

示例13: parseJavaSource

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
/**
 * Parses the specified Java source file located in the given Java project.
 * 
 * @param sourceFile
 *            The specified Java source file.
 * @param project
 *            The given Java project.
 * @return The parsed compilation unit.
 * @throws IOException
 *             Thrown when I/O error occurs during reading the file.
 * @throws JavaModelException
 */
public static CompilationUnit parseJavaSource(File sourceFile, IJavaProject project)
		throws IOException, JavaModelException {
	ASTParser parser = ASTParser.newParser(AST.JLS8);
	char[] content = SharedUtils.getFileContents(sourceFile);

	parser.setSource(content);
	parser.setProject(project);

	parser.setResolveBindings(true);
	parser.setBindingsRecovery(true);
	parser.setUnitName(sourceFile.getName());
	parser.setKind(ASTParser.K_COMPILATION_UNIT);

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

示例14: handleImportRemoval

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
private void handleImportRemoval(CompilationUnit cu, ASTRewrite rewriter, ImportRewrite importRewrite,
		ITypeBinding superclass) throws CoreException, JavaModelException, BadLocationException {
	ICompilationUnit icu = (ICompilationUnit) cu.getJavaElement().getAdapter(IOpenable.class);
	TextEdit importEdits = importRewrite.rewriteImports(new NullProgressMonitor());
	TextEdit edits = rewriter.rewriteAST();
	importEdits.addChild(edits);
	
	// apply the text edits to the compilation unit
	String source = icu.getSource();
	Document document = new Document(source);
	importEdits.apply(document);

	String oldContents = icu.getBuffer().getContents();
	icu.getBuffer().setContents(document.get());
	ASTParser parser = ASTParser.newParser(AST.JLS8);
	parser.setResolveBindings(true);
	parser.setKind(ASTParser.K_COMPILATION_UNIT);
	parser.setBindingsRecovery(true);
	parser.setSource(icu);
	CompilationUnit astRoot = (CompilationUnit) parser.createAST(null);
	if (!ImportRelevanceFinder.isStillNeeded(astRoot, superclass.getQualifiedName())) {
		importRewrite.removeImport(superclass.getQualifiedName());
	}
	icu.getBuffer().setContents(oldContents);
}
 
開發者ID:vogellacompany,項目名稱:codemodify,代碼行數:26,代碼來源:LambdaConverterFix.java

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


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