private void runAfterCommitActions(@NotNull Document document) {
    ApplicationManager.getApplication().assertIsDispatchThread();
    List<Runnable> list;
    synchronized (ACTION_AFTER_COMMIT) {
      list = document.getUserData(ACTION_AFTER_COMMIT);
      if (list != null) {
        list = new ArrayList<Runnable>(list);
        document.putUserData(ACTION_AFTER_COMMIT, null);
      }
    }
    if (list != null) {
      for (final Runnable runnable : list) {
        runnable.run();
      }
    }

    if (!hasUncommitedDocuments() && !actionsWhenAllDocumentsAreCommitted.isEmpty()) {
      List<Object> keys = new ArrayList<Object>(actionsWhenAllDocumentsAreCommitted.keySet());
      for (Object key : keys) {
        try {
          Runnable action = actionsWhenAllDocumentsAreCommitted.remove(key);
          myDocumentCommitProcessor.log(
              "Running after commit runnable: ", null, false, key, action);
          action.run();
        } catch (Throwable e) {
          LOG.error(e);
        }
      }
    }
  }
  @NotNull
  public synchronized List<Breakpoint> getBreakpoints() {
    if (myBreakpointsListForIteration == null) {
      myBreakpointsListForIteration = new ArrayList<Breakpoint>(myBreakpoints.size());

      XBreakpoint<?>[] xBreakpoints =
          ApplicationManager.getApplication()
              .runReadAction(
                  new Computable<XBreakpoint<?>[]>() {
                    public XBreakpoint<?>[] compute() {
                      return getXBreakpointManager().getAllBreakpoints();
                    }
                  });
      for (XBreakpoint<?> xBreakpoint : xBreakpoints) {
        if (isJavaType(xBreakpoint)) {
          Breakpoint breakpoint = myBreakpoints.get(xBreakpoint);
          if (breakpoint == null) {
            breakpoint = createJavaBreakpoint(xBreakpoint);
            myBreakpoints.put(xBreakpoint, breakpoint);
          }
        }
      }

      myBreakpointsListForIteration.addAll(myBreakpoints.values());
    }
    return myBreakpointsListForIteration;
  }
 public void checkWarnings() {
   highlightingTypes.put(
       WARNING_MARKER, new ExpectedHighlightingSet(HighlightSeverity.WARNING, false, true));
   highlightingTypes.put(
       END_LINE_WARNING_MARKER,
       new ExpectedHighlightingSet(HighlightSeverity.WARNING, true, true));
 }
  @NotNull
  private VirtualFilePointerImpl getOrCreate(
      @NotNull Disposable parentDisposable,
      @Nullable VirtualFilePointerListener listener,
      @NotNull String path,
      @NotNull Pair<VirtualFile, String> fileAndUrl) {
    FilePointerPartNode root = myPointers.get(listener);
    FilePointerPartNode node;
    if (root == null) {
      root = new FilePointerPartNode(path, null, fileAndUrl);
      myPointers.put(listener, root);
      node = root;
    } else {
      node = root.findPointerOrCreate(path, 0, fileAndUrl);
    }

    VirtualFilePointerImpl pointer;
    if (node.leaf == null) {
      pointer = new VirtualFilePointerImpl(listener, parentDisposable, fileAndUrl);
      node.associate(pointer, fileAndUrl);
    } else {
      pointer = node.leaf;
    }
    pointer.myNode.incrementUsageCount(1);

    root.checkConsistency();
    return pointer;
  }
 public void checkInfos() {
   highlightingTypes.put(
       INFO_MARKER, new ExpectedHighlightingSet(HighlightSeverity.INFORMATION, false, true));
   highlightingTypes.put(
       "inject",
       new ExpectedHighlightingSet(HighlightInfoType.INJECTED_FRAGMENT_SEVERITY, false, true));
 }
 public void putData(String kind, String realm, Object data) {
   if (data == null) {
     myStorage.remove(kind + "$" + realm);
   } else {
     myStorage.put(kind + "$" + realm, data);
   }
 }
  public void removeEntryPoint(RefElement anEntryPoint) {
    if (anEntryPoint instanceof RefClass) {
      RefClass refClass = (RefClass) anEntryPoint;
      if (!refClass.isInterface()) {
        anEntryPoint = refClass.getDefaultConstructor();
      }
    }

    if (anEntryPoint == null) return;

    myTemporaryEntryPoints.remove(anEntryPoint);

    Set<Map.Entry<String, SmartRefElementPointer>> set = myPersistentEntryPoints.entrySet();
    String key = null;
    for (Map.Entry<String, SmartRefElementPointer> entry : set) {
      SmartRefElementPointer value = entry.getValue();
      if (value.getRefElement() == anEntryPoint) {
        key = entry.getKey();
        break;
      }
    }

    if (key != null) {
      myPersistentEntryPoints.remove(key);
      ((RefElementImpl) anEntryPoint).setEntry(false);
    }

    if (anEntryPoint.isPermanentEntry() && anEntryPoint.isValid()) {
      final Project project = anEntryPoint.getElement().getProject();
      final EntryPointsManagerImpl entryPointsManager = getInstance(project);
      if (this != entryPointsManager) {
        entryPointsManager.removeEntryPoint(anEntryPoint);
      }
    }
  }
  public void checkLineMarkers(
      @NotNull Collection<LineMarkerInfo> markerInfos, @NotNull String text) {
    String fileName = myFile == null ? "" : myFile.getName() + ": ";
    String failMessage = "";

    for (LineMarkerInfo info : markerInfos) {
      if (!containsLineMarker(info, myLineMarkerInfos.values())) {
        if (!failMessage.isEmpty()) failMessage += '\n';
        failMessage +=
            fileName
                + "Extra line marker highlighted "
                + rangeString(text, info.startOffset, info.endOffset)
                + ": '"
                + info.getLineMarkerTooltip()
                + "'";
      }
    }

    for (LineMarkerInfo expectedLineMarker : myLineMarkerInfos.values()) {
      if (!markerInfos.isEmpty() && !containsLineMarker(expectedLineMarker, markerInfos)) {
        if (!failMessage.isEmpty()) failMessage += '\n';
        failMessage +=
            fileName
                + "Line marker was not highlighted "
                + rangeString(text, expectedLineMarker.startOffset, expectedLineMarker.endOffset)
                + ": '"
                + expectedLineMarker.getLineMarkerTooltip()
                + "'";
      }
    }

    if (!failMessage.isEmpty()) Assert.fail(failMessage);
  }
  public static boolean putProxyCredentialsIntoServerFile(
      @NotNull final File configDir,
      @NotNull final String host,
      @NotNull final PasswordAuthentication authentication) {
    final IdeaSVNConfigFile configFile =
        new IdeaSVNConfigFile(new File(configDir, SERVERS_FILE_NAME));
    configFile.updateGroups();

    String groupName = SvnAuthenticationManager.getGroupForHost(host, configFile);
    // no proxy defined in group -> no sense in password
    if (StringUtil.isEmptyOrSpaces(groupName)) return false;
    final Map<String, String> properties = configFile.getAllGroups().get(groupName).getProperties();
    if (StringUtil.isEmptyOrSpaces(properties.get(SvnAuthenticationManager.HTTP_PROXY_HOST)))
      return false;
    if (StringUtil.isEmptyOrSpaces(properties.get(SvnAuthenticationManager.HTTP_PROXY_PORT)))
      return false;

    configFile.setValue(
        groupName, SvnAuthenticationManager.HTTP_PROXY_USERNAME, authentication.getUserName());
    configFile.setValue(
        groupName,
        SvnAuthenticationManager.HTTP_PROXY_PASSWORD,
        String.valueOf(authentication.getPassword()));
    configFile.save();
    return true;
  }
 void removeNode(@NotNull FilePointerPartNode node, VirtualFilePointerListener listener) {
   boolean rootNodeEmpty = node.remove();
   if (rootNodeEmpty) {
     myPointers.remove(listener);
   } else {
     myPointers.get(listener).checkConsistency();
   }
 }
