@Nullable
  public static MethodReferenceBag getMethodParameterReferenceBag(
      PsiElement psiElement, int wantIndex) {

    PsiElement variableContext = psiElement.getContext();
    if (!(variableContext instanceof ParameterList)) {
      return null;
    }

    ParameterList parameterList = (ParameterList) variableContext;
    if (!(parameterList.getContext() instanceof MethodReference)) {
      return null;
    }

    ParameterBag currentIndex = PsiElementUtils.getCurrentParameterIndex(psiElement);
    if (currentIndex == null) {
      return null;
    }

    if (wantIndex >= 0 && currentIndex.getIndex() != wantIndex) {
      return null;
    }

    return new MethodReferenceBag(
        parameterList, (MethodReference) parameterList.getContext(), currentIndex);
  }
  public static boolean isFunctionReference(
      PsiElement psiElement, int wantIndex, String... funcName) {

    PsiElement variableContext = psiElement.getContext();
    if (!(variableContext instanceof ParameterList)) {
      return false;
    }

    ParameterList parameterList = (ParameterList) variableContext;
    PsiElement context = parameterList.getContext();
    if (!(context instanceof FunctionReference)) {
      return false;
    }

    FunctionReference methodReference = (FunctionReference) context;
    String name = methodReference.getName();

    if (name == null || !Arrays.asList(funcName).contains(name)) {
      return false;
    }

    ParameterBag currentIndex = getCurrentParameterIndex(psiElement);
    if (currentIndex == null) {
      return false;
    }

    return !(wantIndex >= 0 && currentIndex.getIndex() != wantIndex);
  }
  @Nullable
  public static ParameterBag getCurrentParameterIndex(PsiElement psiElement) {

    if (!(psiElement.getContext() instanceof ParameterList)) {
      return null;
    }

    ParameterList parameterList = (ParameterList) psiElement.getContext();
    if (!(parameterList.getContext() instanceof ParameterListOwner)) {
      return null;
    }

    return getCurrentParameterIndex(parameterList.getParameters(), psiElement);
  }
Ejemplo n.º 4
0
 /**
  * Get a {@link ParameterList} with the query string parameters.
  * 
  * @return a {@link ParameterList} containing the query string parameters.
  * @throws OAuthException if the request URL is not valid.
  */
 public ParameterList getQueryStringParams()
 {
   try
   {
     ParameterList result = new ParameterList();
     String queryString = new URL(url).getQuery();
     result.addQuerystring(queryString);
     result.addAll(querystringParams);
     return result;
   }
   catch (MalformedURLException mue)
   {
     throw new OAuthException("Malformed URL", mue);
   }
 }
Ejemplo n.º 5
0
 public ParameterList getParameterList() {
   ParameterList paramList = new ParameterList();
   String uri = getURI();
   if (uri == null) return paramList;
   int paramIdx = uri.indexOf('?');
   if (paramIdx < 0) return paramList;
   while (0 < paramIdx) {
     int eqIdx = uri.indexOf('=', (paramIdx + 1));
     String name = uri.substring(paramIdx + 1, eqIdx);
     int nextParamIdx = uri.indexOf('&', (eqIdx + 1));
     String value = uri.substring(eqIdx + 1, (0 < nextParamIdx) ? nextParamIdx : uri.length());
     Parameter param = new Parameter(name, value);
     paramList.add(param);
     paramIdx = nextParamIdx;
   }
   return paramList;
 }
Ejemplo n.º 6
0
 byte[] getByteBodyContents()
 {
   if (bytePayload != null) return bytePayload;
   String body = (payload != null) ? payload : bodyParams.asFormUrlEncodedString();
   try
   {
     return body.getBytes(getCharset());
   }
   catch(UnsupportedEncodingException uee)
   {
     throw new OAuthException("Unsupported Charset: "+getCharset(), uee);
   }
 }
  /**
   * Extract type hint from method parameter
   *
   * <p>function foo(\FooClass $class)
   */
  @Nullable
  public static String getMethodParameterTypeHint(@NotNull Method method) {
    ParameterList childOfType = PsiTreeUtil.getChildOfType(method, ParameterList.class);
    if (childOfType == null) {
      return null;
    }

    PsiElement[] parameters = childOfType.getParameters();
    if (parameters.length == 0) {
      return null;
    }

    ClassReference classReference = PsiTreeUtil.getChildOfType(parameters[0], ClassReference.class);
    if (classReference == null) {
      return null;
    }

    String fqn = classReference.getFQN();
    if (fqn == null) {
      return null;
    }

    return fqn;
  }
Ejemplo n.º 8
0
 /**
  * Returns the complete url (host + resource + encoded querystring parameters).
  *
  * @return the complete url.
  */
 public String getCompleteUrl()
 {
   return querystringParams.appendTo(url);
 }
Ejemplo n.º 9
0
 public String getParameterValue(String name) {
   ParameterList paramList = getParameterList();
   return paramList.getValue(name);
 }