/** * 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; }
@Override public void enterMethodDeclaration(@NotNull JavaParser.MethodDeclarationContext ctx) { // Peek JavaId and ensure it is a class or enum final JavaId class_ctx = (JavaId) this.contextStack.peek().getConstructId(); this.isOfExpectedType(class_ctx, new JavaId.Type[] { JavaId.Type.CLASS, JavaId.Type.ENUM }, true); // Build the identifier final JavaMethodId id = new JavaMethodId((JavaId) class_ctx, ctx.IDENTIFIER().getText(), this.getParameters(ctx.formalParameters().formalParameterList())); this.contextStack.push(id); this.saveConstruct(id, this.getConstructContent(ctx)); }