Examples of ASTParser


Examples of net.sf.lapg.templates.ast.AstParser

    return t.invoke(new EvaluationContext(context != null ? context.getThisObject() : null, context, t), this, arguments);
  }

  public String eval(ILocatedEntity referer, String template, String templateId, EvaluationContext context) {
    final String inputName = templateId != null ? templateId : referer.getLocation();
    AstParser p = new AstParser(new ErrorReporter() {
      public void error(int start, int end, int line, String s) {
        DefaultEvaluationStrategy.this.fireError(null, inputName + ":" + s);
      }
    });
    IBundleEntity[] loaded = null;
    if (!p.parseBody(template, "syntax", inputName)) {
      loaded = new ITemplate[0];
    } else {
      loaded = p.getResult();
    }

    ITemplate t = loaded != null && loaded.length == 1
        && loaded[0].getKind() == IBundleEntity.KIND_TEMPLATE
        && loaded[0].getName().equals("inline")
View Full Code Here

Examples of org.aspectj.org.eclipse.jdt.core.dom.ASTParser

  }
}
protected ASTNode generateElementAST(ASTRewrite rewriter, IDocument document, ICompilationUnit cu) throws JavaModelException {
  if (this.createdNode == null) {
    this.source = removeIndentAndNewLines(this.source, document, cu);
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    parser.setSource(this.source.toCharArray());
    parser.setProject(getCompilationUnit().getJavaProject());
    parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS);
    ASTNode node = parser.createAST(this.progressMonitor);
    String createdNodeSource;
    if (node.getNodeType() != ASTNode.TYPE_DECLARATION) {
      createdNodeSource = generateSyntaxIncorrectAST();
      if (this.createdNode == null)
        throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INVALID_CONTENTS));
View Full Code Here

Examples of org.aspectj.org.eclipse.jdt.core.dom.ASTParser

  IType type = getType();
  String lineSeparator = org.aspectj.org.eclipse.jdt.internal.core.util.Util.getLineSeparator(this.source, type == null ? null : type.getJavaProject());
  buff.append(lineSeparator + " public class A {" + lineSeparator); //$NON-NLS-1$
  buff.append(this.source);
  buff.append(lineSeparator).append('}');
  ASTParser parser = ASTParser.newParser(AST.JLS3);
  parser.setSource(buff.toString().toCharArray());
  CompilationUnit compilationUnit = (CompilationUnit) parser.createAST(null);
  TypeDeclaration typeDeclaration = (TypeDeclaration) compilationUnit.types().iterator().next();
  List bodyDeclarations = typeDeclaration.bodyDeclarations();
  if (bodyDeclarations.size() != 0)
    this.createdNode = (ASTNode) bodyDeclarations.iterator().next();
  return buff.toString();
View Full Code Here

Examples of org.aspectj.org.eclipse.jdt.core.dom.ASTParser