Ejemplo n.º 11
0
 private static Map<String, LocalVariableProxyImpl> getVisibleVariables(
     final StackFrameProxyImpl frame) throws EvaluateException {
   final Map<String, LocalVariableProxyImpl> vars = new HashMap<String, LocalVariableProxyImpl>();
   for (LocalVariableProxyImpl localVariableProxy : frame.visibleVariables()) {
     vars.put(localVariableProxy.name(), localVariableProxy);
   }
   return vars;
 }
 @NotNull
 private IdentityVirtualFilePointer getOrCreateIdentity(@NotNull String url, VirtualFile found) {
   IdentityVirtualFilePointer pointer = myUrlToIdentity.get(url);
   if (pointer == null) {
     pointer = new IdentityVirtualFilePointer(found, url);
     myUrlToIdentity.put(url, pointer);
   }
   return pointer;
 }
Ejemplo n.º 13
0
 private String getOutputDir(final Module module) {
   if (myModuleToOutput.containsKey(module)) {
     return myModuleToOutput.get(module);
   }
   final VirtualFile outputDirectory = myCompileContext.getModuleOutputDirectory(module);
   final String out = outputDirectory != null ? outputDirectory.getPath() : null;
   myModuleToOutput.put(module, out);
   return out;
 }
Ejemplo n.º 14
0
 private void copyRootsFrom(LibraryImpl fromModel) {
   myRoots.clear();
   for (Map.Entry<OrderRootType, VirtualFilePointerContainer> entry :
       fromModel.myRoots.entrySet()) {
     OrderRootType rootType = entry.getKey();
     VirtualFilePointerContainer container = entry.getValue();
     VirtualFilePointerContainer clone = container.clone(myPointersDisposable);
     myRoots.put(rootType, clone);
   }
 }
  static boolean shouldSkipPlugin(
      final IdeaPluginDescriptor descriptor, IdeaPluginDescriptor[] loaded) {
    final String idString = descriptor.getPluginId().getIdString();
    if (idString.equals(CORE_PLUGIN_ID)) {
      return false;
    }

    //noinspection HardCodedStringLiteral
    final String pluginId = System.getProperty("idea.load.plugins.id");
    if (pluginId == null) {
      if (descriptor instanceof IdeaPluginDescriptorImpl && !descriptor.isEnabled()) return true;

      if (!shouldLoadPlugins()) return true;
    }
    final List<String> pluginIds = pluginId == null ? null : StringUtil.split(pluginId, ",");

    final boolean checkModuleDependencies =
        !ourAvailableModules.isEmpty() && !ourAvailableModules.contains("com.intellij.modules.all");
    if (checkModuleDependencies && !hasModuleDependencies(descriptor)) {
      return true;
    }

    boolean shouldLoad;
    //noinspection HardCodedStringLiteral
    final String loadPluginCategory = System.getProperty("idea.load.plugins.category");
    if (loadPluginCategory != null) {
      shouldLoad = loadPluginCategory.equals(descriptor.getCategory());
    } else {
      if (pluginIds != null) {
        shouldLoad = pluginIds.contains(idString);
        if (!shouldLoad) {
          Map<PluginId, IdeaPluginDescriptor> map = new HashMap<PluginId, IdeaPluginDescriptor>();
          for (final IdeaPluginDescriptor pluginDescriptor : loaded) {
            map.put(pluginDescriptor.getPluginId(), pluginDescriptor);
          }
          addModulesAsDependents(map);
          final IdeaPluginDescriptor descriptorFromProperty = map.get(PluginId.getId(pluginId));
          shouldLoad =
              descriptorFromProperty != null
                  && isDependent(
                      descriptorFromProperty,
                      descriptor.getPluginId(),
                      map,
                      checkModuleDependencies);
        }
      } else {
        shouldLoad = !getDisabledPlugins().contains(idString);
      }
      if (shouldLoad && descriptor instanceof IdeaPluginDescriptorImpl) {
        if (isIncompatible(descriptor)) return true;
      }
    }

    return !shouldLoad;
  }
