Package org.jboss.forge.parser.java.ast

Examples of org.jboss.forge.parser.java.ast.TypeDeclarationFinderVisitor


      parser.setResolveBindings(true);
      parser.setKind(ASTParser.K_COMPILATION_UNIT);
      CompilationUnit unit = (CompilationUnit) parser.createAST(null);
      unit.recordModifications();

      TypeDeclarationFinderVisitor visitor = new TypeDeclarationFinderVisitor();
      unit.accept(visitor);

      List<AbstractTypeDeclaration> declarations = visitor.getTypeDeclarations();
      if (!declarations.isEmpty())
      {
         AbstractTypeDeclaration declaration = declarations.get(0);
         return getJavaSource(null, document, unit, declaration);
      }
      else if (visitor.getPackageDeclaration() != null)
      {
         return getJavaSource(null, document, unit, visitor.getPackageDeclaration());
      }
      throw new ParserException("Could not find type declaration in Java source - is this actually code?");
   }
View Full Code Here


   }

   private List<AbstractTypeDeclaration> getNestedDeclarations(ASTNode body)
   {

      TypeDeclarationFinderVisitor typeDeclarationFinder = new TypeDeclarationFinderVisitor();
      body.accept(typeDeclarationFinder);
      List<AbstractTypeDeclaration> declarations = typeDeclarationFinder.getTypeDeclarations();

      List<AbstractTypeDeclaration> result = new ArrayList<AbstractTypeDeclaration>(declarations);
      if (!declarations.isEmpty())
      {
         // We don't want to return the current class' declaration.
View Full Code Here

      return result;
   }

   protected AbstractTypeDeclaration getBodyDeclaration()
   {
      TypeDeclarationFinderVisitor typeDeclarationFinder = new TypeDeclarationFinderVisitor();
      unit.accept(typeDeclarationFinder);
      AbstractTypeDeclaration declaration = typeDeclarationFinder.getTypeDeclaration();
      if (declaration == null)
      {
         throw new RuntimeException(
                  "A type-declaration is required in order to complete the current operation, but no type-declaration exists in compilation unit: "
                           + unit.toString());
View Full Code Here

      parser.setResolveBindings(true);
      parser.setKind(ASTParser.K_COMPILATION_UNIT);
      CompilationUnit unit = (CompilationUnit) parser.createAST(null);
      unit.recordModifications();

      TypeDeclarationFinderVisitor visitor = new TypeDeclarationFinderVisitor();
      unit.accept(visitor);

      AbstractTypeDeclaration declaration = visitor.getTypeDeclaration();
      if (declaration instanceof TypeDeclaration)
      {
         if (((TypeDeclaration) declaration).isInterface())
         {
            return new JavaInterfaceImpl(document, unit);
View Full Code Here

      return result;
   }

   protected AbstractTypeDeclaration getBodyDeclaration()
   {
      TypeDeclarationFinderVisitor typeDeclarationFinder = new TypeDeclarationFinderVisitor();
      unit.accept(typeDeclarationFinder);
      AbstractTypeDeclaration declaration = typeDeclarationFinder.getTypeDeclaration();
      if (declaration == null)
      {
         throw new RuntimeException(
                  "A type-declaration is required in order to complete the current operation, but no type-declaration exists in compilation unit: "
                           + unit.toString());
View Full Code Here

      parser.setResolveBindings(true);
      parser.setKind(ASTParser.K_COMPILATION_UNIT);
      CompilationUnit unit = (CompilationUnit) parser.createAST(null);
      unit.recordModifications();

      TypeDeclarationFinderVisitor visitor = new TypeDeclarationFinderVisitor();
      unit.accept(visitor);

      AbstractTypeDeclaration declaration = visitor.getTypeDeclaration();
      if (declaration instanceof TypeDeclaration)
      {
         if (((TypeDeclaration) declaration).isInterface())
         {
            return new JavaInterfaceImpl(document, unit);
View Full Code Here

      parser.setResolveBindings(true);
      parser.setKind(ASTParser.K_COMPILATION_UNIT);
      CompilationUnit unit = (CompilationUnit) parser.createAST(null);
      unit.recordModifications();

      TypeDeclarationFinderVisitor visitor = new TypeDeclarationFinderVisitor();
      unit.accept(visitor);

      AbstractTypeDeclaration declaration = visitor.getTypeDeclaration();
      if (declaration instanceof TypeDeclaration)
      {
         if (((TypeDeclaration) declaration).isInterface())
         {
            return new JavaInterfaceImpl(document, unit);
View Full Code Here

      return result;
   }

   protected AbstractTypeDeclaration getBodyDeclaration()
   {
      TypeDeclarationFinderVisitor typeDeclarationFinder = new TypeDeclarationFinderVisitor();
      unit.accept(typeDeclarationFinder);
      AbstractTypeDeclaration declaration = typeDeclarationFinder.getTypeDeclaration();
      if (declaration == null)
      {
         throw new RuntimeException(
                  "A type-declaration is required in order to complete the current operation, but no type-declaration exists in compilation unit: "
                           + unit.toString());
View Full Code Here

   }

   private List<AbstractTypeDeclaration> getNestedDeclarations(ASTNode body)
   {

      TypeDeclarationFinderVisitor typeDeclarationFinder = new TypeDeclarationFinderVisitor();
      body.accept(typeDeclarationFinder);
      List<AbstractTypeDeclaration> declarations = typeDeclarationFinder.getTypeDeclarations();

      List<AbstractTypeDeclaration> result = new ArrayList<AbstractTypeDeclaration>(declarations);
      if (!declarations.isEmpty())
      {
         // We don't want to return the current class' declaration.
View Full Code Here

      return Collections.unmodifiableList(result);
   }

   private List<AbstractTypeDeclaration> getNestedDeclarations(BodyDeclaration body)
   {
      final TypeDeclarationFinderVisitor typeDeclarationFinder = new TypeDeclarationFinderVisitor();
      body.accept(typeDeclarationFinder);
      final List<AbstractTypeDeclaration> declarations = typeDeclarationFinder.getTypeDeclarations();

      final List<AbstractTypeDeclaration> result = new ArrayList<AbstractTypeDeclaration>(declarations);
      if (!declarations.isEmpty())
      {
         // We don't want to return the current enum constant body's declaration.
View Full Code Here

TOP

Related Classes of org.jboss.forge.parser.java.ast.TypeDeclarationFinderVisitor

Copyright © 2018 www.massapicom. 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.