public boolean equals(Object o) {
   if (o instanceof StructureViewTreeElementWrapper) {
     return Comparing.equal(
         unwrapValue(getValue()), unwrapValue(((StructureViewTreeElementWrapper) o).getValue()));
   } else if (o instanceof StructureViewTreeElement) {
     return Comparing.equal(unwrapValue(getValue()), ((StructureViewTreeElement) o).getValue());
   }
   return false;
 }
Exemplo n.º 2
0
  public boolean equalsByActualOffset(@NotNull HighlightInfo info) {
    if (info == this) return true;

    return info.getSeverity() == getSeverity()
        && info.getActualStartOffset() == getActualStartOffset()
        && info.getActualEndOffset() == getActualEndOffset()
        && Comparing.equal(info.type, type)
        && Comparing.equal(info.gutterIconRenderer, gutterIconRenderer)
        && Comparing.equal(info.forcedTextAttributes, forcedTextAttributes)
        && Comparing.equal(info.forcedTextAttributesKey, forcedTextAttributesKey)
        && Comparing.strEqual(info.getDescription(), getDescription());
  }
Exemplo n.º 3
0
  @Override
  public boolean equals(Object obj) {
    if (obj == this) return true;
    if (!(obj instanceof HighlightInfo)) return false;
    HighlightInfo info = (HighlightInfo) obj;

    return info.getSeverity() == getSeverity()
        && info.startOffset == startOffset
        && info.endOffset == endOffset
        && Comparing.equal(info.type, type)
        && Comparing.equal(info.gutterIconRenderer, gutterIconRenderer)
        && Comparing.equal(info.forcedTextAttributes, forcedTextAttributes)
        && Comparing.equal(info.forcedTextAttributesKey, forcedTextAttributesKey)
        && Comparing.strEqual(info.getDescription(), getDescription());
  }
 private static boolean infoEquals(HighlightInfo expectedInfo, HighlightInfo info) {
   if (expectedInfo == info) return true;
   return info.getSeverity() == expectedInfo.getSeverity()
       && info.startOffset == expectedInfo.startOffset
       && info.endOffset == expectedInfo.endOffset
       && info.isAfterEndOfLine() == expectedInfo.isAfterEndOfLine()
       && (expectedInfo.type == WHATEVER || expectedInfo.type.equals(info.type))
       && (Comparing.strEqual(ANY_TEXT, expectedInfo.getDescription())
           || Comparing.strEqual(info.getDescription(), expectedInfo.getDescription()))
       && (expectedInfo.forcedTextAttributes == null
           || Comparing.equal(
               expectedInfo.getTextAttributes(null, null), info.getTextAttributes(null, null)))
       && (expectedInfo.forcedTextAttributesKey == null
           || expectedInfo.forcedTextAttributesKey.equals(info.forcedTextAttributesKey));
 }
  private void recycleChangeList(
      final ShelvedChangeList listCopy, final ShelvedChangeList newList) {
    if (newList != null) {
      for (Iterator<ShelvedBinaryFile> shelvedChangeListIterator =
              listCopy.getBinaryFiles().iterator();
          shelvedChangeListIterator.hasNext(); ) {
        final ShelvedBinaryFile binaryFile = shelvedChangeListIterator.next();
        for (ShelvedBinaryFile newBinary : newList.getBinaryFiles()) {
          if (Comparing.equal(newBinary.BEFORE_PATH, binaryFile.BEFORE_PATH)
              && Comparing.equal(newBinary.AFTER_PATH, binaryFile.AFTER_PATH)) {
            shelvedChangeListIterator.remove();
          }
        }
      }
      for (Iterator<ShelvedChange> iterator = listCopy.getChanges(myProject).iterator();
          iterator.hasNext(); ) {
        final ShelvedChange change = iterator.next();
        for (ShelvedChange newChange : newList.getChanges(myProject)) {
          if (Comparing.equal(change.getBeforePath(), newChange.getBeforePath())
              && Comparing.equal(change.getAfterPath(), newChange.getAfterPath())) {
            iterator.remove();
          }
        }
      }

      // needed only if partial unshelve
      try {
        final CommitContext commitContext = new CommitContext();
        final List<FilePatch> patches = new ArrayList<FilePatch>();
        for (ShelvedChange change : listCopy.getChanges(myProject)) {
          patches.add(change.loadFilePatch(myProject, commitContext));
        }
        writePatchesToFile(myProject, listCopy.PATH, patches, commitContext);
      } catch (IOException e) {
        LOG.info(e);
        // left file as is
      } catch (PatchSyntaxException e) {
        LOG.info(e);
        // left file as is
      }
    }

    if ((!listCopy.getBinaryFiles().isEmpty()) || (!listCopy.getChanges(myProject).isEmpty())) {
      listCopy.setRecycled(true);
      myRecycledShelvedChangeLists.add(listCopy);
      notifyStateChanged();
    }
  }
  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }

    DocumentFoldingInfo info = (DocumentFoldingInfo) o;

    if (myFile != null ? !myFile.equals(info.myFile) : info.myFile != null) {
      return false;
    }
    if (!myProject.equals(info.myProject)
        || !myPsiElements.equals(info.myPsiElements)
        || !mySerializedElements.equals(info.mySerializedElements)) {
      return false;
    }

    if (myRangeMarkers.size() != info.myRangeMarkers.size()) return false;
    for (int i = 0; i < myRangeMarkers.size(); i++) {
      RangeMarker marker = myRangeMarkers.get(i);
      RangeMarker other = info.myRangeMarkers.get(i);
      if (marker == other || !marker.isValid() || !other.isValid()) {
        continue;
      }
      if (!TextRange.areSegmentsEqual(marker, other)) return false;

      FoldingInfo fi = marker.getUserData(FOLDING_INFO_KEY);
      FoldingInfo ofi = other.getUserData(FOLDING_INFO_KEY);
      if (!Comparing.equal(fi, ofi)) return false;
    }
    return true;
  }
 private void validateEncoding(ModuleChunk chunk, String chunkPresentableName) {
   final CompilerEncodingService es = CompilerEncodingService.getInstance(myProject);
   Charset charset = null;
   for (Module module : chunk.getModules()) {
     final Charset moduleCharset = es.getPreferredModuleEncoding(module);
     if (charset == null) {
       charset = moduleCharset;
     } else {
       if (!Comparing.equal(charset, moduleCharset)) {
         // warn user
         final Charset chunkEncoding = CompilerEncodingService.getPreferredModuleEncoding(chunk);
         final StringBuilder message = new StringBuilder();
         message.append("Modules in chunk [");
         message.append(chunkPresentableName);
         message.append("] configured to use different encodings.\n");
         if (chunkEncoding != null) {
           message
               .append("\"")
               .append(chunkEncoding.name())
               .append("\" encoding will be used to compile the chunk");
         } else {
           message.append("Default compiler encoding will be used to compile the chunk");
         }
         myCompileContext.addMessage(
             CompilerMessageCategory.INFORMATION, message.toString(), null, -1, -1);
         break;
       }
     }
   }
 }
  private static boolean addToPath(
      AbstractTreeNode<?> rootElement,
      Object element,
      ArrayList<AbstractTreeNode> result,
      Collection<Object> processedElements) {
    Object value = rootElement.getValue();
    if (value instanceof StructureViewTreeElement) {
      value = ((StructureViewTreeElement) value).getValue();
    }
    if (!processedElements.add(value)) {
      return false;
    }

    if (Comparing.equal(value, element)) {
      result.add(0, rootElement);
      return true;
    }

    Collection<? extends AbstractTreeNode> children = rootElement.getChildren();
    for (AbstractTreeNode child : children) {
      if (addToPath(child, element, result, processedElements)) {
        result.add(0, rootElement);
        return true;
      }
    }

    return false;
  }