Ejemplo n.º 16
0
 @NotNull
 public Map<String, String> getLocalNamespaceDeclarations() {
   Map<String, String> namespaces = new THashMap<String, String>();
   for (final XmlAttribute attribute : getAttributes()) {
     if (!attribute.isNamespaceDeclaration() || attribute.getValue() == null) continue;
     // xmlns -> "", xmlns:a -> a
     final String localName = attribute.getLocalName();
     namespaces.put(localName.equals(attribute.getName()) ? "" : localName, attribute.getValue());
   }
   return namespaces;
 }
    static void registerDisposable(Disposable parentDisposable, VirtualFilePointerImpl pointer) {
      synchronized (ourInstances) {
        DelegatingDisposable result = ourInstances.get(parentDisposable);
        if (result == null) {
          ourInstances.put(parentDisposable, result = new DelegatingDisposable(parentDisposable));
          Disposer.register(parentDisposable, result);
        }

        result.myCounts.put(pointer, result.myCounts.get(pointer) + 1);
      }
    }
  public BackgroundableActionEnabledHandler getBackgroundableActionHandler(
      final VcsBackgroundableActions action) {
    ApplicationManager.getApplication().assertIsDispatchThread();

    BackgroundableActionEnabledHandler result = myBackgroundableActionHandlerMap.get(action);
    if (result == null) {
      result = new BackgroundableActionEnabledHandler();
      myBackgroundableActionHandlerMap.put(action, result);
    }
    return result;
  }
