Exemple #1
0
  private Type typecheckCases(Environment env, Optional<Type> expected) {
    Type commonType = null;
    // do actual type-checking on cases
    for (Case c : cases) {
      Type rt = c.getAST().typecheck(env, expected);
      // System.out.println("rt = " + rt);
      if (commonType == null) commonType = rt;
      if (!rt.equals(commonType)) {
        // System.out.println("WARNING: rt = " + rt + " and commonType = " + commonType);
        ToolError.reportError(ErrorMessage.MATCH_NO_COMMON_RETURN, this);
        return null;
      }
    }

    if (expected.equals(Optional.empty())) {
      return commonType;
    } else {
      // System.out.println("expected = " + expected);
      // System.out.println("commonType = " + commonType);
      if (commonType == null
          || /*expected.equals(commonType) ||*/ expected.get().equals(commonType)) {
        return commonType;
      } else {
        ToolError.reportError(ErrorMessage.MATCH_NO_COMMON_RETURN, this);
        return null;
      }
    }
  }
Exemple #2
0
  @Override
  public void validateIfLocked(final ILockKey context, Optional<ILock> heldLock)
      throws LockException {

    Optional<ILock> stored =
        storage.read(storeProvider -> storeProvider.getLockStore().fetchLock(context));

    // The implementation below assumes the following use cases:
    // +-----------+-----------------+----------+
    // |   eq      |     held        | not held |
    // +-----------+-----------------+----------+
    // |stored     |(stored == held)?| invalid  |
    // +-----------+-----------------+----------+
    // |not stored |    invalid      |  valid   |
    // +-----------+-----------------+----------+
    if (!stored.equals(heldLock)) {
      if (stored.isPresent()) {
        throw new LockException(
            String.format(
                "Unable to perform operation for: %s. Use override/cancel option.",
                formatLockKey(context)));
      } else if (heldLock.isPresent()) {
        throw new LockException(
            String.format("Invalid operation context: %s", formatLockKey(context)));
      }
    }
  }
    @Override
    public boolean equals(Object o) {
      if (this == o) return true;
      if (o == null || getClass() != o.getClass()) return false;

      TestEvent<?> testEvent = (TestEvent<?>) o;

      if (type != testEvent.type) return false;
      if (!prev.equals(testEvent.prev)) return false;
      return !(value != null ? !value.equals(testEvent.value) : testEvent.value != null);
    }
 public static <T> T showChoicePopup(
     String title, String header, String content, List<T> choiceList) {
   T retVal = null;
   ChoiceDialog<T> dialog = new ChoiceDialog<>(choiceList.get(0), choiceList);
   dialog.setTitle(title);
   dialog.setHeaderText(header);
   dialog.setContentText(content);
   Optional<T> result = dialog.showAndWait();
   if (!result.equals(Optional.<T>empty())) {
     retVal = result.get();
   }
   return retVal;
 }
Exemple #5
0
 /** Metadata is not considered for equality. In general only serialised fields are. */
 @Override
 public boolean equals(Object o) {
   if (this == o) return true;
   if (o == null || getClass() != o.getClass()) return false;
   TurboIssue issue = (TurboIssue) o;
   return commentCount == issue.commentCount
       && id == issue.id
       && isOpen == issue.isOpen
       && isPullRequest == issue.isPullRequest
       && !(assignee != null ? !assignee.equals(issue.assignee) : issue.assignee != null)
       && !(createdAt != null ? !createdAt.equals(issue.createdAt) : issue.createdAt != null)
       && !(creator != null ? !creator.equals(issue.creator) : issue.creator != null)
       && !(description != null
           ? !description.equals(issue.description)
           : issue.description != null)
       && !(labels != null ? !labels.equals(issue.labels) : issue.labels != null)
       && !(milestone != null ? !milestone.equals(issue.milestone) : issue.milestone != null)
       && !(title != null ? !title.equals(issue.title) : issue.title != null)
       && !(updatedAt != null ? !updatedAt.equals(issue.updatedAt) : issue.updatedAt != null)
       && !(markedReadAt != null
           ? !markedReadAt.equals(issue.markedReadAt)
           : issue.markedReadAt != null);
 }