* </ul>
*/
public org.aspectj.org.eclipse.jdt.core.dom.CompilationUnit getAST3() throws JavaModelException {
  if (this.operation.astLevel != AST.JLS3 || !this.operation.resolveBindings) {
    // create AST (optionally resolving bindings)
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    parser.setCompilerOptions(workingCopy.getJavaProject().getOptions(true));
    if (JavaProject.hasJavaNature(workingCopy.getJavaProject().getProject()))
      parser.setResolveBindings(true);
    parser.setStatementsRecovery((this.operation.reconcileFlags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0);
    parser.setBindingsRecovery((this.operation.reconcileFlags & ICompilationUnit.ENABLE_BINDINGS_RECOVERY) != 0);
    parser.setSource(workingCopy);
    return (org.aspectj.org.eclipse.jdt.core.dom.CompilationUnit) parser.createAST(this.operation.progressMonitor);   
  }
  return this.operation.makeConsistent(this.workingCopy);
}
View Full Code Here

Examples of org.aspectj.org.eclipse.jdt.core.dom.ASTParser

   * @param source
   */
  private String processElement(ICompilationUnit unit, char[] source) {
    Document document = new Document(new String(source));
    CompilerOptions options = new CompilerOptions(unit.getJavaProject().getOptions(true));
    ASTParser parser = ASTParser.newParser(this.apiLevel);
    parser.setCompilerOptions(options.getMap());
    parser.setSource(source);
    parser.setKind(ASTParser.K_COMPILATION_UNIT);
    parser.setResolveBindings(false);
    org.aspectj.org.eclipse.jdt.core.dom.CompilationUnit ast = (org.aspectj.org.eclipse.jdt.core.dom.CompilationUnit) parser.createAST(null);
       
    ASTRewrite rewriter= sortCompilationUnit(ast, null);
    if (rewriter == null)
      return document.get();
   
View Full Code Here

Examples of org.aspectj.org.eclipse.jdt.core.dom.ASTParser

   }
  protected CompilationUnit parse(ICompilationUnit cu) throws JavaModelException {
    // ensure cu is consistent (noop if already consistent)
    cu.makeConsistent(this.progressMonitor);
    // create an AST for the compilation unit
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    parser.setSource(cu);
    return (CompilationUnit) parser.createAST(this.progressMonitor);
  }
View Full Code Here

Examples of org.eclipse.jdt.core.dom.ASTParser

            methods.add(xpathList);
        }
    }
   
    private void performPropertyParsingViaJDTAST(final String classname, final Set<TMLScriptProperty> properties) {
        ASTParser parser = ASTParser.newParser(AST.JLS3);
        StringWriter writer = new StringWriter();
        InputStreamReader reader = new InputStreamReader(retrieveJavaSource(classname));
        try {
            WGUtils.inToOut(reader, writer, 1024);
        }
        catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        parser.setSource(writer.toString().toCharArray());
        ASTNode ast = parser.createAST(new NullProgressMonitor());
        ast.accept(new ASTVisitor() {

            private Map<String, String> _imports = new HashMap<String, String>();
           
            @Override
View Full Code Here

Examples of org.eclipse.jdt.core.dom.ASTParser

            return methods;
        }
      }
   
    private void performMethodParsingViaJDTAST(final String classname, final Set<TMLScriptMethod> methods, final int envFlags) {
        ASTParser parser = ASTParser.newParser(AST.JLS3);
        StringWriter writer = new StringWriter();
        InputStreamReader reader = new InputStreamReader(retrieveJavaSource(classname));
        try {
            WGUtils.inToOut(reader, writer, 1024);
        }
        catch (IOException e) {
        }
        parser.setSource(writer.toString().toCharArray());
        ASTNode ast = parser.createAST(new NullProgressMonitor());
        ast.accept(new ASTVisitor() {
            private Map<String, String> _imports = new HashMap<String, String>();

            @Override
            public void endVisit(ImportDeclaration node) {
View Full Code Here

Examples of org.eclipse.jdt.core.dom.ASTParser

           
            return constructors;
    }

    private void performConstructorParsingViaJDTAST(final String classname, final Set<TMLScriptMethod> constructors) {
        ASTParser parser = ASTParser.newParser(AST.JLS3);
        StringWriter writer = new StringWriter();
        InputStreamReader reader = new InputStreamReader(retrieveJavaSource(classname));
        try {
            WGUtils.inToOut(reader, writer, 1024);
        }
        catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        parser.setSource(writer.toString().toCharArray());
        ASTNode ast = parser.createAST(new NullProgressMonitor());
        ast.accept(new ASTVisitor() {
           
            private Map<String, String> _imports = new HashMap<String, String>();

            @Override
View Full Code Here

Examples of org.eclipse.jdt.core.dom.ASTParser

  protected String constructCUContent(ICompilationUnit cu, String typeContent, String lineDelimiter) throws CoreException {
    String typeComment = getTypeComment(cu, lineDelimiter);
    IPackageFragment pack = (IPackageFragment) cu.getParent();
    String content = CodeGeneration.getCompilationUnitContent(cu, typeComment, typeContent, lineDelimiter);
    if (content != null) {
      ASTParser parser = ASTParser.newParser(AST.JLS2);
      parser.setSource(content.toCharArray());
      CompilationUnit unit = (CompilationUnit) parser.createAST(null);
      if ((pack.isDefaultPackage() || unit.getPackage() != null) && !unit.types().isEmpty()) { return content; }
    }
    StringBuffer buf = new StringBuffer();
    if (!pack.isDefaultPackage()) {
      buf.append("package ").append(pack.getElementName()).append(';'); //$NON-NLS-1$
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.