Ejemplo n.º 19
0
  public String getAttributeValue(String qname) { // todo ?
    Map<String, String> map = myAttributeValueMap;
    while (map == null) {
      getAttributes();
      map = myAttributeValueMap;

      if (map == null) {
        myAttributes = null;
      }
    }
    return map.get(qname);
  }
  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);
    }
  }
Ejemplo n.º 21
0
  private Map<OrderRootType, VirtualFilePointerContainer> initRoots() {
    Disposer.register(this, myPointersDisposable);

    Map<OrderRootType, VirtualFilePointerContainer> result =
        new HashMap<OrderRootType, VirtualFilePointerContainer>(4);

    for (OrderRootType rootType : getAllRootTypes()) {
      result.put(
          rootType, VirtualFilePointerManager.getInstance().createContainer(myPointersDisposable));
    }

    return result;
  }
  @Override
  public void writeExternal(Element element) throws WriteExternalException {
    final CodeStyleSettings parentSettings = new CodeStyleSettings();
    DefaultJDOMExternalizer.writeExternal(
        this, element, new DifferenceFilter<CodeStyleSettings>(this, parentSettings));
    List<CustomCodeStyleSettings> customSettings =
        new ArrayList<CustomCodeStyleSettings>(getCustomSettingsValues());

    Collections.sort(
        customSettings,
        new Comparator<CustomCodeStyleSettings>() {
          @Override
          public int compare(final CustomCodeStyleSettings o1, final CustomCodeStyleSettings o2) {
            return o1.getTagName().compareTo(o2.getTagName());
          }
        });

    for (final CustomCodeStyleSettings settings : customSettings) {
      final CustomCodeStyleSettings parentCustomSettings =
          parentSettings.getCustomSettings(settings.getClass());
      if (parentCustomSettings == null) {
        throw new WriteExternalException("Custom settings are null for " + settings.getClass());
      }
      settings.writeExternal(element, parentCustomSettings);
    }

    final FileType[] fileTypes =
        myAdditionalIndentOptions
            .keySet()
            .toArray(new FileType[myAdditionalIndentOptions.keySet().size()]);
    Arrays.sort(
        fileTypes,
        new Comparator<FileType>() {
          @Override
          public int compare(final FileType o1, final FileType o2) {
            return o1.getDefaultExtension().compareTo(o2.getDefaultExtension());
          }
        });

    for (FileType fileType : fileTypes) {
      final IndentOptions indentOptions = myAdditionalIndentOptions.get(fileType);
      Element additionalIndentOptions = new Element(ADDITIONAL_INDENT_OPTIONS);
      indentOptions.serialize(additionalIndentOptions, getDefaultIndentOptions(fileType));
      additionalIndentOptions.setAttribute(FILETYPE, fileType.getDefaultExtension());
      if (!additionalIndentOptions.getChildren().isEmpty()) {
        element.addContent(additionalIndentOptions);
      }
    }

    myCommonSettingsManager.writeExternal(element);
  }
