Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Problems with Enum

I hope I do. My CompilationUnit provider looks like this:

public static CompilationUnit getCompilationUnit(String srcFile) throws IOException {
       BufferedReader in = new BufferedReader(new FileReader(srcFile));
       StringBuffer sb = new StringBuffer("");
       String line = null;
       while((line = in.readLine()) != null){
           sb.append(line + "\n");
       }
       ASTParser parser = ASTParser.newParser(AST.JLS3);
       parser.setCompilerOptions(new HashMap());
       parser.setKind(ASTParser.K_COMPILATION_UNIT);
       parser.setSource(sb.toString().toCharArray());
       parser.setResolveBindings(true);
       return (CompilationUnit) parser.createAST(null);
   }

I need java 1.5 (so I use AST.JLS3 instead of 2) rest seems ok. Moreover I checked the oroginal eclipse packagrs (withoud org.aspectj prefix) and it still doesn't work. Maybe this is not the way how enums should be handled.
Are you following the (minimal...) instructions from the eclipse wiki?

http://wiki.eclipse.org/index.php/Developer's_guide_to_building_tools_on_top_of_AJDT_and_AspectJ#Using_the_AspectJ_AST_parser



On 28/11/2007, Andy Clement <andrew.clement@xxxxxxxxx> wrote:
I know your code is simple java code. But I have never used the class
org.aspectj.org.eclipse.jdt.core.dom.ASTVisitor and would not support
that as an entry point to AST processing.  If you just want to parse
pure java, use the standard compiler classes and not the org.aspectj
prefixed classes.

But I would raise a bug if it does not work with AjASTVisitor

Andy.

On 28/11/2007, Wojto <jestem.wojtek@xxxxxxxxxx> wrote:
My code isn't AspectJ code. It's simple Java 1.5 code. I tried changing
my visitor to AjASTVisitor, but it still doesn't work.

I suspect you should be using AjASTVisitor as the superclass if you
intend to process AspectJ code eventually.  Be aware that the AspectJ
AST support is not complete - we are accepting contributions from
anyone who wants to fill in missing pieces.  I'm surprised enum isn't
working for you though, I would have imagined it is merely the AJ
constructs that are not visited correctly.

On 28/11/2007, Wojto <jestem.wojtek@xxxxxxxxxx> wrote:

Hello everybody! I'm new here so I find it nice to say hello in the very
beginning :-)

And now to the point... I'm trying to write a simple mertic-counting
tool. I decided to use aspectj's AST. Currently I'm trying to make out
the api of the ast (as in eclipse I find it tricky). Everything works
fine for classes but not for enum's. My code looks like this:

import java.util.ArrayList;

import org.aspectj.org.eclipse.jdt.core.dom.ASTVisitor;
import org.aspectj.org.eclipse.jdt.core.dom.AnonymousClassDeclaration;
import org.aspectj.org.eclipse.jdt.core.dom.CompilationUnit;
import org.aspectj.org.eclipse.jdt.core.dom.EnumDeclaration;
import org.aspectj.org.eclipse.jdt.core.dom.MethodDeclaration;

import pl.wirp.user23.logic.metrics.beans.MetricResult;

public class NLOCVisitor extends ASTVisitor {

    private ArrayList<MetricResult> result = new ArrayList<MetricResult>();

    public ArrayList<MetricResult> getResult() {
        return result;
    }

......

    @Override
    public boolean visit(EnumDeclaration ed) {
        System.out.println(ed.toString());
        return true;
    }

    @Override
    public boolean visit(AnonymousClassDeclaration acd) {
        System.out.println(acd);
        return true;
    }

   ...
}

I want (by now) write the source of my enum on standard out. Similar
code for classes works fine, but for enums nothing happens. Methodes
aren't even invoked.
My enum class looks like this:
public enum BasicEnum {
    A = 1, B = 2, C = 3;
    public int getNumberOfEnumerators(){
        return 3;
    }
}

so it's really simple.
I would appreciate any help. Thanks!
Wojtek

----------------------------------------------------------------------
"Kup bilet na najlepsze zawody Freestyle Motocross - DIVERSE Night of
the Jumps!" http://link.interia.pl/f1c5f

_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users


_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users




----------------------------------------------------------------------
Odmienila swoje oblicze a Ty ... ??

http://link.interia.pl/f1c86
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users

_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users





----------------------------------------------------------------------
Bedac w toalecie korzystala z ...

  http://link.interia.pl/f1c2a



Back to the top