Exemplo n.º 9
0
 public XmlAttribute setAttribute(String name, String namespace, String value)
     throws IncorrectOperationException {
   if (!Comparing.equal(namespace, "")) {
     final String prefix = getPrefixByNamespace(namespace);
     if (prefix != null && prefix.length() > 0) name = prefix + ":" + name;
   }
   return setAttribute(name, value);
 }
 private static boolean needUnshelve(final FilePatch patch, final List<ShelvedChange> changes) {
   for (ShelvedChange change : changes) {
     if (Comparing.equal(patch.getBeforeName(), change.getBeforePath())) {
       return true;
     }
   }
   return false;
 }
Exemplo n.º 11
0
  @Nullable
  public XmlAttribute getAttribute(String qname) {
    if (qname == null) return null;
    final XmlAttribute[] attributes = getAttributes();

    final boolean caseSensitive = isCaseSensitive();

    for (final XmlAttribute attribute : attributes) {
      final LeafElement attrNameElement =
          (LeafElement) XmlChildRole.ATTRIBUTE_NAME_FINDER.findChild(attribute.getNode());
      if (attrNameElement != null
          && (caseSensitive && Comparing.equal(attrNameElement.getChars(), qname)
              || !caseSensitive && Comparing.equal(attrNameElement.getChars(), qname, false))) {
        return attribute;
      }
    }
    return null;
  }