Ejemplo n.º 23
0
  private ProgressIndicatorEx removeFromMaps(@NotNull InlineProgressIndicator progress) {
    final ProgressIndicatorEx original = myInline2Original.get(progress);

    myInline2Original.remove(progress);

    myOriginal2Inlines.remove(original, progress);
    if (myOriginal2Inlines.get(original) == null) {
      final int originalIndex = myOriginals.indexOf(original);
      myOriginals.remove(originalIndex);
      myInfos.remove(originalIndex);
    }

    return original;
  }
Ejemplo n.º 24
0
 private VirtualFile getTempDir(Module module) throws IOException {
   VirtualFile tempDir = myModuleToTempDirMap.get(module);
   if (tempDir == null) {
     final String projectName = myProject.getName();
     final String moduleName = module.getName();
     File tempDirectory = FileUtil.createTempDirectory(projectName, moduleName);
     tempDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDirectory);
     if (tempDir == null) {
       LOG.error("Cannot locate temp directory " + tempDirectory.getPath());
     }
     myModuleToTempDirMap.put(module, tempDir);
   }
   return tempDir;
 }
  @Override
  public void after(@NotNull final List<? extends VFileEvent> events) {
    incModificationCount();

    for (FilePointerPartNode node : myPointersToUpdateUrl) {
      synchronized (this) {
        VirtualFilePointerImpl pointer = node.leaf;
        String urlBefore = pointer.getUrlNoUpdate();
        Pair<VirtualFile, String> after = node.update();
        String urlAfter = after.second;
        if (URL_COMPARATOR.compare(urlBefore, urlAfter) != 0) {
          // url has changed, reinsert
          FilePointerPartNode root = myPointers.get(pointer.getListener());
          int useCount = node.useCount;
          node.remove();
          FilePointerPartNode newNode =
              root.findPointerOrCreate(VfsUtilCore.urlToPath(urlAfter), 0, after);
          VirtualFilePointerImpl existingPointer = newNode.leaf;
          if (existingPointer != null) {
            // can happen when e.g. file renamed to the existing file
            // merge two pointers
            pointer.myNode = newNode;
          } else {
            newNode.associate(pointer, after);
          }
          newNode.incrementUsageCount(useCount);
        }
      }
    }

    VirtualFilePointer[] pointersToFireArray = toPointers(myPointersToFire);
    for (VirtualFilePointer pointer : pointersToFireArray) {
      ((VirtualFilePointerImpl) pointer).myNode.update();
    }

    for (EventDescriptor event : myEvents) {
      event.fireAfter();
    }

    if (pointersToFireArray.length != 0) {
      myBus.syncPublisher(VirtualFilePointerListener.TOPIC).validityChanged(pointersToFireArray);
    }

    myPointersToUpdateUrl = Collections.emptyList();
    myEvents = Collections.emptyList();
    myPointersToFire = Collections.emptyList();
    for (FilePointerPartNode root : myPointers.values()) {
      root.checkConsistency();
    }
  }
