Пример #1
0
 public void checkConstraints(Collection<ConstraintViolation> violations) {
   super.checkConstraints(violations);
   if (!this.linkOperationExpressionIsCreationDerivation()) {
     violations.add(new ConstraintViolation("linkOperationExpressionIsCreationDerivation", this));
   }
   if (!this.linkOperationExpressionIsClearDerivation()) {
     violations.add(new ConstraintViolation("linkOperationExpressionIsClearDerivation", this));
   }
   if (!this.linkOperationExpressionReferentDerivation()) {
     violations.add(new ConstraintViolation("linkOperationExpressionReferentDerivation", this));
   }
   if (!this.linkOperationExpressionFeatureDerivation()) {
     violations.add(new ConstraintViolation("linkOperationExpressionFeatureDerivation", this));
   }
   if (!this.linkOperationExpressionAssociationReference()) {
     violations.add(new ConstraintViolation("linkOperationExpressionAssociationReference", this));
   }
   if (!this.linkOperationExpressionArgumentCompatibility()) {
     violations.add(new ConstraintViolation("linkOperationExpressionArgumentCompatibility", this));
   }
   QualifiedName associationName = this.getAssociationName();
   if (associationName != null) {
     associationName.checkConstraints(violations);
   }
 }
Пример #2
0
 public void print(String prefix, boolean includeDerived) {
   super.print(prefix, includeDerived);
   QualifiedName associationName = this.getAssociationName();
   if (associationName != null) {
     System.out.println(prefix + " associationName:");
     associationName.print(prefix + "  ", includeDerived);
   }
 }
Пример #3
0
 public List replaceVBLiteralArrayParamaters(InvocationExpression ie) {
   List newParameters = new ArrayList();
   List arrayCreationDeclarations =
       createVBArrayCreationDeclatationsAndSubstituteParams(
           this.getParameters(), newParameters, ie.getContext());
   this.parameters = newParameters;
   return arrayCreationDeclarations;
 }
Пример #4
0
 public void _deriveAll() {
   this.getIsCreation();
   this.getIsClear();
   super._deriveAll();
   QualifiedName associationName = this.getAssociationName();
   if (associationName != null) {
     associationName.deriveAll();
   }
 }
Пример #5
0
  @Override
  public Function<Object[], ?> visit(InvocationExpression e) {

    final Function<Object[], ?> m = e.getTarget().accept(this);

    int size = e.getArguments().size();
    List<Function<Object[], ?>> ppe = new ArrayList<>(size);
    for (Expression p : e.getArguments()) ppe.add(p.accept(this));

    Function<Object[], Object[]> params =
        pp -> {
          Object[] r = new Object[ppe.size()];
          int index = 0;
          for (Function<Object[], ?> pe : ppe) {
            r[index++] = pe.apply(pp);
          }

          return r;
        };

    return m.compose(params);
  }
Пример #6
0
  @Override
  public Void visitInvocationExpression(final InvocationExpression node, final Void data) {
    super.visitInvocationExpression(node, data);

    final AstNodeCollection<Expression> arguments = node.getArguments();
    final Expression lastArgument = arguments.lastOrNullObject();

    Expression arrayArg = lastArgument;

    if (arrayArg instanceof CastExpression) arrayArg = ((CastExpression) arrayArg).getExpression();

    if (arrayArg == null
        || arrayArg.isNull()
        || !(arrayArg instanceof ArrayCreationExpression
            && node.getTarget() instanceof MemberReferenceExpression)) {

      return null;
    }

    final ArrayCreationExpression newArray = (ArrayCreationExpression) arrayArg;
    final MemberReferenceExpression target = (MemberReferenceExpression) node.getTarget();

    if (!newArray.getAdditionalArraySpecifiers().hasSingleElement()) {
      return null;
    }

    final MethodReference method = (MethodReference) node.getUserData(Keys.MEMBER_REFERENCE);

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

    final MethodDefinition resolved = method.resolve();

    if (resolved == null || !resolved.isVarArgs()) {
      return null;
    }

    final List<MethodReference> candidates;
    final Expression invocationTarget = target.getTarget();

    if (invocationTarget == null || invocationTarget.isNull()) {
      candidates =
          MetadataHelper.findMethods(
              context.getCurrentType(), MetadataFilters.matchName(resolved.getName()));
    } else {
      final ResolveResult targetResult = _resolver.apply(invocationTarget);

      if (targetResult == null || targetResult.getType() == null) {
        return null;
      }

      candidates =
          MetadataHelper.findMethods(
              targetResult.getType(), MetadataFilters.matchName(resolved.getName()));
    }

    final List<TypeReference> argTypes = new ArrayList<>();

    for (final Expression argument : arguments) {
      final ResolveResult argResult = _resolver.apply(argument);

      if (argResult == null || argResult.getType() == null) {
        return null;
      }

      argTypes.add(argResult.getType());
    }

    final MethodBinder.BindResult c1 = MethodBinder.selectMethod(candidates, argTypes);

    if (c1.isFailure() || c1.isAmbiguous()) {
      return null;
    }

    argTypes.remove(argTypes.size() - 1);

    final ArrayInitializerExpression initializer = newArray.getInitializer();
    final boolean hasElements = !initializer.isNull() && !initializer.getElements().isEmpty();

    if (hasElements) {
      for (final Expression argument : initializer.getElements()) {
        final ResolveResult argResult = _resolver.apply(argument);

        if (argResult == null || argResult.getType() == null) {
          return null;
        }

        argTypes.add(argResult.getType());
      }
    }

    final MethodBinder.BindResult c2 = MethodBinder.selectMethod(candidates, argTypes);

    if (c2.isFailure()
        || c2.isAmbiguous()
        || !StringUtilities.equals(
            c2.getMethod().getErasedSignature(), c1.getMethod().getErasedSignature())) {

      return null;
    }

    lastArgument.remove();

    if (!hasElements) {
      return null;
    }

    for (final Expression newArg : initializer.getElements()) {
      newArg.remove();
      arguments.add(newArg);
    }

    return null;
  }