001// Copyright 2010, 2012 The Apache Software Foundation 002// 003// Licensed under the Apache License, Version 2.0 (the "License"); 004// you may not use this file except in compliance with the License. 005// You may obtain a copy of the License at 006// 007// http://www.apache.org/licenses/LICENSE-2.0 008// 009// Unless required by applicable law or agreed to in writing, software 010// distributed under the License is distributed on an "AS IS" BASIS, 011// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012// See the License for the specific language governing permissions and 013// limitations under the License. 014 015package org.apache.tapestry5.internal.services; 016 017import org.apache.tapestry5.services.StackTraceElementAnalyzer; 018import org.apache.tapestry5.services.StackTraceElementClassConstants; 019 020/** 021 * Encapsulates a number of tests for identifying stack frames that are a side-effect 022 * of various Tapestry Aspect Oriented Programming and other code generation behaviors. 023 * 024 * @since 5.2.0 025 */ 026public class TapestryAOPStackFrameAnalyzer implements StackTraceElementAnalyzer 027{ 028 private static final String[] SYNTHETIC_METHOD_PREFIXES = new String[] 029 {"conduit_get_", "conduit_set_", "reject_field_change_", "shim_set_", "shim_get_"}; 030 031 public String classForFrame(StackTraceElement frame) 032 { 033 if (omit(frame)) 034 return StackTraceElementClassConstants.OMITTED; 035 036 return null; 037 } 038 039 private boolean omit(StackTraceElement frame) 040 { 041 if (frame.getClassName().equals("org.apache.tapestry5.internal.plastic.MethodHandleImpl")) 042 { 043 return true; 044 } 045 046 if (frame.getMethodName().equals("invoke") && frame.getClassName().contains("$MethodAccess_")) 047 { 048 return true; 049 } 050 051 if (frame.getMethodName().equals("proceedToAdvisedMethod") && frame.getClassName().contains("$Invocation_")) 052 { 053 return true; 054 } 055 056 if (frame.getMethodName().equals("invoke") && frame.getClassName().contains("$Shim_")) 057 { 058 return true; 059 } 060 061 for (String prefix : SYNTHETIC_METHOD_PREFIXES) 062 { 063 if (frame.getMethodName().startsWith(prefix)) 064 return true; 065 } 066 067 return false; 068 } 069 070}