Ejemplo n.º 26
0
  @NotNull
  private InlineProgressIndicator createInlineDelegate(
      @NotNull TaskInfo info, @NotNull ProgressIndicatorEx original, final boolean compact) {
    final Collection<InlineProgressIndicator> inlines = myOriginal2Inlines.get(original);
    if (inlines != null) {
      for (InlineProgressIndicator eachInline : inlines) {
        if (eachInline.isCompact() == compact) return eachInline;
      }
    }

    final InlineProgressIndicator inline = new MyInlineProgressIndicator(compact, info, original);

    myInline2Original.put(inline, original);
    myOriginal2Inlines.put(original, inline);

    if (compact) {
      inline
          .getComponent()
          .addMouseListener(
              new MouseAdapter() {
                @Override
                public void mousePressed(MouseEvent e) {
                  handle(e);
                }

                @Override
                public void mouseReleased(MouseEvent e) {
                  handle(e);
                }
              });
    }

    return inline;
  }
Ejemplo n.º 27
0
  private void removeProgress(@NotNull InlineProgressIndicator progress) {
    synchronized (myOriginals) {
      if (!myInline2Original.containsKey(progress)) return;

      final boolean last = myOriginals.size() == 1;
      final boolean beforeLast = myOriginals.size() == 2;

      myPopup.removeIndicator(progress);

      final ProgressIndicatorEx original = removeFromMaps(progress);
      if (myOriginals.contains(original)) return;

      if (last) {
        restoreEmptyStatus();
        if (myShouldClosePopupAndOnProcessFinish) {
          hideProcessPopup();
        }
      } else {
        if (myPopup.isShowing() || myOriginals.size() > 1) {
          buildInProcessCount();
        } else if (beforeLast) {
          buildInInlineIndicator(createInlineDelegate(myInfos.get(0), myOriginals.get(0), true));
        } else {
          restoreEmptyStatus();
        }
      }

      runQuery();
    }
  }
 @TestOnly
 public void clearCodeStyleSettings() {
   CodeStyleSettings cleanSettings = new CodeStyleSettings();
   copyFrom(cleanSettings);
   myAdditionalIndentOptions.clear(); // hack
   myLoadedAdditionalIndentOptions = false;
 }
 @Override
 public void removeVcsListener(VcsListener listener) {
   final MessageBusConnection connection = myAdapters.remove(listener);
   if (connection != null) {
     connection.disconnect();
   }
 }
  /**
   * remove highlights (bounded with <marker>...</marker>) from test case file
   *
   * @param document document to process
   */
  private void extractExpectedHighlightsSet(final Document document) {
    final String text = document.getText();

    final Set<String> markers = myHighlightingTypes.keySet();
    final String typesRx = "(?:" + StringUtil.join(markers, ")|(?:") + ")";
    final String openingTagRx =
        "<("
            + typesRx
            + ")"
            + "(?:\\s+descr=\"((?:[^\"]|\\\\\"|\\\\\\\\\"|\\\\\\[|\\\\\\])*)\")?"
            + "(?:\\s+type=\"([0-9A-Z_]+)\")?"
            + "(?:\\s+foreground=\"([0-9xa-f]+)\")?"
            + "(?:\\s+background=\"([0-9xa-f]+)\")?"
            + "(?:\\s+effectcolor=\"([0-9xa-f]+)\")?"
            + "(?:\\s+effecttype=\"([A-Z]+)\")?"
            + "(?:\\s+fonttype=\"([0-9]+)\")?"
            + "(?:\\s+textAttributesKey=\"((?:[^\"]|\\\\\"|\\\\\\\\\"|\\\\\\[|\\\\\\])*)\")?"
            + "(?:\\s+bundleMsg=\"((?:[^\"]|\\\\\"|\\\\\\\\\")*)\")?"
            + "(/)?>";

    final Matcher matcher = Pattern.compile(openingTagRx).matcher(text);
    int pos = 0;
    final Ref<Integer> textOffset = Ref.create(0);
    while (matcher.find(pos)) {
      textOffset.set(textOffset.get() + matcher.start() - pos);
      pos = extractExpectedHighlight(matcher, text, document, textOffset);
    }
  }