コード例 #1
0
  @Nullable
  public static String getArrayHashValue(
      ArrayCreationExpression arrayCreationExpression, String keyName) {
    ArrayHashElement translationArrayHashElement =
        PsiElementUtils.getChildrenOfType(
            arrayCreationExpression,
            PlatformPatterns.psiElement(ArrayHashElement.class)
                .withFirstChild(
                    PlatformPatterns.psiElement(PhpElementTypes.ARRAY_KEY)
                        .withText(
                            PlatformPatterns.string()
                                .oneOf("'" + keyName + "'", "\"" + keyName + "\""))));

    if (translationArrayHashElement == null) {
      return null;
    }

    if (!(translationArrayHashElement.getValue() instanceof StringLiteralExpression)) {
      return null;
    }

    StringLiteralExpression valueString =
        (StringLiteralExpression) translationArrayHashElement.getValue();
    if (valueString == null) {
      return null;
    }

    return valueString.getContents();
  }
コード例 #2
0
 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());
 }
コード例 #3
0
 /** public function indexAction() */
 public static PsiElementPattern.Capture<PsiElement> getActionMethodPattern() {
   return PlatformPatterns.psiElement(PhpTokenTypes.IDENTIFIER)
       .withText(PlatformPatterns.string().endsWith("Action"))
       .afterLeafSkipping(
           PlatformPatterns.psiElement(PsiWhiteSpace.class),
           PlatformPatterns.psiElement(PhpTokenTypes.kwFUNCTION))
       .inside(Method.class)
       .withLanguage(PhpLanguage.INSTANCE);
 }
コード例 #4
0
 /** matches "@Callback(property="<value>")" */
 public static ElementPattern<PsiElement> getTextIdentifier() {
   return PlatformPatterns.psiElement(PhpDocTokenTypes.DOC_STRING)
       .withParent(
           PlatformPatterns.psiElement(StringLiteralExpression.class)
               .afterLeafSkipping(
                   PlatformPatterns.psiElement(PhpDocTokenTypes.DOC_TEXT)
                       .withText(PlatformPatterns.string().contains("=")),
                   PlatformPatterns.psiElement(PhpDocTokenTypes.DOC_IDENTIFIER))
               .withParent(
                   PlatformPatterns.psiElement(PhpDocElementTypes.phpDocAttributeList)
                       .withParent(PlatformPatterns.psiElement(PhpDocElementTypes.phpDocTag))));
 }
コード例 #5
0
  /**
   * matches "@Callback("<value>", foo...)" TODO: is this also valid "@Callback(key="", "<value>")"?
   */
  public static ElementPattern<PsiElement> getDefaultPropertyValue() {

    return PlatformPatterns.psiElement(PhpDocTokenTypes.DOC_IDENTIFIER)
        .afterLeaf(
            PlatformPatterns.psiElement(PhpDocTokenTypes.DOC_TEXT)
                .withText(PlatformPatterns.string().equalTo("\""))
                .afterLeaf(PlatformPatterns.psiElement(PhpDocTokenTypes.DOC_LPAREN)))
        .withParent(
            PlatformPatterns.psiElement(PhpDocElementTypes.phpDocTagValue)
                .withParent(PlatformPatterns.psiElement(PhpDocElementTypes.phpDocTag)))
        .withLanguage(PhpLanguage.INSTANCE);
  }