コード例 #1
0
  @Nullable
  @Override
  public List<? extends PsiElement> resolve(
      @NotNull DartReference reference, boolean incompleteCode) {
    if (reference instanceof DartThisExpression) {
      return toResult(PsiTreeUtil.getParentOfType(reference, DartClass.class));
    }
    if (reference instanceof DartParameterNameReferenceExpression) {
      final DartCallExpression callExpression =
          PsiTreeUtil.getParentOfType(reference, DartCallExpression.class);
      final DartExpression expression =
          callExpression != null ? callExpression.getExpression() : null;
      final PsiElement target =
          expression instanceof DartReference ? ((DartReference) expression).resolve() : null;
      final DartFormalParameterList parameters =
          PsiTreeUtil.getChildOfType(
              target != null ? target.getParent() : null, DartFormalParameterList.class);
      return toResult(DartResolveUtil.findParameterByName(parameters, reference.getText()));
    }
    if (DartResolveUtil.aloneOrFirstInChain(reference)) {
      return resolveSimpleReference(reference);
    }
    final DartReference leftReference = DartResolveUtil.getLeftReference(reference);
    // reference [node, node]
    final DartReference[] references =
        PsiTreeUtil.getChildrenOfType(reference, DartReference.class);
    if (references != null && references.length == 2) {
      // prefix
      final List<DartComponentName> names =
          DartResolveUtil.findComponentsInLibraryByPrefix(
              reference, references[0].getCanonicalText(), references[1].getCanonicalText());
      if (!names.isEmpty()) {
        return toResult(names);
      }
      return toResult(references[1].resolve());
    } else if (leftReference != null) {
      final DartClassResolveResult classResolveResult = leftReference.resolveDartClass();
      final DartClass dartClass = classResolveResult.getDartClass();
      if (dartClass != null) {
        final String name = reference.getCanonicalText();
        final DartComponent subComponent =
            leftReference instanceof DartType
                ? dartClass.findNamedConstructor(name)
                : filterAccess(reference, dartClass.findMembersByName(name));
        return toResult(subComponent == null ? null : subComponent.getComponentName());
      }
      // prefix
      final List<DartComponentName> names =
          DartResolveUtil.findComponentsInLibraryByPrefix(
              reference, leftReference.getCanonicalText(), reference.getCanonicalText());
      if (!names.isEmpty()) {
        return toResult(names);
      }
    }

    return null;
  }
コード例 #2
0
 @Nullable
 public static String getTestLabel(@NotNull final DartCallExpression testCallExpression) {
   final DartArguments arguments = testCallExpression.getArguments();
   final DartArgumentList argumentList = arguments == null ? null : arguments.getArgumentList();
   final List<DartExpression> argExpressions =
       argumentList == null ? null : argumentList.getExpressionList();
   return argExpressions != null
           && !argExpressions.isEmpty()
           && argExpressions.get(0) instanceof DartStringLiteralExpression
       ? StringUtil.unquoteString(argExpressions.get(0).getText())
       : null;
 }