Ejemplo n.º 1
0
 public static <T> void assertUnorderedCollection(
     Collection<? extends T> collection, Consumer<T>... checkers) {
   Assert.assertNotNull(collection);
   if (collection.size() != checkers.length) {
     Assert.fail(toString(collection));
   }
   Set<Consumer<T>> checkerSet = new HashSet<Consumer<T>>(Arrays.asList(checkers));
   int i = 0;
   Throwable lastError = null;
   for (final T actual : collection) {
     boolean flag = true;
     for (final Consumer<T> condition : checkerSet) {
       Throwable error = accepts(condition, actual);
       if (error == null) {
         checkerSet.remove(condition);
         flag = false;
         break;
       } else {
         lastError = error;
       }
     }
     if (flag) {
       lastError.printStackTrace();
       Assert.fail("Incorrect element(" + i + "): " + actual);
     }
     i++;
   }
 }
Ejemplo n.º 2
0
 public static <T> void assertOneOf(T value, T... values) {
   boolean found = false;
   for (T v : values) {
     if (value == v || value != null && value.equals(v)) {
       found = true;
     }
   }
   Assert.assertTrue(value + " should be equal to one of " + Arrays.toString(values), found);
 }
Ejemplo n.º 3
0
  private static void removeIdFromParentList(
      final int parentId, final int id, @NotNull VirtualFile parent, VirtualFile file) {
    int[] childList = FSRecords.list(parentId);

    int index = ArrayUtil.indexOf(childList, id);
    if (index == -1) {
      throw new RuntimeException(
          "Cannot find child ("
              + id
              + ")"
              + file
              + "\n\tin ("
              + parentId
              + ")"
              + parent
              + "\n\tactual children:"
              + Arrays.toString(childList));
    }
    childList = ArrayUtil.remove(childList, index);
    FSRecords.updateList(parentId, childList);
  }
  private void analyzeCodeBlock(
      @Nullable final PsiElement scope, ProblemsHolder holder, final boolean onTheFly) {
    if (scope == null) return;

    PsiClass containingClass = PsiTreeUtil.getParentOfType(scope, PsiClass.class);
    if (containingClass != null
        && PsiUtil.isLocalOrAnonymousClass(containingClass)
        && !(containingClass instanceof PsiEnumConstantInitializer)) return;

    final StandardDataFlowRunner dfaRunner =
        new StandardDataFlowRunner(
            TREAT_UNKNOWN_MEMBERS_AS_NULLABLE, !isInsideConstructorOrInitializer(scope)) {
          @Override
          protected boolean shouldCheckTimeLimit() {
            if (!onTheFly) return false;
            return super.shouldCheckTimeLimit();
          }
        };
    analyzeDfaWithNestedClosures(
        scope, holder, dfaRunner, Arrays.asList(dfaRunner.createMemoryState()), onTheFly);
  }
Ejemplo n.º 5
0
 public static <T> T assertOneElement(T[] ts) {
   Assert.assertNotNull(ts);
   Assert.assertEquals(Arrays.asList(ts).toString(), 1, ts.length);
   return ts[0];
 }
Ejemplo n.º 6
0
 public static <T> void assertUnorderedCollection(T[] collection, Consumer<T>... checkers) {
   assertUnorderedCollection(Arrays.asList(collection), checkers);
 }
Ejemplo n.º 7
0
 public <T> void assertDoesntContain(Collection<? extends T> collection, T... notExpected) {
   assertDoesntContain(collection, Arrays.asList(notExpected));
 }
