コード例 #1
0
    public void addCompletions(
        @NotNull CompletionParameters parameters,
        ProcessingContext context,
        @NotNull CompletionResultSet resultSet) {

      PsiElement element = parameters.getPosition().getParent();
      Project project = element.getProject();

      if (!SilexProjectComponent.isEnabled(project)) {
        return;
      }

      if (!(element instanceof StringLiteralExpression)) {
        return;
      }

      Container container =
          Utils.findContainerForFirstParameterOfPimpleMethod((StringLiteralExpression) element);
      if (container == null) {
        return;
      }

      for (Service service : container.getServices().values()) {
        resultSet.addElement(new ServiceLookupElement(service, project));
      }

      for (Parameter parameter : container.getParameters().values()) {
        resultSet.addElement(new ParameterLookupElement(parameter));
      }

      resultSet.stopHere();
    }
コード例 #2
0
    public void addCompletions(
        @NotNull CompletionParameters parameters,
        ProcessingContext context,
        @NotNull CompletionResultSet resultSet) {

      PsiElement stringLiteralExpression = parameters.getPosition().getParent();
      Project project = stringLiteralExpression.getProject();

      if (!SilexProjectComponent.isEnabled(project)) {
        return;
      }

      if (!(stringLiteralExpression instanceof StringLiteralExpression)) {
        return;
      }

      PsiElement arrayKeyElement = stringLiteralExpression.getParent();
      PsiElement element = arrayKeyElement.getParent();

      if (element instanceof ArrayHashElement) {

        if (!arrayKeyElement.isEquivalentTo(element.getFirstChild())) {
          return;
        }

        element = element.getParent();
      }

      if (!(element instanceof ArrayCreationExpression)) {
        return;
      }

      PsiElement parameterList = element.getParent();
      if (!(parameterList instanceof ParameterList)) {
        return;
      }

      PsiElement[] params = ((ParameterList) parameterList).getParameters();
      if (!(params.length > 1 && params[1].isEquivalentTo(element))) {
        return;
      }

      PsiElement methodReference = parameterList.getParent();
      if (!(methodReference instanceof MethodReference)) {
        return;
      }

      String methodReferenceName = ((MethodReference) methodReference).getName();
      if ((methodReferenceName == null) || !(methodReferenceName.equals("register"))) {
        return;
      }

      Container container =
          Utils.findContainerForMethodReference((MethodReference) methodReference);
      if (container == null) {
        return;
      }

      for (Parameter parameter : container.getParameters().values()) {
        resultSet.addElement(new ParameterLookupElement(parameter));
      }

      resultSet.stopHere();
    }