Exemplo n.º 12
0
  private static boolean attributeListsEqual(List<Attribute> l1, List<Attribute> l2) {
    if (l1 == null) return l2 == null;
    if (l2 == null) return false;

    if (l1.size() != l2.size()) return false;

    Iterator<Attribute> i1 = l1.iterator();

    for (Attribute aL2 : l2) {
      Attribute attr1 = i1.next();

      if (!Comparing.equal(attr1.getName(), aL2.getName())
          || !Comparing.equal(attr1.getValue(), aL2.getValue())) {
        return false;
      }
    }
    return true;
  }
 public static Element getOption(@NotNull Element parent, @NotNull @NonNls String fieldName) {
   for (Element element : parent.getChildren("option")) {
     String childName = element.getAttributeValue("name");
     if (Comparing.strEqual(childName, fieldName)) {
       return element;
     }
   }
   return null;
 }
  public static void convert(
      Element element, final Map<String, SmartRefElementPointer> persistentEntryPoints) {
    List content = element.getChildren();
    for (final Object aContent : content) {
      Element entryElement = (Element) aContent;
      if (ENTRY_POINT_ATTR.equals(entryElement.getName())) {
        String fqName = entryElement.getAttributeValue(SmartRefElementPointerImpl.FQNAME_ATTR);
        final String type = entryElement.getAttributeValue(SmartRefElementPointerImpl.TYPE_ATTR);
        if (Comparing.strEqual(type, RefJavaManager.METHOD)) {

          int spaceIdx = fqName.indexOf(' ');
          int lastDotIdx = fqName.lastIndexOf('.');

          int parenIndex = fqName.indexOf('(');

          while (lastDotIdx > parenIndex) lastDotIdx = fqName.lastIndexOf('.', lastDotIdx - 1);

          boolean notype = false;
          if (spaceIdx < 0 || spaceIdx + 1 > lastDotIdx || spaceIdx > parenIndex) {
            notype = true;
          }

          final String className = fqName.substring(notype ? 0 : spaceIdx + 1, lastDotIdx);
          final String methodSignature =
              notype
                  ? fqName.substring(lastDotIdx + 1)
                  : fqName.substring(0, spaceIdx) + ' ' + fqName.substring(lastDotIdx + 1);

          fqName = className + " " + methodSignature;
        } else if (Comparing.strEqual(type, RefJavaManager.FIELD)) {
          final int lastDotIdx = fqName.lastIndexOf('.');
          if (lastDotIdx > 0 && lastDotIdx < fqName.length() - 2) {
            String className = fqName.substring(0, lastDotIdx);
            String fieldName = fqName.substring(lastDotIdx + 1);
            fqName = className + " " + fieldName;
          } else {
            continue;
          }
        }
        SmartRefElementPointerImpl entryPoint = new SmartRefElementPointerImpl(type, fqName);
        persistentEntryPoints.put(entryPoint.getFQName(), entryPoint);
      }
    }
  }
 public void refreshPresentation() {
   // 1. vertical 2. number of lines 3. soft wraps (4. ignore spaces)
   PresentationState current = new PresentationState();
   if (myFragmentedContent != null && !Comparing.equal(myPresentationState, current)) {
     myFragmentedContent.recalculate();
     refreshData(myFragmentedContent);
   }
   myPreviousDiff.registerCustomShortcutSet(myPreviousDiff.getShortcutSet(), myParent);
   myNextDiff.registerCustomShortcutSet(myNextDiff.getShortcutSet(), myParent);
 }