Exemple #6
0
  @Override
  protected Type doTypecheck(Environment env, Optional<Type> expected) {
    this.resolve(env);

    Type matchOverType = matchingOver.typecheck(env, expected);
    // System.out.println("env = " + env);
    // System.out.println("matchingOver = " + matchingOver);
    // System.out.println("matchOverType = " + matchOverType);

    if (!(matchingOver instanceof Variable)) {
      throw new RuntimeException("Can only match over variable");
    }

    // Variable v = (Variable) matchingOver;
    // System.out.println("v = " + v);
    // System.out.println("v.getType()=" + v.getType());

    StaticTypeBinding staticBinding = getStaticTypeBinding(matchingOver, env);

    // System.out.println(staticBinding);

    /*
    if (staticBinding == null) {
    	throw new RuntimeException("variable matching over must be statically tagged");
    }
    */

    // Variable we're matching must exist and be a tagged type
    // String typeName = getTypeName(matchOverType);

    TaggedInfo matchTaggedInfo = TaggedInfo.lookupTagByType(matchOverType); // FIXME:

    // System.out.println(matchOverType);

    if (matchTaggedInfo == null) {
      ToolError.reportError(ErrorMessage.TYPE_NOT_TAGGED, matchingOver, matchOverType.toString());
    }

    // System.out.println(matchTaggedInfo);
    matchTaggedInfo.resolve(env, this);
    // System.out.println(matchTaggedInfo);

    checkNotMultipleDefaults();

    checkDefaultLast();

    Type returnType = typecheckCases(env, expected);

    checkAllCasesAreTagged(env);

    checkAllCasesAreUnique();

    checkSubtagsPreceedSupertags();

    // ONLY FOR STATICS FIXME:
    // System.out.println(env);
    if (staticBinding != null) {
      NameBinding nb = env.lookup(staticBinding.getTypeName());
      if (nb != null) {
        checkStaticSubtags(TaggedInfo.lookupTagByType(nb.getType())); // matchTaggedInfo
        checkBoundedAndUnbounded(TaggedInfo.lookupTagByType(nb.getType())); // matchTaggedInfo
      }
    }

    // If we've omitted default, we must included all possible sub-tags
    if (defaultCase == null) {
      // first, the variables tag must use comprised-of!

      // next, the match cases must include all those in the comprises-of list
      if (true) {}
    }

    // If we've included default, we can't have included all subtags for a tag using comprised-of
    if (defaultCase != null) {
      // We only care if tag specifies comprises-of
      if (matchTaggedInfo.hasComprises()) {
        // all subtags were specified, error
        if (comprisesSatisfied(matchTaggedInfo)) {
          // ToolError.reportError(ErrorMessage.DEFAULT_PRESENT, matchingOver);
        }
      }
    }

    // System.out.println(expected);

    if (returnType == null) {
      if (defaultCase != null) {
        if (!expected.equals(Optional.empty())) {
          // System.out.println(defaultCase.getAST().getType());
          // System.out.println(expected.get());
          if (!expected.get().equals(defaultCase.getAST().getType())) {
            ToolError.reportError(ErrorMessage.MATCH_NO_COMMON_RETURN, this);
            return null;
          }
        }
      }
    }

    return returnType;
  }
 private boolean clientCorrelationIdIsSetAndDoesNotMatchWith(final Metadata metadata) {
   return clientCorrelationId.isPresent()
       && !clientCorrelationId.equals(metadata.clientCorrelationId());
 }
 private boolean versionIsSetAndDoesNotMatchWith(final Metadata metadata) {
   return version.isPresent() && !version.equals(metadata.version());
 }
 private boolean streamIdIsSetAndDoesNotMatchWith(final Metadata metadata) {
   return streamId.isPresent() && !streamId.equals(metadata.streamId());
 }
 private boolean userIdIsSetAndDoesNotMatchWith(final Metadata metadata) {
   return userId.isPresent() && !userId.equals(metadata.userId());
 }
 static void checkPattern(Tree target, Tree pattern, Optional<Tree> expected) {
   Optional<Tree> result = find(target, pattern);
   String mark = result.equals(expected) ? "[✓]" : "[ ]";
   System.out.println(mark + " " + pattern.toString());
   assert result.equals(expected) : "Expected" + expected + ", but got " + result;
 }