Ejemplo n.º 8
0
 public static String toString(Object[] collection, String separator) {
   return toString(Arrays.asList(collection), separator);
 }
  public static boolean checkConsistency(@NotNull PsiFile psiFile, @NotNull Document document) {
    // todo hack
    if (psiFile.getVirtualFile() == null) return true;

    CharSequence editorText = document.getCharsSequence();
    int documentLength = document.getTextLength();
    if (psiFile.textMatches(editorText)) {
      LOG.assertTrue(psiFile.getTextLength() == documentLength);
      return true;
    }

    char[] fileText = psiFile.textToCharArray();
    @SuppressWarnings("NonConstantStringShouldBeStringBuffer")
    @NonNls
    String error =
        "File '"
            + psiFile.getName()
            + "' text mismatch after reparse. "
            + "File length="
            + fileText.length
            + "; Doc length="
            + documentLength
            + "\n";
    int i = 0;
    for (; i < documentLength; i++) {
      if (i >= fileText.length) {
        error += "editorText.length > psiText.length i=" + i + "\n";
        break;
      }
      if (i >= editorText.length()) {
        error += "editorText.length > psiText.length i=" + i + "\n";
        break;
      }
      if (editorText.charAt(i) != fileText[i]) {
        error += "first unequal char i=" + i + "\n";
        break;
      }
    }
    // error += "*********************************************" + "\n";
    // if (i <= 500){
    //  error += "Equal part:" + editorText.subSequence(0, i) + "\n";
    // }
    // else{
    //  error += "Equal part start:\n" + editorText.subSequence(0, 200) + "\n";
    //  error += "................................................" + "\n";
    //  error += "................................................" + "\n";
    //  error += "................................................" + "\n";
    //  error += "Equal part end:\n" + editorText.subSequence(i - 200, i) + "\n";
    // }
    error += "*********************************************" + "\n";
    error +=
        "Editor Text tail:("
            + (documentLength - i)
            + ")\n"; // + editorText.subSequence(i, Math.min(i + 300, documentLength)) + "\n";
    error += "*********************************************" + "\n";
    error += "Psi Text tail:(" + (fileText.length - i) + ")\n";
    error += "*********************************************" + "\n";

    if (document instanceof DocumentWindow) {
      error += "doc: '" + document.getText() + "'\n";
      error += "psi: '" + psiFile.getText() + "'\n";
      error += "ast: '" + psiFile.getNode().getText() + "'\n";
      error += psiFile.getLanguage() + "\n";
      PsiElement context =
          InjectedLanguageManager.getInstance(psiFile.getProject()).getInjectionHost(psiFile);
      if (context != null) {
        error += "context: " + context + "; text: '" + context.getText() + "'\n";
        error += "context file: " + context.getContainingFile() + "\n";
      }
      error +=
          "document window ranges: "
              + Arrays.asList(((DocumentWindow) document).getHostRanges())
              + "\n";
    }
    LOG.error(error);
    // document.replaceString(0, documentLength, psiFile.getText());
    return false;
  }
  @Override
  @NotNull
  public synchronized VirtualFile[] getChildren() {
    VirtualFileSystemEntry[] children = myChildren;
    NewVirtualFileSystem delegate = getFileSystem();
    final boolean ignoreCase = !delegate.isCaseSensitive();
    if (allChildrenLoaded()) {
      assertConsistency(children, ignoreCase);
      return children;
    }

    final FSRecords.NameId[] childrenIds = ourPersistence.listAll(this);
    VirtualFileSystemEntry[] result;
    if (childrenIds.length == 0) {
      result = EMPTY_ARRAY;
    } else {
      Arrays.sort(
          childrenIds,
          new java.util.Comparator<FSRecords.NameId>() {
            @Override
            public int compare(FSRecords.NameId o1, FSRecords.NameId o2) {
              String name1 = o1.name;
              String name2 = o2.name;
              int cmp = compareNames(name1, name2, ignoreCase);
              if (cmp == 0 && name1 != name2) {
                LOG.error(
                    ourPersistence
                        + " returned duplicate file names("
                        + name1
                        + ","
                        + name2
                        + ")"
                        + " ignoreCase: "
                        + ignoreCase
                        + " SystemInfo.isFileSystemCaseSensitive: "
                        + SystemInfo.isFileSystemCaseSensitive
                        + " SystemInfo.OS: "
                        + SystemInfo.OS_NAME
                        + " "
                        + SystemInfo.OS_VERSION
                        + " in the dir: "
                        + VirtualDirectoryImpl.this
                        + ";"
                        + " children: "
                        + Arrays.toString(childrenIds));
              }
              return cmp;
            }
          });
      result = new VirtualFileSystemEntry[childrenIds.length];
      int delegateI = 0;
      int i = 0;

      int cachedEnd = getAdoptedChildrenStart();
      // merge (sorted) children[0..cachedEnd) and childrenIds into the result array.
      // file that is already in children array must be copied into the result as is
      // for the file name that is new in childrenIds the file must be created and copied into
      // result
      while (delegateI < childrenIds.length) {
        FSRecords.NameId nameId = childrenIds[delegateI];
        while (i < cachedEnd && children[i].compareNameTo(nameId.name, ignoreCase) < 0)
          i++; // skip files that are not in childrenIds

        VirtualFileSystemEntry resultFile;
        if (i < cachedEnd && children[i].compareNameTo(nameId.name, ignoreCase) == 0) {
          resultFile = children[i++];
        } else {
          resultFile = createChild(nameId.name, nameId.id, delegate);
        }
        result[delegateI++] = resultFile;
      }

      assertConsistency(result, ignoreCase, children, cachedEnd, childrenIds);
    }

    if (getId() > 0) {
      myChildren = result;
      setChildrenLoaded();
    }

    return result;
  }
