/** * Returns true if the method has the @Test annotation or both the method name and its class name have the postfix or suffix 'test'. * @return */ public boolean isTestMethod() { boolean is_test = this.hasAnnotation("Test"); // @Test annotation not found, let's check the qualified names of the class context and the method itself if(!is_test && this.context.getType().equals(JavaId.Type.CLASS)) { is_test = ((JavaClassId)this.context).isTestClass() && (this.methodId.toLowerCase().startsWith("test") || this.methodId.toLowerCase().endsWith("test")); } return is_test; } }
/** * Creates a {@link JavaMethodId} from the given string, with a definition context of the given type. * Accepted types are {@link JavaId.Type#CLASS} and {@link JavaId.Type#ENUM}. * @param _s * @return */ public static JavaMethodId parseMethodQName(JavaId.Type _ctx_type, String _s) { if(_s == null || _s.equals("")) throw new IllegalArgumentException("String null or empty"); if(_ctx_type==null || (!_ctx_type.equals(JavaId.Type.CLASS) && !_ctx_type.equals(JavaId.Type.ENUM))) throw new IllegalArgumentException("Accepts context types CLASS or ENUM, got [" + _ctx_type + "]"); final int i = _s.indexOf('('); if(i==-1 || !_s.endsWith(")")) throw new IllegalArgumentException("String does not contain brackets (), as required for qualified names for Java methods"); final int j = _s.lastIndexOf('.', i); if(j==-1) throw new IllegalArgumentException("String does not contain dot (.), as required for qualified names for Java methods (as to separate class and method name)"); JavaId def_ctx = null; JavaMethodId mid = null; try { if(_ctx_type.equals(JavaId.Type.CLASS)) def_ctx = JavaId.parseClassQName(_s.substring(0, j)); else if(_ctx_type.equals(JavaId.Type.ENUM)) def_ctx = JavaId.parseEnumQName(_s.substring(0, j)); mid = new JavaMethodId(def_ctx, _s.substring(j+1, i), JavaId.parseParameterTypes(_s.substring(i+1, _s.length()-1))); } catch(StringIndexOutOfBoundsException e) { JavaId.log.error("Exception while parsing the string '" + _s + "'"); } return mid; }
if(_ctx_type==null || (!_ctx_type.equals(JavaId.Type.CLASS) && !_ctx_type.equals(JavaId.Type.ENUM))) throw new IllegalArgumentException("Accepts context types CLASS or ENUM, got [" + _ctx_type + "]"); JavaConstructorId coid = null; try { if(_ctx_type.equals(JavaId.Type.CLASS)) def_ctx = JavaId.parseClassQName(_s.substring(0, i)); else if(_ctx_type.equals(JavaId.Type.ENUM)) def_ctx = JavaId.parseEnumQName(_s.substring(0, i));
if( (Boolean.valueOf((String)_params.get("junit")) || Boolean.valueOf((String)_params.get("path"))) && _params.get("stacktrace")!=null && !c_type.equals(JavaId.Type.CLASSINIT)) {
if (topmost_stack_entry!=null && ( (JavaId)topmost_stack_entry.getConstructId()).type.equals(JavaId.Type.METHOD)) {
/** * Gets the top-most element <a>of a given types</a> (without removing it). * * @param _t * the type of context elements to consider * @return */ public ContextStackEntry peek(JavaId.Type[] _t) { final Iterator<ContextStackEntry> iterator = this.nestedDeclarationContexts.iterator(); ContextStackEntry entry = null, result = null; search: while (iterator.hasNext()) { entry = iterator.next(); for(int i=0; i<_t.length; i++ ){ if (((JavaId)entry.getConstructId()).getType().equals(_t[i])) { result = entry; break search; } } } return result; }
@Deprecated public boolean headMatches(JavaId.Type[] pattern) { boolean result = true; int patternElementIndex = 0; ContextStackEntry construct = null; Iterator<ContextStackEntry> itr = this.iterator(); while (itr.hasNext() && patternElementIndex < pattern.length) { construct = itr.next(); if (!pattern[patternElementIndex].equals(((JavaId) construct.getConstructId()).type)) { result = false; break; } else { patternElementIndex++; } } return result; }
/** * * @param _jid * @return */ private JavaId getCompilationUnit(JavaId _jid) { // Got it --> return provided object if( (_jid.getType().equals(JavaId.Type.CLASS) && !((JavaClassId)_jid).isNestedClass()) || (_jid.getType().equals(JavaId.Type.INTERFACE) && !((JavaInterfaceId)_jid).isNested()) || (_jid.getType().equals(JavaId.Type.ENUM) && !((JavaEnumId)_jid).isNested()) ) { return _jid; } else { return this.getCompilationUnit((JavaId)_jid.getDefinitionContext()); } }
public boolean isNestedClass() { return this.declarationContext!=null && !this.declarationContext.getType().equals(JavaId.Type.PACKAGE); }
/** * Returns true if the interface is not directly declared within a package, but within another construct like a class or interface. * @return */ public boolean isNested() { return this.declarationContext!=null && !this.declarationContext.getType().equals(JavaId.Type.PACKAGE); }
/** * Returns true if the enum is not directly declared within a package, but within another construct like a class or interface. * @return */ public boolean isNested() { return this.declarationContext!=null && !this.declarationContext.getType().equals(JavaId.Type.PACKAGE); }