List of usage examples for org.aspectj.lang.reflect SourceLocation getLine
int getLine();
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>. */// w ww . j a v a2s . c om @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;//from ww w . j av a 2 s .c o m } this.withinType = sourceLocation.getWithinType(); this.fileName = sourceLocation.getFileName(); this.line = sourceLocation.getLine(); this.column = sourceLocation.getColumn(); }
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/* ww w. j av a2 s.c om*/ 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(); }