public void registerReferenceProviders(PsiReferenceRegistrar registrar) {
   registrar.registerReferenceProvider(
       PsiJavaPatterns.literalExpression()
           .annotationParam("org.unitils.dbunit.annotation.DataSet", "value"),
       new URIReferenceProvider(),
       PsiReferenceRegistrar.HIGHER_PRIORITY);
   registrar.registerReferenceProvider(
       PsiJavaPatterns.literalExpression()
           .annotationParam("org.unitils.dbunit.annotation.ExpectedDataSet", "value"),
       new URIReferenceProvider(),
       PsiReferenceRegistrar.HIGHER_PRIORITY);
   registrar.registerReferenceProvider(
       PsiJavaPatterns.literalExpression()
           .insideAnnotationParam(
               PlatformPatterns.string()
                   .with(
                       new PatternCondition<String>("DataSet") {
                         public boolean accepts(
                             @NotNull final String annotationFQN,
                             final ProcessingContext context) {
                           return annotationFQN.equals("org.unitils.dbunit.annotation.DataSet");
                         }
                       }),
               "value"),
       new URIReferenceProvider());
 }
  public void registerReferenceProviders(final PsiReferenceRegistrar registrar) {
    registrar.registerReferenceProvider(
        psiElement(GrLiteral.class), new PropertiesReferenceProvider());

    registrar.registerReferenceProvider(
        psiElement(GroovyDocPsiElement.class), new GroovyDocReferenceProvider());

    registrar.registerReferenceProvider(
        GroovyPatterns.stringLiteral().withParent(GrAnnotationNameValuePair.class),
        new SpockUnrollReferenceProvider());
  }
  @Override
  public void registerReferenceProviders(PsiReferenceRegistrar psiReferenceRegistrar) {

    psiReferenceRegistrar.registerReferenceProvider(
        PlatformPatterns.psiElement(StringLiteralExpression.class),
        new PsiReferenceProvider() {
          @NotNull
          @Override
          public PsiReference[] getReferencesByElement(
              @NotNull PsiElement psiElement, @NotNull ProcessingContext processingContext) {
            if (!Symfony2ProjectComponent.isEnabled(psiElement)
                || !(psiElement.getContext() instanceof ParameterList)) {
              return new PsiReference[0];
            }

            ParameterList parameterList = (ParameterList) psiElement.getContext();

            if (parameterList == null || !(parameterList.getContext() instanceof MethodReference)) {
              return new PsiReference[0];
            }

            MethodReference method = (MethodReference) parameterList.getContext();
            Symfony2InterfacesUtil interfacesUtil = new Symfony2InterfacesUtil();
            if (!interfacesUtil.isTranslatorCall(method)) {
              return new PsiReference[0];
            }

            int domainParameter = 2;
            if (method.getName().equals("transChoice")) {
              domainParameter = 3;
            }

            ParameterBag currentIndex = PsiElementUtils.getCurrentParameterIndex(psiElement);
            if (currentIndex == null) {
              return new PsiReference[0];
            }

            if (currentIndex.getIndex() == domainParameter) {
              return new PsiReference[] {
                new TranslationDomainReference((StringLiteralExpression) psiElement)
              };
            }

            if (currentIndex.getIndex() == 0) {
              String domain = PsiElementUtils.getMethodParameterAt(parameterList, domainParameter);

              if (domain == null) {
                domain = "messages";
              }

              return new PsiReference[] {
                new TranslationReference((StringLiteralExpression) psiElement, domain)
              };
            }

            return new PsiReference[0];
          }
        });
  }
  @Override
  public void registerReferenceProviders(PsiReferenceRegistrar registrar) {

    registrar.registerReferenceProvider(
        XmlHelper.getRouteConfigControllerPattern(),
        new PsiReferenceProvider() {
          @NotNull
          @Override
          public PsiReference[] getReferencesByElement(
              @NotNull PsiElement psiElement, @NotNull ProcessingContext processingContext) {

            if (!Symfony2ProjectComponent.isEnabled(psiElement)) {
              return new PsiReference[0];
            }

            return new PsiReference[] {new RouteActionReference(psiElement)};
          }
        });
  }
 @Override
 public void registerReferenceProviders(PsiReferenceRegistrar registrar) {
   registrar.registerReferenceProvider(
       XmlPatterns.xmlAttributeValue().withLocalName("key"),
       new PsiReferenceProvider() {
         @NotNull
         @Override
         public PsiReference[] getReferencesByElement(
             @NotNull PsiElement element, @NotNull ProcessingContext context) {
           PropertiesFile propertiesFile =
               PropertiesImplUtil.getPropertiesFile(element.getContainingFile());
           if (propertiesFile == null) return PsiReference.EMPTY_ARRAY;
           XmlProperty property =
               new XmlProperty(
                   PsiTreeUtil.getParentOfType(element, XmlTag.class),
                   (XmlPropertiesFileImpl) propertiesFile);
           return new PsiReference[] {
             new PsiReferenceBase.Immediate<PsiElement>(element, PomService.convertToPsi(property))
           };
         }
       });
 }
 @Override
 public void registerReferenceProviders(PsiReferenceRegistrar psiReferenceRegistrar) {
   psiReferenceRegistrar.registerReferenceProvider(
       StandardPatterns.psiElement(CSharpCallArgumentList.class)
           .withParent(CSharpArrayAccessExpressionImpl.class),
       new PsiReferenceProvider() {
         @NotNull
         @Override
         public PsiReference[] getReferencesByElement(
             @NotNull PsiElement element, @NotNull ProcessingContext processingContext) {
           CSharpArrayAccessExpressionImpl parent =
               (CSharpArrayAccessExpressionImpl) element.getParent();
           PsiElement callable = parent.resolveToCallable();
           if (callable == null) {
             return PsiReference.EMPTY_ARRAY;
           }
           return new PsiReference[] {
             new PsiReferenceBase.Immediate<PsiElement>(
                 element, new TextRange(0, element.getTextLength()), callable)
           };
         }
       });
 }
 @Override
 public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {
   registrar.registerReferenceProvider(
       REF_PATTERN, new JsonPropertyName2SchemaDefinitionReferenceProvider());
 }