Exemplo n.º 16
0
  public Couple<String> setText(@Nullable final String text, @Nullable final String requestor) {
    if (StringUtil.isEmpty(text)
        && !Comparing.equal(requestor, myCurrentRequestor)
        && !EventLog.LOG_REQUESTOR.equals(requestor)) {
      return Couple.of(myInfoPanel.getText(), myCurrentRequestor);
    }

    boolean logMode = myInfoPanel.updateText(EventLog.LOG_REQUESTOR.equals(requestor) ? "" : text);
    myCurrentRequestor = logMode ? EventLog.LOG_REQUESTOR : requestor;
    return Couple.of(text, requestor);
  }
 public boolean equals(Object object) {
   if (!(object instanceof ActionUrl)) {
     return false;
   }
   ActionUrl url = (ActionUrl) object;
   Object comp = myComponent instanceof Pair ? ((Pair) myComponent).first : myComponent;
   Object thatComp =
       url.myComponent instanceof Pair ? ((Pair) url.myComponent).first : url.myComponent;
   return Comparing.equal(comp, thatComp)
       && myGroupPath.equals(url.myGroupPath)
       && myAbsolutePosition == url.getAbsolutePosition();
 }
Exemplo n.º 18
0
 @Override
 public void visitReferenceExpression(final PsiReferenceExpression reference) {
   if (myLineRange.intersects(reference.getTextRange())) {
     final PsiElement psiElement = reference.resolve();
     if (psiElement instanceof PsiVariable) {
       final PsiVariable var = (PsiVariable) psiElement;
       if (var instanceof PsiField) {
         if (myCollectExpressions
             && !DebuggerUtils.hasSideEffectsOrReferencesMissingVars(
                 reference, myVisibleLocals)) {
           /*
           if (var instanceof PsiEnumConstant && reference.getQualifier() == null) {
             final PsiClass enumClass = ((PsiEnumConstant)var).getContainingClass();
             if (enumClass != null) {
               final PsiExpression expression = JavaPsiFacade.getInstance(var.getProject()).getParserFacade().createExpressionFromText(enumClass.getName() + "." + var.getName(), var);
               final PsiReference ref = expression.getReference();
               if (ref != null) {
                 ref.bindToElement(var);
                 myExpressions.add(new TextWithImportsImpl(expression));
               }
             }
           }
           else {
             myExpressions.add(new TextWithImportsImpl(reference));
           }
           */
           final PsiModifierList modifierList = var.getModifierList();
           boolean isConstant =
               (var instanceof PsiEnumConstant)
                   || (modifierList != null
                       && modifierList.hasModifierProperty(PsiModifier.STATIC)
                       && modifierList.hasModifierProperty(PsiModifier.FINAL));
           if (!isConstant) {
             myExpressions.add(new TextWithImportsImpl(reference));
           }
         }
       } else {
         if (myVisibleLocals.contains(var.getName())) {
           myVars.add(var.getName());
         } else {
           // fix for variables used in inner classes
           if (!Comparing.equal(
               PsiTreeUtil.getParentOfType(reference, PsiClass.class),
               PsiTreeUtil.getParentOfType(var, PsiClass.class))) {
             myExpressions.add(new TextWithImportsImpl(reference));
           }
         }
       }
     }
   }
   super.visitReferenceExpression(reference);
 }
