Example usage for org.aspectj.lang.reflect SourceLocation getWithinType

List of usage examples for org.aspectj.lang.reflect SourceLocation getWithinType

Introduction

In this page you can find the example usage for org.aspectj.lang.reflect SourceLocation getWithinType.

Prototype

Class getWithinType();

Source Link

Usage

From source file:com.arpnetworking.steno.aspect.LogBuilderAspect.java

License:Apache License

/**
 * Before outputting the message inject additional context.
 *
 * @param joinPoint The <code>JoinPoint</code>.
 *//*from  w w  w.  j  av a  2 s. c  o m*/
@Before("call(* com.arpnetworking.steno.LogBuilder.log())")
public void addToContextLineAndMethod(final JoinPoint joinPoint) {
    final SourceLocation sourceLocation = joinPoint.getSourceLocation();
    final LogBuilder targetLogBuilder = (LogBuilder) joinPoint.getTarget();
    targetLogBuilder.addContext("line", String.valueOf(sourceLocation.getLine()));
    targetLogBuilder.addContext("file", sourceLocation.getFileName());
    targetLogBuilder.addContext("class", sourceLocation.getWithinType());
}

From source file:com.github.woozoo73.ht.SourceLocationInfo.java

License:Apache License

@SuppressWarnings("deprecation")
public SourceLocationInfo(SourceLocation sourceLocation) {
    if (sourceLocation == null) {
        return;//  w  w  w.  j  ava 2  s .  c om
    }

    this.withinType = sourceLocation.getWithinType();
    this.fileName = sourceLocation.getFileName();
    this.line = sourceLocation.getLine();
    this.column = sourceLocation.getColumn();
}

From source file:com.thoughtworks.testme.aspect.TestCoveringAClassObserverHelper.java

License:Open Source License

/**
 * Record the TestCase that initialized a class (even if the class is a super-type of, or called by, a directly tested class). The file name of the source code for the class is the key used for
 * this record (e.g. "com/example/YourClass.java"). The path of the class file name is relative to some source root (e.g. "YourProject/src/").
 * //from  www .j  a  v  a 2 s.co  m
 * @param SourceLocation
 *            of the weaved join point
 * @param TestCase
 *            that is currently executing
 */
static void recordLink(SourceLocation location, TestCase testCase) {
    String classFileNameUnqualified = location.getFileName(); // Xerox code doesn't include any path info - grrrr.
    String classFileDirectory = location.getWithinType().getPackage().getName().replace('.', '/'); // use the package to derive a path
    String classFileName = classFileDirectory + "/" + classFileNameUnqualified;

    String testName = testCase.getClass().getCanonicalName();

    log.fine("Class source file: " + classFileName + " covered by test case: " + testName);
    db.add(classFileName, testName);
}

From source file:org.springframework.aop.aspectj.MethodInvocationProceedingJoinPointTests.java

License:Apache License

@Test
public void testCanGetSourceLocationFromJoinPoint() {
    final Object raw = new TestBean();
    ProxyFactory pf = new ProxyFactory(raw);
    pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
    pf.addAdvice(new MethodBeforeAdvice() {
        @Override//from   ww w.  ja v  a2  s .  co m
        public void before(Method method, Object[] args, Object target) throws Throwable {
            SourceLocation sloc = AbstractAspectJAdvice.currentJoinPoint().getSourceLocation();
            assertEquals("Same source location must be returned on subsequent requests", sloc,
                    AbstractAspectJAdvice.currentJoinPoint().getSourceLocation());
            assertEquals(TestBean.class, sloc.getWithinType());
            try {
                sloc.getLine();
                fail("Can't get line number");
            } catch (UnsupportedOperationException ex) {
                // Expected
            }

            try {
                sloc.getFileName();
                fail("Can't get file name");
            } catch (UnsupportedOperationException ex) {
                // Expected
            }
        }
    });
    ITestBean itb = (ITestBean) pf.getProxy();
    // Any call will do
    itb.getAge();
}