Ejemplo n.º 11
0
 public static <T> void assertSameElements(T[] collection, T... expected) {
   assertSameElements(Arrays.asList(collection), expected);
 }
Ejemplo n.º 12
0
 public static <T> void assertOrderedCollection(T[] collection, @NotNull Consumer<T>... checkers) {
   Assert.assertNotNull(collection);
   assertOrderedCollection(Arrays.asList(collection), checkers);
 }
Ejemplo n.º 13
0
 public static <T> void assertOrderedEquals(
     final String errorMsg, @NotNull Iterable<T> actual, @NotNull T... expected) {
   Assert.assertNotNull(actual);
   Assert.assertNotNull(expected);
   assertOrderedEquals(errorMsg, actual, Arrays.asList(expected));
 }
Ejemplo n.º 14
0
 public static <T> void assertOrderedEquals(T[] actual, T... expected) {
   assertOrderedEquals(Arrays.asList(actual), expected);
 }
 @Override
 public boolean equals(final BaseInjection o1, final BaseInjection o2) {
   return o1.sameLanguageParameters(o2)
       && Arrays.equals(o1.getInjectionPlaces(), o2.getInjectionPlaces());
 }
Ejemplo n.º 16
0
 public static void assertSize(int expectedSize, final Object[] array) {
   assertEquals(toString(Arrays.asList(array)), expectedSize, array.length);
 }
Ejemplo n.º 17
0
 public static <T> void assertSameElements(Collection<? extends T> collection, T... expected) {
   assertSameElements(collection, Arrays.asList(expected));
 }
  private void assertConsistency(
      @NotNull VirtualFileSystemEntry[] array, boolean ignoreCase, @NotNull Object... details) {
    if (!CHECK) return;
    boolean allChildrenLoaded = allChildrenLoaded();
    for (int i = 0; i < array.length; i++) {
      VirtualFileSystemEntry file = array[i];
      boolean isAdopted = isAdoptedChild(file);
      assert !isAdopted || !allChildrenLoaded;
      if (isAdopted && i != array.length - 1) {
        assert isAdoptedChild(array[i + 1]);
      }
      if (i != 0) {
        VirtualFileSystemEntry prev = array[i - 1];
        String prevName = prev.getName();
        int cmp = file.compareNameTo(prevName, ignoreCase);
        if (cmp == 0) {
          Function<VirtualFileSystemEntry, String> verboseToString =
              new Function<VirtualFileSystemEntry, String>() {
                @Override
                public String fun(VirtualFileSystemEntry entry) {
                  return entry
                      + " (name: '"
                      + entry.getName()
                      + "', "
                      + entry.getClass()
                      + ", parent:"
                      + entry.getParent()
                      + "; id:"
                      + entry.getId()
                      + "; FS:"
                      + entry.getFileSystem()
                      + "; delegate.attrs:"
                      + entry.getFileSystem().getAttributes(entry)
                      + "; caseSensitive:"
                      + entry.getFileSystem().isCaseSensitive()
                      + "; canonical:"
                      + entry.getFileSystem().getCanonicallyCasedName(entry)
                      + ") ";
                }
              };
          String children = StringUtil.join(array, verboseToString, ",");
          throw new AssertionError(
              verboseToString.fun(prev)
                  + " equals to "
                  + verboseToString.fun(file)
                  + "; children: "
                  + children
                  + "\nDetails: "
                  + ContainerUtil.map(
                      details,
                      new Function<Object, Object>() {
                        @Override
                        public Object fun(Object o) {
                          return o instanceof Object[] ? Arrays.toString((Object[]) o) : o;
                        }
                      }));
        }

        if (isAdopted == isAdoptedChild(prev)) {
          assert cmp > 0 : "Not sorted. " + Arrays.toString(details);
        }
      }
    }
  }
Ejemplo n.º 19
0
 public <T> void assertContainsElements(Collection<? extends T> collection, T... expected) {
   assertContainsElements(collection, Arrays.asList(expected));
 }