Example usage for org.aspectj.org.eclipse.jdt.core.dom AdviceDeclaration getPointcut

List of usage examples for org.aspectj.org.eclipse.jdt.core.dom AdviceDeclaration getPointcut

Introduction

In this page you can find the example usage for org.aspectj.org.eclipse.jdt.core.dom AdviceDeclaration getPointcut.

Prototype

public PointcutDesignator getPointcut() 

Source Link

Usage

From source file:org.eclipse.ajdt.core.tests.dom.rewrite.ASTRewritingPointcutDeclTest.java

License:Open Source License

public void testBeforePointcutRename() throws Exception {
    IProject project = createPredefinedProject("AST"); //$NON-NLS-1$
    Map compilerOptions = JavaCore.create(project).getOptions(true);

    // add node, change ASTVisitor and ASTMatcher
    // update ASTConverter and ASTRewriteAnalyzer
    Document doc = new Document("aspect A {\n" //$NON-NLS-1$
            + "    public pointcut a();\n" //$NON-NLS-1$
            + "    public pointcut b();\n" + "    before(): a() {}\n" //$NON-NLS-1$ //$NON-NLS-2$
            + "}\n"); //$NON-NLS-1$
    ASTParser parser = ASTParser.newParser(AST.JLS2); // ajh02: need to
    // use 2 for// w  w  w  .  j  a v  a  2s .c o m
    // returnType - in 3
    // it has
    // "returnType2"
    parser.setSource(doc.get().toCharArray());
    parser.setCompilerOptions(compilerOptions);
    CompilationUnit astRoot = (CompilationUnit) parser.createAST(null);
    AjASTRewrite rewrite = AjASTRewrite.create(astRoot.getAST());
    AST ast = astRoot.getAST();
    AspectDeclaration type = (AspectDeclaration) findAbstractTypeDeclaration(astRoot, "A"); //$NON-NLS-1$
    { // rename before advice pointcut expression
        AdviceDeclaration adviceDeclaration = (AdviceDeclaration) type.getAdvice().get(0);
        ReferencePointcut referencePointcut = (ReferencePointcut) adviceDeclaration.getPointcut();
        SimpleName name = referencePointcut.getName();
        SimpleName newName = ast.newSimpleName("b"); //$NON-NLS-1$
        rewrite.replace(name, newName, null);
    }
    String expected = "aspect A {\n" + "    public pointcut a();\n" //$NON-NLS-1$ //$NON-NLS-2$
            + "    public pointcut b();\n" + "    before(): b() {}\n" //$NON-NLS-1$ //$NON-NLS-2$
            + "}\n"; //$NON-NLS-1$
    check(rewrite, doc, expected, compilerOptions);
}

From source file:org.eclipse.ajdt.core.tests.dom.rewrite.ASTRewritingPointcutDeclTest.java

License:Open Source License

public void testAfterPointcutRename() throws Exception {
    IProject project = createPredefinedProject("AST"); //$NON-NLS-1$
    Map compilerOptions = JavaCore.create(project).getOptions(true);

    // add node, change ASTVisitor and ASTMatcher
    // update ASTConverter and ASTRewriteAnalyzer
    Document doc = new Document("aspect A {\n" //$NON-NLS-1$
            + "    public pointcut a();\n" //$NON-NLS-1$
            + "    public pointcut b();\n" + "    after(): a() {}\n" //$NON-NLS-1$ //$NON-NLS-2$
            + "}\n"); //$NON-NLS-1$
    ASTParser parser = ASTParser.newParser(AST.JLS2); // ajh02: need to
    // use 2 for//from w  ww.  j av a 2  s.c o  m
    // returnType - in 3
    // it has
    // "returnType2"
    parser.setSource(doc.get().toCharArray());
    parser.setCompilerOptions(compilerOptions);
    CompilationUnit astRoot = (CompilationUnit) parser.createAST(null);
    AjASTRewrite rewrite = AjASTRewrite.create(astRoot.getAST());
    AST ast = astRoot.getAST();
    AspectDeclaration type = (AspectDeclaration) findAbstractTypeDeclaration(astRoot, "A"); //$NON-NLS-1$
    { // rename after advice pointcut expression
        AdviceDeclaration adviceDeclaration = (AdviceDeclaration) type.getAdvice().get(0);
        ReferencePointcut referencePointcut = (ReferencePointcut) adviceDeclaration.getPointcut();
        SimpleName name = referencePointcut.getName();
        SimpleName newName = ast.newSimpleName("b"); //$NON-NLS-1$
        rewrite.replace(name, newName, null);
    }
    String expected = "aspect A {\n" + "    public pointcut a();\n" //$NON-NLS-1$ //$NON-NLS-2$
            + "    public pointcut b();\n" + "    after(): b() {}\n" //$NON-NLS-1$ //$NON-NLS-2$
            + "}\n"; //$NON-NLS-1$
    check(rewrite, doc, expected, compilerOptions);
}

From source file:org.eclipse.ajdt.core.tests.dom.rewrite.ASTRewritingPointcutDeclTest.java

License:Open Source License

public void testAroundPointcutRename() throws Exception {
    IProject project = createPredefinedProject("AST"); //$NON-NLS-1$
    Map compilerOptions = JavaCore.create(project).getOptions(true);

    // add node, change ASTVisitor and ASTMatcher
    // update ASTConverter and ASTRewriteAnalyzer
    Document doc = new Document("aspect A {\n" //$NON-NLS-1$
            + "    public pointcut a();\n" //$NON-NLS-1$
            + "    public pointcut b();\n" //$NON-NLS-1$
            + "    void around(): a() {}\n" + "}\n"); //$NON-NLS-1$ //$NON-NLS-2$
    ASTParser parser = ASTParser.newParser(AST.JLS2); // ajh02: need to
    // use 2 for/*  w  w  w  .jav a  2s  .co m*/
    // returnType - in 3
    // it has
    // "returnType2"
    parser.setSource(doc.get().toCharArray());
    parser.setCompilerOptions(compilerOptions);
    CompilationUnit astRoot = (CompilationUnit) parser.createAST(null);
    AjASTRewrite rewrite = AjASTRewrite.create(astRoot.getAST());
    AST ast = astRoot.getAST();
    AspectDeclaration type = (AspectDeclaration) findAbstractTypeDeclaration(astRoot, "A"); //$NON-NLS-1$
    { // rename around advice pointcut expression
        AdviceDeclaration adviceDeclaration = (AdviceDeclaration) type.getAdvice().get(0);
        ReferencePointcut referencePointcut = (ReferencePointcut) adviceDeclaration.getPointcut();
        SimpleName name = referencePointcut.getName();
        SimpleName newName = ast.newSimpleName("b"); //$NON-NLS-1$
        rewrite.replace(name, newName, null);
    }
    String expected = "aspect A {\n" + "    public pointcut a();\n" //$NON-NLS-1$ //$NON-NLS-2$
            + "    public pointcut b();\n" //$NON-NLS-1$
            + "    void around(): b() {}\n" + "}\n"; //$NON-NLS-1$ //$NON-NLS-2$
    check(rewrite, doc, expected, compilerOptions);
}