private static VirtualFile[] copyFiles( final VirtualFile[] fromFiles, final VirtualFile toDir, VirtualFile rawProjectRoot) throws IOException { final VirtualFile[] toFiles = new VirtualFile[fromFiles.length]; final boolean rootSpecified = rawProjectRoot != null; for (int i = 0, n = fromFiles.length; i < n; i++) { VirtualFile fromFile = fromFiles[i]; VirtualFile toP = toDir; if (rootSpecified) { final List<String> fromParents = new ArrayList<>(4); VirtualFile fromP = fromFile.getParent(); if (!Comparing.equal(fromP, rawProjectRoot)) { do { fromParents.add(fromP.getName()); } while (!Comparing.equal((fromP = fromP.getParent()), rawProjectRoot)); for (int j = fromParents.size() - 1; j >= 0; j--) { toP = toP.createChildDirectory(null, fromParents.get(j)); } } } final VirtualFile toFile = toP.createChildData(null, fromFile.getName()); toFile.setBinaryContent(fromFile.contentsToByteArray()); toFiles[i] = toFile; } return toFiles; }
public boolean equals(Object object) { if (!(object instanceof TextWithImportsImpl)) { return false; } TextWithImportsImpl item = ((TextWithImportsImpl) object); return Comparing.equal(item.myText, myText) && Comparing.equal(item.myImports, myImports); }
@Override public boolean isConfigurationFromContext( JUnitConfiguration unitConfiguration, ConfigurationContext context) { if (RunConfigurationProducer.getInstance(PatternConfigurationProducer.class) .isMultipleElementsSelected(context)) { return false; } final RunConfiguration predefinedConfiguration = context.getOriginalConfiguration(JUnitConfigurationType.getInstance()); final Location contextLocation = context.getLocation(); String paramSetName = contextLocation instanceof PsiMemberParameterizedLocation ? ((PsiMemberParameterizedLocation) contextLocation).getParamSetName() : null; assert contextLocation != null; Location location = JavaExecutionUtil.stepIntoSingleClass(contextLocation); if (location == null) { return false; } final PsiElement element = location.getPsiElement(); final PsiClass testClass = JUnitUtil.getTestClass(element); final PsiMethod testMethod = JUnitUtil.getTestMethod(element, false); final PsiPackage testPackage; if (element instanceof PsiPackage) { testPackage = (PsiPackage) element; } else if (element instanceof PsiDirectory) { testPackage = JavaDirectoryService.getInstance().getPackage(((PsiDirectory) element)); } else { testPackage = null; } PsiDirectory testDir = element instanceof PsiDirectory ? (PsiDirectory) element : null; RunnerAndConfigurationSettings template = RunManager.getInstance(location.getProject()) .getConfigurationTemplate(getConfigurationFactory()); final Module predefinedModule = ((JUnitConfiguration) template.getConfiguration()).getConfigurationModule().getModule(); final String vmParameters = predefinedConfiguration instanceof JUnitConfiguration ? ((JUnitConfiguration) predefinedConfiguration).getVMParameters() : null; if (vmParameters != null && !Comparing.strEqual(vmParameters, unitConfiguration.getVMParameters())) return false; if (paramSetName != null && !Comparing.strEqual(paramSetName, unitConfiguration.getProgramParameters())) return false; final TestObject testobject = unitConfiguration.getTestObject(); if (testobject != null) { if (testobject.isConfiguredByElement( unitConfiguration, testClass, testMethod, testPackage, testDir)) { final Module configurationModule = unitConfiguration.getConfigurationModule().getModule(); if (Comparing.equal(location.getModule(), configurationModule)) return true; if (Comparing.equal(predefinedModule, configurationModule)) { return true; } } } return false; }
@Override protected RunnerAndConfigurationSettings findExistingByElement( Location location, @NotNull RunnerAndConfigurationSettings[] existingConfigurations, ConfigurationContext context) { final PsiClass aClass = ApplicationConfigurationType.getMainClass(location.getPsiElement()); if (aClass == null) { return null; } final Module predefinedModule = ((ApplicationConfiguration) ((RunManagerImpl) RunManagerEx.getInstanceEx(location.getProject())) .getConfigurationTemplate(getConfigurationFactory()) .getConfiguration()) .getConfigurationModule() .getModule(); for (RunnerAndConfigurationSettings existingConfiguration : existingConfigurations) { final ApplicationConfiguration appConfiguration = (ApplicationConfiguration) existingConfiguration.getConfiguration(); if (Comparing.equal( JavaExecutionUtil.getRuntimeQualifiedName(aClass), appConfiguration.MAIN_CLASS_NAME)) { if (Comparing.equal( location.getModule(), appConfiguration.getConfigurationModule().getModule())) { return existingConfiguration; } final Module configurationModule = appConfiguration.getConfigurationModule().getModule(); if (Comparing.equal(location.getModule(), configurationModule)) return existingConfiguration; if (Comparing.equal(predefinedModule, configurationModule)) { return existingConfiguration; } } } return null; }
public boolean restoreSelection(TreeSelection treeSelection) { if (treeSelection.isEmpty()) return false; DefaultMutableTreeNode root = (DefaultMutableTreeNode) myTreeModel.getRoot(); for (int i = 0; i < root.getChildCount(); i++) { TreeNode node = root.getChildAt(i); if (node instanceof MessageNode) { MessageNode messageNode = (MessageNode) node; String[] text = messageNode.getText(); if (text.length == 0) continue; if (Comparing.equal(treeSelection.mySelectedTarget, text[0])) { TreePath pathToSelect = new TreePath(messageNode.getPath()); for (Enumeration enumeration = messageNode.children(); enumeration.hasMoreElements(); ) { Object o = enumeration.nextElement(); if (o instanceof MessageNode) { messageNode = (MessageNode) o; if (Comparing.equal(treeSelection.mySelectedTask, text[0])) { pathToSelect = new TreePath(messageNode.getPath()); break; } } } TreeUtil.selectPath(myTree, pathToSelect); myTree.expandPath(pathToSelect); return true; } } } return false; }
public boolean isModified() { return myManifestFileConfiguration != null && (!myManifestFileConfiguration.getClasspath().equals(getConfiguredClasspath()) || !Comparing.equal( myManifestFileConfiguration.getMainClass(), getConfiguredMainClass()) || !Comparing.equal( myManifestFileConfiguration.getManifestFilePath(), getConfiguredManifestPath())); }
public boolean isModified() { if (myProperties.isEnabled() != myRunTargetCheckBox.isSelected()) return true; if (myTarget == null) { return myProperties.getFileUrl() != null; } if (!Comparing.equal(myTarget.getName(), myProperties.getTargetName())) return true; final VirtualFile file = myTarget.getModel().getBuildFile().getVirtualFile(); return file != null && !Comparing.equal(file.getUrl(), myProperties.getFileUrl()); }
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; }
public static boolean isRoot(PsiFileSystemItem directory) { if (directory == null) return true; VirtualFile vFile = directory.getVirtualFile(); if (vFile == null) return true; ProjectFileIndex fileIndex = ProjectFileIndex.SERVICE.getInstance(directory.getProject()); return Comparing.equal(fileIndex.getClassRootForFile(vFile), vFile) || Comparing.equal(fileIndex.getContentRootForFile(vFile), vFile) || Comparing.equal(fileIndex.getSourceRootForFile(vFile), vFile); }
@Override public int compare(VirtualFile file1, VirtualFile file2) { final VirtualFile r1 = getFileRoot(file1); final VirtualFile r2 = getFileRoot(file2); for (VirtualFile root : myEntries) { if (Comparing.equal(r1, root)) return 1; if (Comparing.equal(r2, root)) return -1; } return 0; }
@Override public boolean equals(Object obj) { if (obj instanceof GrClosureParameter) { return Comparing.equal(myType, ((GrClosureParameter) obj).getType()) && Comparing.equal(myOptional, ((GrClosureParameter) obj).isOptional()) && Comparing.equal( myDefaultInitializer, ((GrClosureParameter) obj).getDefaultInitializer()); } return super.equals(obj); }
@SuppressWarnings("UnsafeVfsRecursion") @NotNull public static VirtualFileVisitor.Result visitChildrenRecursively( @NotNull VirtualFile file, @NotNull VirtualFileVisitor<?> visitor) throws VisitorException { boolean pushed = false; try { final boolean visited = visitor.allowVisitFile(file); if (visited) { VirtualFileVisitor.Result result = visitor.visitFileEx(file); if (result.skipChildren) return result; } Iterable<VirtualFile> childrenIterable = null; VirtualFile[] children = null; try { if (file.isValid() && visitor.allowVisitChildren(file) && !visitor.depthLimitReached()) { childrenIterable = visitor.getChildrenIterable(file); if (childrenIterable == null) { children = file.getChildren(); } } } catch (InvalidVirtualFileAccessException e) { LOG.info("Ignoring: " + e.getMessage()); return VirtualFileVisitor.CONTINUE; } if (childrenIterable != null) { visitor.saveValue(); pushed = true; for (VirtualFile child : childrenIterable) { VirtualFileVisitor.Result result = visitChildrenRecursively(child, visitor); if (result.skipToParent != null && !Comparing.equal(result.skipToParent, child)) return result; } } else if (children != null && children.length != 0) { visitor.saveValue(); pushed = true; for (VirtualFile child : children) { VirtualFileVisitor.Result result = visitChildrenRecursively(child, visitor); if (result.skipToParent != null && !Comparing.equal(result.skipToParent, child)) return result; } } if (visited) { visitor.afterChildrenVisited(file); } return VirtualFileVisitor.CONTINUE; } finally { visitor.restoreValue(pushed); } }
public boolean isEqual(WCInfo val1, WCInfo val2) { if (val1 == val2) return true; if (val1 == null || val2 == null || val1.getClass() != val2.getClass()) return false; if (!Comparing.equal(val1.getFormat(), val2.getFormat())) return false; if (!Comparing.equal(val1.getPath(), val2.getPath())) return false; if (!Comparing.equal(val1.getStickyDepth(), val2.getStickyDepth())) return false; if (!Comparing.equal(val1.getType(), val2.getType())) return false; if (!Comparing.equal(val1.getUrl(), val2.getUrl())) return false; return true; }
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()); }
public boolean equals(final Object object) { if (!(object instanceof Data)) return false; final Data second = (Data) object; return Comparing.equal(TEST_OBJECT, second.TEST_OBJECT) && Comparing.equal(getMainClassName(), second.getMainClassName()) && Comparing.equal(getPackageName(), second.getPackageName()) && Comparing.equal(getMethodName(), second.getMethodName()) && Comparing.equal(getWorkingDirectory(), second.getWorkingDirectory()) && Comparing.equal(VM_PARAMETERS, second.VM_PARAMETERS) && Comparing.equal(PARAMETERS, second.PARAMETERS) && Comparing.equal(myPattern, second.myPattern) && Comparing.equal(FORK_MODE, second.FORK_MODE) && Comparing.equal(DIR_NAME, second.DIR_NAME); }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; DirectoryInfo info = (DirectoryInfo) o; return sourceRootTypeData == info.sourceRootTypeData && Comparing.equal(contentRoot, info.contentRoot) && Comparing.equal(libraryClassRoot, info.libraryClassRoot) && Comparing.equal(module, info.module) && Arrays.equals(orderEntries, info.orderEntries) && Comparing.equal(sourceRoot, info.sourceRoot); }
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()); }
public LocalChangeList getListCopy(@NotNull final VirtualFile file) { for (LocalChangeList list : myMap.values()) { for (Change change : list.getChanges()) { if (change.getAfterRevision() != null && Comparing.equal(change.getAfterRevision().getFile().getVirtualFile(), file)) { return list.copy(); } if (change.getBeforeRevision() != null && Comparing.equal(change.getBeforeRevision().getFile().getVirtualFile(), file)) { return list.copy(); } } } return null; }
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(); } }
private void editSelected() { CheckedTreeNode node = getSelectedToolNode(); if (node != null && node.getUserObject() instanceof Tool) { Tool selected = (Tool) node.getUserObject(); if (selected != null) { String oldGroupName = selected.getGroup(); ToolEditorDialog dlg = new ToolEditorDialog(this); dlg.setData(selected, getGroups()); dlg.show(); if (dlg.isOK()) { selected.copyFrom(dlg.getData()); String newGroupName = selected.getGroup(); if (!Comparing.equal(oldGroupName, newGroupName)) { CheckedTreeNode oldGroupNode = (CheckedTreeNode) node.getParent(); removeNodeFromParent(node); ((ToolsGroup) oldGroupNode.getUserObject()).removeElement(selected); if (oldGroupNode.getChildCount() == 0) { removeNodeFromParent(oldGroupNode); } insertNewTool(selected, true); } else { (getModel()).nodeChanged(node); } myIsModified = true; update(); } } } }
public void insertOrUpdateTranslation( String key, String value, final PropertiesFile propertiesFile) throws IncorrectOperationException { final IProperty property = propertiesFile.findPropertyByKey(key); if (property != null) { final String oldValue = property.getValue(); if (!Comparing.equal(oldValue, value)) { property.setValue(value); myCodeStyleManager.reformat(property.getPsiElement()); } return; } if (myOrdered) { if (myAlphaSorted) { myCodeStyleManager.reformat(propertiesFile.addProperty(key, value).getPsiElement()); return; } final Pair<IProperty, Integer> propertyAndPosition = findExistedPrevSiblingProperty(key, propertiesFile); myCodeStyleManager.reformat( propertiesFile .addPropertyAfter( key, value, propertyAndPosition == null ? null : (Property) propertyAndPosition.getFirst()) .getPsiElement()); } else { insertPropertyLast(key, value, propertiesFile); } }
protected boolean shouldDisplay( EvaluationContext context, @NotNull ObjectReference objInstance, @NotNull Field field) { final boolean isSynthetic = DebuggerUtils.isSynthetic(field); if (!SHOW_SYNTHETICS && isSynthetic) { return false; } if (SHOW_VAL_FIELDS_AS_LOCAL_VARIABLES && isSynthetic) { try { final StackFrameProxy frameProxy = context.getFrameProxy(); if (frameProxy != null) { final Location location = frameProxy.location(); if (location != null && objInstance.equals(context.getThisObject()) && Comparing.equal(objInstance.referenceType(), location.declaringType()) && StringUtil.startsWith( field.name(), FieldDescriptorImpl.OUTER_LOCAL_VAR_FIELD_PREFIX)) { return false; } } } catch (EvaluateException ignored) { } } if (!SHOW_STATIC && field.isStatic()) { return false; } if (!SHOW_STATIC_FINAL && field.isStatic() && field.isFinal()) { return false; } return true; }
@Nullable public PsiElement[] getElements(boolean[] isCopied) { try { Transferable content = myCopyPasteManager.getContents(); if (content == null) { return null; } Object transferData; try { transferData = content.getTransferData(ourDataFlavor); } catch (UnsupportedFlavorException e) { return null; } catch (IOException e) { return null; } if (!(transferData instanceof MyData)) { return null; } MyData dataProxy = (MyData) transferData; if (!Comparing.equal(dataProxy, myRecentData)) { return null; } if (isCopied != null) { isCopied[0] = myRecentData.isCopied(); } return myRecentData.getElements(); } catch (Exception e) { if (LOG.isDebugEnabled()) { LOG.debug(e); } return null; } }
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; }
@Override public boolean isModified() { boolean compilationEnabled = commonSettingsEditor.getEnableCompilationCheckbox().isSelected(); String outputPath = commonSettingsEditor.getProtobufCompilerOutputPathField().getText().trim(); boolean compileInGivenPath = commonSettingsEditor.getProtobufCompilerRunInFixedDirectory().isSelected(); String runDirectory = commonSettingsEditor.getProtobufCompilerRunDirectory().getText().trim(); return (configuration.isCompilationEnabled() != compilationEnabled || !Comparing.equal( configuration.getCompilerOutputPath(), FileUtil.toSystemIndependentName(outputPath)) || configuration.isCompilationUseGivenRunDirectory() != compileInGivenPath || !Comparing.equal( configuration.getCompilationRunDirectory(), FileUtil.toSystemIndependentName(runDirectory))); }
private static boolean isActionChanged(String actionId, Keymap oldKeymap, Keymap newKeymap) { if (!newKeymap.canModify()) return false; Shortcut[] oldShortcuts = oldKeymap.getShortcuts(actionId); Shortcut[] newShortcuts = newKeymap.getShortcuts(actionId); return !Comparing.equal(oldShortcuts, newShortcuts); }
private static PsiAnnotationMemberValue[] readFromClass( @NonNls String attributeName, @NotNull PsiAnnotation magic, PsiType type) { PsiAnnotationMemberValue fromClassAttr = magic.findAttributeValue(attributeName); PsiType fromClassType = fromClassAttr instanceof PsiClassObjectAccessExpression ? ((PsiClassObjectAccessExpression) fromClassAttr).getOperand().getType() : null; PsiClass fromClass = fromClassType instanceof PsiClassType ? ((PsiClassType) fromClassType).resolve() : null; if (fromClass == null) return null; String fqn = fromClass.getQualifiedName(); if (fqn == null) return null; List<PsiAnnotationMemberValue> constants = new ArrayList<PsiAnnotationMemberValue>(); for (PsiField field : fromClass.getFields()) { if (!field.hasModifierProperty(PsiModifier.PUBLIC) || !field.hasModifierProperty(PsiModifier.STATIC) || !field.hasModifierProperty(PsiModifier.FINAL)) continue; PsiType fieldType = field.getType(); if (!Comparing.equal(fieldType, type)) continue; PsiAssignmentExpression e = (PsiAssignmentExpression) JavaPsiFacade.getElementFactory(field.getProject()) .createExpressionFromText("x=" + fqn + "." + field.getName(), field); PsiReferenceExpression refToField = (PsiReferenceExpression) e.getRExpression(); constants.add(refToField); } if (constants.isEmpty()) return null; return constants.toArray(new PsiAnnotationMemberValue[constants.size()]); }
@Override public boolean equals(Object o) { if (!super.equals(o)) return false; GitlabRepository repository = (GitlabRepository) o; if (!Comparing.equal(myCurrentProject, repository.myCurrentProject)) return false; return true; }
@Override public boolean isModified() { VcsContentAnnotationSettings settings = VcsContentAnnotationSettings.getInstance(myProject); if (myHighlightRecentlyChanged.isSelected() != settings.isShow()) return true; if (!Comparing.equal(myHighlightInterval.getValue(), settings.getLimitDays())) return true; return false; }
@Override public void apply( @NotNull MultiMap<VirtualFile, TextFilePatchInProgress> patchGroups, @Nullable LocalChangeList localList, @Nullable String fileName, @Nullable TransparentlyFailedValueI<Map<String, Map<String, CharSequence>>, PatchSyntaxException> additionalInfo) { final List<FilePatch> patches; try { patches = ApplyPatchSaveToFileExecutor.patchGroupsToOneGroup(patchGroups, myBaseDir); } catch (IOException e) { myInner.handleException(e, true); return; } final PatchApplier<BinaryFilePatch> patchApplier = new PatchApplier<BinaryFilePatch>( myVcs.getProject(), myBaseDir, patches, localList, null, null); patchApplier.execute(false, true); // 3 boolean thereAreCreations = false; for (FilePatch patch : patches) { if (patch.isNewFile() || !Comparing.equal(patch.getAfterName(), patch.getBeforeName())) { thereAreCreations = true; break; } } if (thereAreCreations) { // restore deletion of old directory: myInner.next(new DirectoryAddition()); // 2 } appendResolveConflictToContext(myInner); // 1 appendTailToContextLast(myInner); // 4 myInner.ping(); }