Exemplo n.º 19
0
 public static boolean inTheSameMethod(
     @NotNull SourcePosition pos1, @NotNull SourcePosition pos2) {
   ApplicationManager.getApplication().assertReadAccessAllowed();
   PsiElement elem1 = pos1.getElementAt();
   PsiElement elem2 = pos2.getElementAt();
   if (elem1 == null) return elem2 == null;
   if (elem2 != null) {
     PsiElement expectedMethod = getContainingMethod(elem1);
     PsiElement currentMethod = getContainingMethod(elem2);
     return Comparing.equal(expectedMethod, currentMethod);
   }
   return false;
 }
 @Nullable
 private VirtualFile findNextFile(final VirtualFile file) {
   final EditorWindow[] windows = getWindows(); // TODO: use current file as base
   for (int i = 0; i != windows.length; ++i) {
     final VirtualFile[] files = windows[i].getFiles();
     for (final VirtualFile fileAt : files) {
       if (!Comparing.equal(fileAt, file)) {
         return fileAt;
       }
     }
   }
   return null;
 }
  private void registerAdditionalIndentOptions(FileType fileType, IndentOptions options) {
    boolean exist = false;
    for (final FileType existing : myAdditionalIndentOptions.keySet()) {
      if (Comparing.strEqual(existing.getDefaultExtension(), fileType.getDefaultExtension())) {
        exist = true;
        break;
      }
    }

    if (!exist) {
      myAdditionalIndentOptions.put(fileType, options);
    }
  }
  public void setConfigurationDirParameters(
      final boolean newUseDefault, final String newConfigurationDirectory) {
    final String defaultPath = IdeaSubversionConfigurationDirectory.getPath();
    final String oldEffectivePath =
        isUseDefaultConfiguation() ? defaultPath : getConfigurationDirectory();
    final String newEffectivePath = newUseDefault ? defaultPath : newConfigurationDirectory;

    boolean directoryChanged =
        !Comparing.equal(getConfigurationDirectory(), newConfigurationDirectory);
    if (directoryChanged) {
      setConfigurationDirectory(newConfigurationDirectory);
    }
    boolean usageChanged = isUseDefaultConfiguation() != newUseDefault;
    if (usageChanged) {
      setUseDefaultConfiguation(newUseDefault);
    }

    if (directoryChanged || usageChanged) {
      if (!Comparing.equal(oldEffectivePath, newEffectivePath)) {
        clear();
      }
    }
  }
 private static int getSeqNumber(@NotNull PsiClass aClass) {
   // sequence number of this class among its parent' child classes named the same
   PsiElement parent = aClass.getParent();
   if (parent == null) return -1;
   int seqNo = 0;
   for (PsiElement child : parent.getChildren()) {
     if (child == aClass) return seqNo;
     if (child instanceof PsiClass
         && Comparing.strEqual(aClass.getName(), ((PsiClass) child).getName())) {
       seqNo++;
     }
   }
   return -1;
 }
  private static boolean containsLineMarker(LineMarkerInfo info, Collection<LineMarkerInfo> where) {
    final String infoTooltip = info.getLineMarkerTooltip();

    for (LineMarkerInfo markerInfo : where) {
      String markerInfoTooltip;
      if (markerInfo.startOffset == info.startOffset
          && markerInfo.endOffset == info.endOffset
          && (Comparing.equal(infoTooltip, markerInfoTooltip = markerInfo.getLineMarkerTooltip())
              || ANY_TEXT.equals(markerInfoTooltip)
              || ANY_TEXT.equals(infoTooltip))) {
        return true;
      }
    }
    return false;
  }
Exemplo n.º 25
0
 public static boolean elementsEqual(Element e1, Element e2) {
   if (e1 == null) {
     return e2 == null;
   }
   if (!Comparing.equal(e1.getName(), e2.getName())) {
     return false;
   }
   if (!elementListsEqual(e1.getChildren(), e2.getChildren())) {
     return false;
   }
   if (!attributeListsEqual(e1.getAttributes(), e2.getAttributes())) {
     return false;
   }
   return true;
 }
Exemplo n.º 26
0
 private void closeEditor() {
   boolean unsplit = false;
   if (mySplittedWindow != null && !mySplittedWindow.isDisposed()) {
     final EditorWithProviderComposite[] editors = mySplittedWindow.getEditors();
     if (editors.length == 1 && Comparing.equal(editors[0].getFile(), myNewVirtualFile)) {
       unsplit = true;
     }
   }
   FileEditorManager.getInstance(myProject).closeFile(myNewVirtualFile);
   if (unsplit) {
     for (EditorWindow editorWindow : mySplittedWindow.findSiblings()) {
       editorWindow.unsplit(true);
     }
   }
 }