Exemplo n.º 8
0
 @Override
 public void registerReferenceProviders(PsiReferenceRegistrar registrar) {
   registrar.registerReferenceProvider(stringLiteral(), new MyProvider());
 }
  @Override
  public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {
    registrar.registerReferenceProvider(
        HEREDOC_TERMINATOR_PATTERN,
        new PsiReferenceProvider() {
          @NotNull
          @Override
          public PsiReference[] getReferencesByElement(
              @NotNull PsiElement element, @NotNull ProcessingContext context) {
            assert element instanceof PerlHeredocTerminatorElementImpl;
            return new PsiReference[] {
              new PerlHeredocReference(element, new TextRange(0, element.getTextLength()))
            };
          }
        });
    registrar.registerReferenceProvider(
        SUB_NAME_PATTERN,
        new PsiReferenceProvider() {
          @NotNull
          @Override
          public PsiReference[] getReferencesByElement(
              @NotNull PsiElement element, @NotNull ProcessingContext context) {
            return new PsiReference[] {
              new PerlSubReference(element, new TextRange(0, element.getTextLength()))
            };
          }
        });
    registrar.registerReferenceProvider(
        VARIABLE_NAME_PATTERN.withParent(VARIABLE_PATTERN),
        new PsiReferenceProvider() {
          @NotNull
          @Override
          public PsiReference[] getReferencesByElement(
              @NotNull PsiElement element, @NotNull ProcessingContext context) {
            assert element instanceof PerlVariableNameElement;
            assert !(element.getParent() instanceof PerlGlobVariable);

            return new PsiReference[] {
              new PerlVariableNameReference(element, new TextRange(0, element.getTextLength()))
            };
          }
        });
    registrar.registerReferenceProvider(
        VARIABLE_NAME_PATTERN.withParent(GLOB_PATTERN),
        new PsiReferenceProvider() {
          @NotNull
          @Override
          public PsiReference[] getReferencesByElement(
              @NotNull PsiElement element, @NotNull ProcessingContext context) {
            assert element instanceof PerlVariableNameElement;
            // check if it's dereference
            PsiElement parent = element.getParent();
            assert parent instanceof PerlGlobVariable
                : "Got: " + parent.getClass() + " in " + parent.getText();

            return new PsiReference[] {
              new PerlGlobVariableNameReference(element, new TextRange(0, element.getTextLength()))
            };
          }
        });
    registrar.registerReferenceProvider(
        NAMESPACE_NAME_PATTERN,
        new PsiReferenceProvider() {
          @NotNull
          @Override
          public PsiReference[] getReferencesByElement(
              @NotNull PsiElement element, @NotNull ProcessingContext context) {
            PsiElement nameSpaceContainer = element.getParent();

            ArrayList<PsiReference> result = new ArrayList<PsiReference>();

            // fixme this should be done using patterns
            if (nameSpaceContainer instanceof PsiPerlUseStatement
                || nameSpaceContainer instanceof PsiPerlRequireExpr)
              result.add(
                  new PerlNamespaceFileReference(
                      element, new TextRange(0, element.getTextLength())));
            else
              result.add(
                  new PerlNamespaceReference(element, new TextRange(0, element.getTextLength())));

            return result.toArray(new PsiReference[result.size()]);
          }
        });
    registrar.registerReferenceProvider(
        STRING_CONENT_PATTERN,
        new PsiReferenceProvider() {
          @NotNull
          @Override
          public PsiReference[] getReferencesByElement(
              @NotNull PsiElement element, @NotNull ProcessingContext context) {
            assert element instanceof PerlStringContentElement;
            if (((PerlStringContentElement) element).looksLikePackage())
              return new PsiReference[] {
                new PerlNamespaceReference(element, new TextRange(0, element.getTextLength()))
              };
            return new PsiReference[0];
          }
        });
  }
  public void registerReferenceProviders(PsiReferenceRegistrar registrar) {
    // errors tag add Reference Provider for Setters Method on parameter field
    registerXmlAttributeReferenceProvider(
        registrar, new SetterMethodsReferenceProvider(FORM_TAG), FIELD_ATTR, ERRORS_TAG);

    // all stripes tags for input form add Reference Provider for Setters Method
    registerXmlAttributeReferenceProvider(
        registrar, new SetterMethodsReferenceProvider(FORM_TAG), NAME_ATTR, INPUT_TAGS);

    // param tag add Reference Provider for Setter Methods
    registerXmlAttributeReferenceProvider(
        registrar, new SetterMethodsReferenceProvider(LINK_TAG), NAME_ATTR, PARAM_TAG);
    registerXmlAttributeReferenceProvider(
        registrar, new SetterMethodsReferenceProvider(URL_TAG), NAME_ATTR, PARAM_TAG);

    registerXmlAttributeReferenceProvider(
        registrar,
        new PsiReferenceProvider() {
          @NotNull
          public PsiReference[] getReferencesByElement(
              @NotNull PsiElement element, @NotNull ProcessingContext context) {
            if (PsiTreeUtil.getChildOfType(element, ELExpressionHolder.class) != null) {
              return PsiReference.EMPTY_ARRAY;
            }

            final PsiClass actionBeanPsiClass =
                StripesReferenceUtil.getBeanClassFromParentTag(
                    (XmlTag) element.getParent().getParent(), FORM_TAG);

            if (null != actionBeanPsiClass) {
              List<String> arr = StringUtil.split(ElementManipulators.getValueText(element), ",");

              List<PsiReference> retval = new LinkedList<PsiReference>();
              int offset = 1;
              for (String anArr : arr) {
                Collections.addAll(
                    retval,
                    new SetterReferenceExSet(anArr, element, offset, '.', actionBeanPsiClass, false)
                        .getPsiReferences());
                offset += (anArr.length() + 1);
              }

              return retval.toArray(new PsiReference[retval.size()]);
            }

            return PsiReference.EMPTY_ARRAY;
          }
        },
        FIELDS_ATTR,
        FIELD_METADATA_TAG);

    registrar.registerReferenceProvider(
        PsiJavaPatterns.literalExpression()
            .and(
                new FilterPattern(
                    new AndFilter(
                        new SuperParentFilter(
                            new QualifiedNameElementFilter(VALIDATE_NESTED_PROPERTIES_ANNOTATION)),
                        new AnnotationParameterFilter(
                            PsiLiteralExpression.class, VALIDATE_ANNOTATION, FIELD_ATTR)))),
        new PsiReferenceProvider() {
          @NotNull
          public PsiReference[] getReferencesByElement(
              @NotNull PsiElement element, @NotNull ProcessingContext context) {
            PsiMember parent = PsiTreeUtil.getParentOfType(element, PsiMethod.class);
            if (parent == null) parent = PsiTreeUtil.getParentOfType(element, PsiField.class);

            PsiClass cls =
                StripesReferenceUtil.resolveClassInType(
                    PropertyUtil.getPropertyType(parent), element.getProject());
            return null == cls
                ? PsiReference.EMPTY_ARRAY
                : new SetterReferenceExSet(element, 1, '.', cls, false).getPsiReferences();
          }
        });

    registrar.registerReferenceProvider(
        PsiJavaPatterns.literalExpression()
            .and(
                new FilterPattern(
                    new OrFilter(
                        new StringArrayAnnotationParameterFilter(
                            STRICT_BINDING_ANNOTATION, ALLOW_ATTR),
                        new StringArrayAnnotationParameterFilter(
                            STRICT_BINDING_ANNOTATION, DENY_ATTR)))),
        new PsiReferenceProvider() {
          @NotNull
          public PsiReference[] getReferencesByElement(
              @NotNull PsiElement element, @NotNull ProcessingContext context) {
            PsiClass cls = PsiTreeUtil.getParentOfType(element, PsiClass.class);
            return null == cls
                ? PsiReference.EMPTY_ARRAY
                : new SetterReferenceExSet(element, 1, '.', cls, false) {
                  @NotNull
                  @Override
                  protected SetterReferenceEx<PsiElement> createReferenceWithBraces(
                      TextRange range, int index, boolean hasBraces) {
                    return new StrictBindingReference(range, this.isSupportBraces(), this, index);
                  }
                }.getPsiReferences();
          }
        });

    registrar.registerReferenceProvider(
        PsiJavaPatterns.literalExpression()
            .and(
                new FilterPattern(
                    new AnnotationParameterFilter(
                        PsiLiteralExpression.class, URL_BINDING_ANNOTATION, VALUE_ATTR))),
        new PsiReferenceProvider() {
          @NotNull
          public PsiReference[] getReferencesByElement(
              @NotNull PsiElement element, @NotNull ProcessingContext context) {
            PsiClass actionBeanPsiClass = PsiTreeUtil.getParentOfType(element, PsiClass.class);
            String str = ElementManipulators.getValueText(element);

            if (null != actionBeanPsiClass && str.startsWith("/")) {
              final List<PsiReference> retval = new LinkedList<PsiReference>();
              for (int i = 0, eqInd = -1, lBraceInd = -1, braceStack = 0; i < str.length(); i++) {
                if (str.charAt(i) == '{') {
                  braceStack++;
                  lBraceInd = i;
                  eqInd = -1;
                } else if (str.charAt(i)
                    == '}') { // we found closing brace and need to retrieve references if possible
                  braceStack--;
                  if (braceStack != 0)
                    continue; // braces are unbalanced - we should not try to parse

                  int endInd =
                      eqInd != -1
                          ? eqInd // there's '=' sign within curly braces bounded part of string.
                                  // processign only part of text located within curl braces
                          : i; // no '=' sign found. process whole text from curly braces;

                  String txt = str.substring(1 + lBraceInd, endInd);
                  if ($EVENT.equals(txt) && eqInd == -1) {
                    retval.add(
                        new UrlBindingReference(
                            element,
                            new TextRange(1 + lBraceInd + 1, 1 + endInd),
                            actionBeanPsiClass));
                  } else {
                    //                                final PsiReference[] psiReferences = new
                    // SetterReferenceExSet(str, element, 1 + lBraceInd + 1, '.',
                    // actionBeanPsiClass, true).getPsiReferences();
                    Collections.addAll(
                        retval,
                        new UrlSetterReferenceExSet(
                                txt, element, 1 + lBraceInd + 1, '.', actionBeanPsiClass, true)
                            .getPsiReferences()
                        //                                        new UrlSetterReferenceExSet(txt,
                        // element, 1, '.', actionBeanPsiClass, true).getPsiReferences()
                        );
                  }

                  // retval.add(new UrlBindingReference(element, new TextRange(1 + lBraceInd + 1, 1
                  // + lBraceInd + 1), actionBeanPsiClass));
                } else if (str.charAt(i) == '=') {
                  eqInd = i;
                }
              }

              return retval.toArray(new PsiReference[retval.size()]);
            }

            return PsiReference.EMPTY_ARRAY;
          }
        });

    registrar.registerReferenceProvider(
        PsiJavaPatterns.literalExpression()
            .methodCallParameter(
                0,
                PsiJavaPatterns.psiMethod()
                    .definedInClass(VALIDATION_ERRORS)
                    .withName(
                        StandardPatterns.string()
                            .oneOf(ADD_METHOD, ADD_ALL_METHOD, PUT_METHOD, PUT_ALL_METHOD))),
        new PsiReferenceProvider() {
          @NotNull
          @Override
          public PsiReference[] getReferencesByElement(
              @NotNull PsiElement element, @NotNull ProcessingContext context) {
            PsiClass cls = PsiTreeUtil.getParentOfType(element, PsiClass.class);
            return null == cls
                ? PsiReference.EMPTY_ARRAY
                : new SetterReferenceExSet(element, 1, '.', cls, true).getPsiReferences();
          }
        });
  }
 @Override
 public void registerReferenceProviders(@NotNull final PsiReferenceRegistrar registrar) {
   registrar.registerReferenceProvider(
       PlatformPatterns.psiElement(YAMLKeyValue.class), new PubspecYamlReferenceProvider());
 }