Java ASTParser类代码示例 - 纯净天空

本文整理汇总了Java中org.eclipse.jdt.core.dom.ASTParser**的典型用法代码示例。如果您正苦于以下问题:Java ASTParser类的具体用法?Java ASTParser怎么用?Java ASTParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

ASTParser类属于org.eclipse.jdt.core.dom包,在下文中一共展示了ASTParser类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: parseAST

​ 点赞 4 ​

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

Ad

[

](https://googleads.g.doubleclick.net/aclk?sa=l&ai=CRuOAvgDLYZz3Ksmg2gTX_JiwDp3BhrBn2sDEg8IOrvaykK4XEAEgl8aRTGCdAaABwJTv_APIAQaoAwHIA8sEqgSOAk_QBGv6JcP9D83OWQecthlwUhzMz92eLVBH2vL3uFroM1lWDB8Lgjriv4cZ9fGr0H62gCzw8ZBDnlo0uridBfXTDQzKbL5hlrdOdRvPx2YGTbINGs-wCvYQs7-TenXMHOItFpCOxF-gQuaQ_BiP9em1aXWkkut01NB0vivlyy-770WFAM9TSp9wzT-jtjtKBxV58UZkJ62Kkyxop-BNnapoeUPoEp4ecBnX4VjQXrkHhGdguDmL_zpIhH9fNRxbsL6Ao_HD7hR2a-lFNhgeOg4PthscujyEE8PDxGoNuhTeYKj_EzfHUIvkKxm_8rY7eacnv4su3_AASZ2mte1IvQrGm2z3h9GX8nix4WMFAsAEkvj6xp0CoAY3gAeo65ADqAeOzhuoB5PYG6gH7paxAqgH_p6xAqgH1ckbqAemvhuoB_PRG6gHltgbqAeqm7ECqAffn7EC2AcB0ggHCIBhEAEYH7EJvkIJr4shHY2ACgGYCwHICwG4DAHYEwyIFBLQFQGYFgH4FgGAFwE&ae=1&num=1&sig=AOD64_2SykC1ZMwgVffusPRSwF6mR6gvRg&client=ca-pub-9584489059513758&nb=9&adurl=https://www.parallels.com.cn/pd/windows-on-mac/%3Fgclid%3DEAIaIQobChMInM73oL2G9QIVSZCWCh1XPgbmEAEYASAAEgImyvD_BwE)

Parallels® Desktop 17 for Mac

Ad Mac与Windows融合。针对macOS
Monterey、Windows11进行了优化。…

Parallels.cn

下载

示例2: getField

​ 点赞 3 ​

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

​ 点赞 3 ​

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

Ad

[

](https://www.googleadservices.com/pagead/aclk?sa=L&ai=C1KCMvgDLYYutK9T62gSr7ZO4Dp3BhrBn2sDEg8IOrvaykK4XEAEgl8aRTGCdAaABwJTv_APIAQaoAwHIA8sEqgSRAk_Q9j6CGV0lJZQUb76N3oWp9_LTb98ddR1pduZMTH3o3d-rPN-Vi7sOlCukDbc6rA7TWtFc87fJNl5YVr6cvU4HsrJzO3eSD67ZAoY9Sv6M78S7hNc2OQS8i3JqCOC0zD3p1rlI0Y8w1p_zkwJJh-km8y8hVPtlsj_yj_wKS44qFuwGBItdZXApqgeErs2YkTKArM9EPtavylCTtRk24BdN3uYSJlj7i4W64U_rvT4X3hXGbkcqLQjvfnfCRnG00vCjvLXMBlm5zJ2FHjadJvfnB7b_o6dK9HEPfJZxvYIOp5HVusrJ-Yh66gbIr2J_vmxmqMAi6eSMEooTpS6oaVHktXBCVgkjCpwQKWyVxjduT8AEkvj6xp0CoAY3gAeo65ADqAeOzhuoB5PYG6gH7paxAqgH_p6xAqgH1ckbqAemvhuoB_PRG6gHltgbqAeqm7ECqAffn7EC2AcB0ggHCIBhEAEYH7EJvkIJr4shHY2ACgGYCwHICwG4DAHYEwyIFBLQFQGYFgH4FgGAFwE&ae=1&num=1&cid=CAASEuRoV19UBuOAeK5fEOJCjkAFMg&sig=AOD64_3c90cdDM_aSj8I7IY-dwBHB5i0WA&client=ca-pub-9584489059513758&nb=9&adurl=https://www.parallels.com.cn/pd/windows-on-mac/%3Fgclid%3DEAIaIQobChMIi4T4oL2G9QIVVL2WCh2r9gTnEAEYASAAEgLDbfD_BwE)

Parallels® Desktop 17 for Mac

Ad Mac与Windows融合。针对macOS
Monterey、Windows11进行了优化。…

Parallels.cn

下载

示例4: getGeneratedClassAnnotation

​ 点赞 3 ​

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

​ 点赞 3 ​

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

​ 点赞 3 ​

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: EclipseParser

​ 点赞 3 ​

import org.eclipse.jdt.core.dom.ASTParser; //导入依赖的package包/类
/**
 * Creates a new EclipseParser
 *
 * @param sourceFile String of source file to read
 * @param outJ       JSON parsed out
 * @throws IOException when file can't be opened or errors in reading/writing
 */
public EclipseParser(String sourceFile, PrintStream outJ, boolean prettyprint) throws IOException {

    File file = new File(sourceFile);
    final BufferedReader reader = new BufferedReader(new FileReader(file));
    char[] source = IOUtils.toCharArray(reader);
    reader.close();
    this.parser = ASTParser.newParser(AST.JLS8);
    parser.setSource(source);
    parser.setKind(ASTParser.K_COMPILATION_UNIT);

    final JsonFactory jsonF = new JsonFactory();
    jG = jsonF.createGenerator(outJ);
    if (prettyprint) {
        jG.setPrettyPrinter(new DefaultPrettyPrinter());
        mapper.enable(SerializationFeature.INDENT_OUTPUT);
    }
    mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
    mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    mapper.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
    SimpleModule module = new SimpleModule();
    module.addSerializer(ASTNode.class, new NodeSerializer());
    mapper.registerModule(module);
}
 

开发者ID:bblfsh,项目名称:java-driver,代码行数:31,代码来源:eclipseParser.java

示例8: getRecoveredAST

​ 点赞 3 ​

import org.eclipse.jdt.core.dom.ASTParser; //导入依赖的package包/类
private CompilationUnit getRecoveredAST(IDocument document, int offset, Document recoveredDocument) {
    CompilationUnit ast = SharedASTProvider.getInstance().getAST(fCompilationUnit, null);
    if (ast != null) {
        recoveredDocument.set(document.get());
        return ast;
    }

    char[] content= document.get().toCharArray();

    // clear prefix to avoid compile errors
    int index= offset - 1;
    while (index >= 0 && Character.isJavaIdentifierPart(content[index])) {
        content[index]= ' ';
        index--;
    }

    recoveredDocument.set(new String(content));

    final ASTParser parser= ASTParser.newParser(IASTSharedValues.SHARED_AST_LEVEL);
    parser.setResolveBindings(true);
    parser.setStatementsRecovery(true);
    parser.setSource(content);
    parser.setUnitName(fCompilationUnit.getElementName());
    parser.setProject(fCompilationUnit.getJavaProject());
    return (CompilationUnit) parser.createAST(new NullProgressMonitor());
}
 

开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:27,代码来源:OverrideCompletionProposal.java

示例9: getParameterTypeNamesForSeeTag

​ 点赞 3 ​

import org.eclipse.jdt.core.dom.ASTParser; //导入依赖的package包/类
private static String[] getParameterTypeNamesForSeeTag(IMethod overridden) {
    try {
        ASTParser parser = ASTParser.newParser(IASTSharedValues.SHARED_AST_LEVEL);
        parser.setProject(overridden.getJavaProject());
        IBinding[] bindings = parser.createBindings(new IJavaElement[] { overridden }, null);
        if (bindings.length == 1 && bindings[0] instanceof IMethodBinding) {
            return getParameterTypeNamesForSeeTag((IMethodBinding) bindings[0]);
        }
    } catch (IllegalStateException e) {
        // method does not exist
    }
    // fall back code. Not good for generic methods!
    String[] paramTypes = overridden.getParameterTypes();
    String[] paramTypeNames = new String[paramTypes.length];
    for (int i = 0; i < paramTypes.length; i++) {
        paramTypeNames[i] = Signature.toString(Signature.getTypeErasure(paramTypes[i]));
    }
    return paramTypeNames;
}
 

开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:20,代码来源:StubUtility.java

示例10: parseCompilationUnits

​ 点赞 3 ​

import org.eclipse.jdt.core.dom.ASTParser; //导入依赖的package包/类
/**
 * Goes through a list of compilation units and parses them. The act of parsing creates the AST structures from the
 * source code.
 * 
 * @param compilationUnits the list of compilation units to parse
 * @return the mapping from compilation unit to the AST roots of each
 */
public static Map<ICompilationUnit, ASTNode> parseCompilationUnits(List<ICompilationUnit> compilationUnits) {
    if (compilationUnits == null) {
        throw new CrystalRuntimeException("null list of compilation units");
    }

    ICompilationUnit[] compUnits = compilationUnits.toArray(new ICompilationUnit[0]);
    final Map<ICompilationUnit, ASTNode> parsedCompilationUnits = new HashMap<ICompilationUnit, ASTNode>();
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    parser.setResolveBindings(true);
    parser.setProject(WorkspaceUtilities.javaProject);
    parser.createASTs(compUnits, new String[0], new ASTRequestor() {
        @Override
           public final void acceptAST(final ICompilationUnit unit, final CompilationUnit node) {
            parsedCompilationUnits.put(unit, node);
        }

        @Override
           public final void acceptBinding(final String key, final IBinding binding) {
            // Do nothing
        }
    }, null);
    return parsedCompilationUnits;
}
 

开发者ID:aroog,项目名称:code,代码行数:31,代码来源:WorkspaceUtilities.java

示例11: parseFiles

​ 点赞 3 ​

import org.eclipse.jdt.core.dom.ASTParser; //导入依赖的package包/类
public void parseFiles(List<InputFile> files, final Handler handler) {
  // We need the whole SourceFile to correctly handle a parsed ADT, so we keep track of it here.
  final Map<String, InputFile> reverseMap = new LinkedHashMap<String, InputFile>();
  for (InputFile file: files) {
    reverseMap.put(file.getPath(), file);
  }

  ASTParser parser = newASTParser();
  FileASTRequestor astRequestor = new FileASTRequestor() {
    @Override
    public void acceptAST(String sourceFilePath, CompilationUnit ast) {
      logger.fine("acceptAST: " + sourceFilePath);
      int errors = ErrorUtil.errorCount();
      checkCompilationErrors(sourceFilePath, ast);
      if (errors == ErrorUtil.errorCount()) {
        handler.handleParsedUnit(reverseMap.get(sourceFilePath), ast);
      }
    }
  };
  // JDT fails to resolve all secondary bindings unless there are the same
  // number of "binding key" strings as source files. It doesn't appear to
  // matter what the binding key strings should be (as long as they're non-
  // null), so the paths array is reused.
  String[] paths = reverseMap.keySet().toArray(new String[reverseMap.size()]);
  parser.createASTs(paths, getEncodings(paths.length), paths, astRequestor, null);
}
 

开发者ID:Sellegit,项目名称:j2objc,代码行数:27,代码来源:JdtParser.java

示例12: isValidExpression

​ 点赞 3 ​

import org.eclipse.jdt.core.dom.ASTParser; //导入依赖的package包/类
public static boolean isValidExpression(String string) {
  String trimmed = string.trim();
  if ("".equals(trimmed)) // speed up for a common case //$NON-NLS-1$
  return false;
  StringBuffer cuBuff = new StringBuffer();
  cuBuff
      .append(CONST_CLASS_DECL)
      .append("Object") // $NON-NLS-1$
      .append(CONST_ASSIGN);
  int offset = cuBuff.length();
  cuBuff.append(trimmed).append(CONST_CLOSE);
  ASTParser p = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
  p.setSource(cuBuff.toString().toCharArray());
  CompilationUnit cu = (CompilationUnit) p.createAST(null);
  Selection selection = Selection.createFromStartLength(offset, trimmed.length());
  SelectionAnalyzer analyzer = new SelectionAnalyzer(selection, false);
  cu.accept(analyzer);
  ASTNode selected = analyzer.getFirstSelectedNode();
  return (selected instanceof Expression)
      && trimmed.equals(
          cuBuff.substring(
              cu.getExtendedStartPosition(selected),
              cu.getExtendedStartPosition(selected) + cu.getExtendedLength(selected)));
}
 

开发者ID:eclipse,项目名称:che,代码行数:25,代码来源:ChangeSignatureProcessor.java

示例13: isValidVarargsExpression

​ 点赞 3 ​

import org.eclipse.jdt.core.dom.ASTParser; //导入依赖的package包/类
public static boolean isValidVarargsExpression(String string) {
  String trimmed = string.trim();
  if ("".equals(trimmed)) // speed up for a common case //$NON-NLS-1$
  return true;
  StringBuffer cuBuff = new StringBuffer();
  cuBuff.append("class A{ {m("); // $NON-NLS-1$
  int offset = cuBuff.length();
  cuBuff.append(trimmed).append(");}}"); // $NON-NLS-1$
  ASTParser p = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
  p.setSource(cuBuff.toString().toCharArray());
  CompilationUnit cu = (CompilationUnit) p.createAST(null);
  Selection selection = Selection.createFromStartLength(offset, trimmed.length());
  SelectionAnalyzer analyzer = new SelectionAnalyzer(selection, false);
  cu.accept(analyzer);
  ASTNode[] selectedNodes = analyzer.getSelectedNodes();
  if (selectedNodes.length == 0) return false;
  for (int i = 0; i < selectedNodes.length; i++) {
    if (!(selectedNodes[i] instanceof Expression)) return false;
  }
  return true;
}
 

开发者ID:eclipse,项目名称:che,代码行数:22,代码来源:ChangeSignatureProcessor.java

示例14: _processUnit

​ 点赞 3 ​

import org.eclipse.jdt.core.dom.ASTParser; //导入依赖的package包/类
private void _processUnit(ICompilationUnit cu)
    throws JavaModelException, MalformedTreeException, BadLocationException {

    // Parse the javacode to be able to modify it
    ASTParser parser = ASTParser.newParser(AST.JLS8);
    parser.setSource(cu);

    // Create a copy of the CompilationUnit to work on
    CompilationUnit copyOfUnit = (CompilationUnit)parser.createAST(null);

    MemberComparator comparator = new MemberComparator();

    // This helper method will sort our java code with the given comparator
    TextEdit edits = CompilationUnitSorter.sort(copyOfUnit, comparator, 0, null, null);

    // The sort method gives us null if there weren't any changes
    if (edits != null) {
        ICompilationUnit workingCopy = cu.getWorkingCopy(new WorkingCopyOwner() {}, null);

        workingCopy.applyTextEdit(edits, null);

        // Commit changes
        workingCopy.commitWorkingCopy(true, null);
    }
}
 

开发者ID:Ixenit,项目名称:eclipsemembersort,代码行数:26,代码来源:SortHandler.java

示例15: Parse

​ 点赞 3 ​

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

示例16: resolveType

​ 点赞 3 ​

import org.eclipse.jdt.core.dom.ASTParser; //导入依赖的package包/类
public static ITypeBinding resolveType(IJavaProject javaProject,
    String qualifiedTypeName) throws JavaModelException {
  IType type = javaProject.findType(qualifiedTypeName);
  if (type == null || !type.exists()) {
    return null;
  }

  ASTParser parser = ASTParser.newParser(AST.JLS3);
  parser.setProject(javaProject);
  IBinding[] bindings = parser.createBindings(new IJavaElement[] {type}, null);
  if (bindings == null) {
    return null;
  }

  return (ITypeBinding) bindings[0];
}
 

开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:17,代码来源:JavaASTUtils.java

示例17: createAst

​ 点赞 3 ​

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

示例18: dumpJava

​ 点赞 3 ​

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

示例19: parseJava

​ 点赞 3 ​

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

示例20: ParserContext

​ 点赞 3 ​

import org.eclipse.jdt.core.dom.ASTParser; //导入依赖的package包/类
public ParserContext(HashMap<String, HashSet<String>> scope, 
                       HashMap<String, DocumentASTRewrite> sourceFileContents,
                       String[] classpaths, String[] sourcepaths, String[] sourceFilesArray, 
                       LineCoverage faultyLineCoverage, LineCoverage seedLineCoverage, 
                       Statements faultyStatements, Statements seedStatements){

this.parser = ASTParser.newParser(AST.JLS8);

      this.scope = scope;
      this.sourceFileContents = sourceFileContents;
      this.classpaths = classpaths;
      this.sourcepaths = sourcepaths;
      this.sourceFilesArray = sourceFilesArray;
      this.faultyLineCoverage = faultyLineCoverage;
      this.seedLineCoverage = seedLineCoverage;
      this.faultyStatements = faultyStatements;
      this.seedStatements = seedStatements;
  }
 

开发者ID:qhanam,项目名称:Java-RSRepair,代码行数:19,代码来源:ParserContext.java

注:本文中的org.eclipse.jdt.core.dom.ASTParser类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


原网址: 访问
创建于: 2021-12-28 20:20:10
目录: default
标签: 无

请先后发表评论
  • 最新评论
  • 总共0条评论