Exemplo n.º 27
0
 protected static void assertSameLinesWithFile(String filePath, String actualText) {
   String fileText;
   try {
     if (OVERWRITE_TESTDATA) {
       VfsTestUtil.overwriteTestData(filePath, actualText);
       System.out.println("File " + filePath + " created.");
     }
     fileText = FileUtil.loadFile(new File(filePath), CharsetToolkit.UTF8);
   } catch (FileNotFoundException e) {
     VfsTestUtil.overwriteTestData(filePath, actualText);
     throw new AssertionFailedError("No output text found. File " + filePath + " created.");
   } catch (IOException e) {
     throw new RuntimeException(e);
   }
   String expected = StringUtil.convertLineSeparators(fileText.trim());
   String actual = StringUtil.convertLineSeparators(actualText.trim());
   if (!Comparing.equal(expected, actual)) {
     throw new FileComparisonFailure(null, expected, actual, filePath);
   }
 }
Exemplo n.º 28
0
 private void commit(@NotNull LibraryImpl fromModel) {
   if (myLibraryTable != null) {
     ApplicationManager.getApplication().assertWriteAccessAllowed();
   }
   if (!Comparing.equal(fromModel.myName, myName)) {
     myName = fromModel.myName;
     if (myLibraryTable instanceof LibraryTableBase) {
       ((LibraryTableBase) myLibraryTable).fireLibraryRenamed(this);
     }
   }
   myKind = fromModel.getKind();
   myProperties = fromModel.myProperties;
   if (areRootsChanged(fromModel)) {
     disposeMyPointers();
     copyRootsFrom(fromModel);
     myJarDirectories.copyFrom(fromModel.myJarDirectories);
     myRootsWatcher.updateWatchedRoots();
     myRootProvider.fireRootSetChanged();
   }
 }
 @NotNull
 public VirtualFile[] getSelectedFiles() {
   final Set<VirtualFile> files = new ArrayListSet<VirtualFile>();
   for (final EditorWindow window : myWindows) {
     final VirtualFile file = window.getSelectedFile();
     if (file != null) {
       files.add(file);
     }
   }
   final VirtualFile[] virtualFiles = VfsUtilCore.toVirtualFileArray(files);
   final VirtualFile currentFile = getCurrentFile();
   if (currentFile != null) {
     for (int i = 0; i != virtualFiles.length; ++i) {
       if (Comparing.equal(virtualFiles[i], currentFile)) {
         virtualFiles[i] = virtualFiles[0];
         virtualFiles[0] = currentFile;
         break;
       }
     }
   }
   return virtualFiles;
 }
  @Nullable
  public static VcsRevisionDescription getCurrentRevisionDescription(
      final Project project, FilePath filePath, @Nullable String branch) throws VcsException {
    filePath = getLastCommitName(project, filePath);
    GitSimpleHandler h =
        new GitSimpleHandler(project, GitUtil.getGitRoot(filePath), GitCommand.LOG);
    GitLogParser parser =
        new GitLogParser(
            project, HASH, COMMIT_TIME, AUTHOR_NAME, COMMITTER_NAME, SUBJECT, BODY, RAW_BODY);
    h.setNoSSH(true);
    h.setSilent(true);
    h.addParameters("-n1", parser.getPretty());
    if (branch != null && !branch.isEmpty()) {
      h.addParameters(branch);
    } else {
      h.addParameters("--all");
    }
    h.endOptions();
    h.addRelativePaths(filePath);
    String result = h.run();
    if (result.length() == 0) {
      return null;
    }
    final GitLogRecord record = parser.parseOneRecord(result);
    if (record == null) {
      return null;
    }
    record.setUsedHandler(h);

    final String author =
        Comparing.equal(record.getAuthorName(), record.getCommitterName())
            ? record.getAuthorName()
            : record.getAuthorName() + " (" + record.getCommitterName() + ")";
    return new VcsRevisionDescriptionImpl(
        new GitRevisionNumber(record.getHash(), record.getDate()),
        record.getDate(),
        author,
        record.getFullMessage());
  }