private void writeState(final Element element) {
   JDOMExternalizerUtil.writeField(
       element, INSTRUMENTATION_TYPE_NAME, myInstrumentationType.toString());
   JDOMExternalizerUtil.writeField(element, LANGUAGE_ANNOTATION_NAME, myLanguageAnnotation);
   JDOMExternalizerUtil.writeField(element, PATTERN_ANNOTATION_NAME, myPatternAnnotation);
   JDOMExternalizerUtil.writeField(element, SUBST_ANNOTATION_NAME, mySubstAnnotation);
   if (myIncludeUncomputablesAsLiterals) {
     JDOMExternalizerUtil.writeField(element, INCLUDE_UNCOMPUTABLES_AS_LITERALS, "true");
   }
   if (mySourceModificationAllowed) {
     JDOMExternalizerUtil.writeField(element, SOURCE_MODIFICATION_ALLOWED, "true");
   }
   switch (myDfaOption) {
     case OFF:
       break;
     case RESOLVE:
       JDOMExternalizerUtil.writeField(element, RESOLVE_REFERENCES, Boolean.TRUE.toString());
       break;
     case ASSIGNMENTS:
       JDOMExternalizerUtil.writeField(
           element, LOOK_FOR_VAR_ASSIGNMENTS, Boolean.TRUE.toString());
       break;
     case DFA:
       JDOMExternalizerUtil.writeField(element, USE_DFA_IF_AVAILABLE, Boolean.TRUE.toString());
       break;
   }
 }
 static boolean shouldLoadPlugins() {
   try {
     // no plugins during bootstrap
     Class.forName("com.intellij.openapi.extensions.Extensions");
   } catch (ClassNotFoundException e) {
     return false;
   }
   //noinspection HardCodedStringLiteral
   final String loadPlugins = System.getProperty("idea.load.plugins");
   return loadPlugins == null || Boolean.TRUE.toString().equals(loadPlugins);
 }
  public boolean isToDrawMacCorner() {
    if (!SystemInfo.isMac || myComponent.getComponentCount() <= 0) {
      return false;
    }

    if (myComponent.getComponentCount() > 0) {
      Component component = myComponent.getComponent(0);
      if (component instanceof JComponent
          && Boolean.TRUE.equals(((JComponent) component).getClientProperty(SUPPRESS_MAC_CORNER))) {
        return false;
      }
    }

    return true;
  }
 @Override
 public void writeExternal(Element element) throws WriteExternalException {
   for (String s : myGroupPath) {
     Element path = new Element(PATH);
     path.setAttribute(VALUE, s);
     element.addContent(path);
   }
   if (myComponent instanceof String) {
     element.setAttribute(VALUE, (String) myComponent);
     element.setAttribute(IS_ACTION, Boolean.TRUE.toString());
   } else if (myComponent instanceof Separator) {
     element.setAttribute(SEPARATOR, Boolean.TRUE.toString());
   } else if (myComponent instanceof Group) {
     final String groupId =
         ((Group) myComponent).getId() != null && ((Group) myComponent).getId().length() != 0
             ? ((Group) myComponent).getId()
             : ((Group) myComponent).getName();
     element.setAttribute(VALUE, groupId != null ? groupId : "");
     element.setAttribute(IS_GROUP, Boolean.TRUE.toString());
   }
   element.setAttribute(ACTION_TYPE, Integer.toString(myActionType));
   element.setAttribute(POSITION, Integer.toString(myAbsolutePosition));
   DefaultJDOMExternalizer.writeExternal(this, element);
 }
  public GeneralHighlightingPass(
      @NotNull Project project,
      @NotNull PsiFile file,
      @NotNull Document document,
      int startOffset,
      int endOffset,
      boolean updateAll,
      @NotNull ProperTextRange priorityRange,
      @Nullable Editor editor) {
    super(project, document, PRESENTABLE_NAME, file, true);
    myStartOffset = startOffset;
    myEndOffset = endOffset;
    myUpdateAll = updateAll;
    myPriorityRange = priorityRange;
    myEditor = editor;

    LOG.assertTrue(file.isValid());
    setId(Pass.UPDATE_ALL);
    myHasErrorElement =
        !isWholeFileHighlighting() && Boolean.TRUE.equals(myFile.getUserData(HAS_ERROR_ELEMENT));
    FileStatusMap fileStatusMap =
        ((DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(myProject)).getFileStatusMap();
    myErrorFound = !isWholeFileHighlighting() && fileStatusMap.wasErrorFound(myDocument);

    myApplyCommand =
        new Runnable() {
          @Override
          public void run() {
            ProperTextRange range = new ProperTextRange(myStartOffset, myEndOffset);
            MarkupModel model = DocumentMarkupModel.forDocument(myDocument, myProject, true);
            UpdateHighlightersUtil.cleanFileLevelHighlights(myProject, Pass.UPDATE_ALL, myFile);
            final EditorColorsScheme colorsScheme = getColorsScheme();
            UpdateHighlightersUtil.setHighlightersInRange(
                myProject,
                myDocument,
                range,
                colorsScheme,
                myHighlights,
                (MarkupModelEx) model,
                Pass.UPDATE_ALL);
          }
        };

    // initial guess to show correct progress in the traffic light icon
    setProgressLimit(document.getTextLength() / 2); // approx number of PSI elements = file length/2
    myGlobalScheme = EditorColorsManager.getInstance().getGlobalScheme();
  }
  public void assertIsDispatchThread(@Nullable final JComponent component) {
    if (component == null) return;

    Thread curThread = Thread.currentThread();
    if (ourDispatchThread == curThread) {
      return;
    }

    if (Boolean.TRUE.equals(component.getClientProperty(WAS_EVER_SHOWN))) {
      assertIsDispatchThread();
    } else {
      final JRootPane root = component.getRootPane();
      if (root != null) {
        component.putClientProperty(WAS_EVER_SHOWN, Boolean.TRUE);
        assertIsDispatchThread();
      }
    }
  }
  public void readDirectoryMappings(final Element element) {
    myMappings.clear();

    final List<VcsDirectoryMapping> mappingsList = new ArrayList<VcsDirectoryMapping>();
    boolean haveNonEmptyMappings = false;
    for (Element child : element.getChildren(ELEMENT_MAPPING)) {
      final String vcs = child.getAttributeValue(ATTRIBUTE_VCS);
      if (vcs != null && !vcs.isEmpty()) {
        haveNonEmptyMappings = true;
      }
      VcsDirectoryMapping mapping =
          new VcsDirectoryMapping(child.getAttributeValue(ATTRIBUTE_DIRECTORY), vcs);
      mappingsList.add(mapping);

      Element rootSettingsElement = child.getChild(ELEMENT_ROOT_SETTINGS);
      if (rootSettingsElement != null) {
        String className = rootSettingsElement.getAttributeValue(ATTRIBUTE_CLASS);
        AbstractVcs vcsInstance = findVcsByName(mapping.getVcs());
        if (vcsInstance != null && className != null) {
          final VcsRootSettings rootSettings = vcsInstance.createEmptyVcsRootSettings();
          if (rootSettings != null) {
            try {
              rootSettings.readExternal(rootSettingsElement);
              mapping.setRootSettings(rootSettings);
            } catch (InvalidDataException e) {
              LOG.error(
                  "Failed to load VCS root settings class "
                      + className
                      + " for VCS "
                      + vcsInstance.getClass().getName(),
                  e);
            }
          }
        }
      }
    }
    boolean defaultProject =
        Boolean.TRUE.toString().equals(element.getAttributeValue(ATTRIBUTE_DEFAULT_PROJECT));
    // run autodetection if there's no VCS in default project and
    if (haveNonEmptyMappings || !defaultProject) {
      myMappingsLoaded = true;
    }
    myMappings.setDirectoryMappings(mappingsList);
  }
 public void writeDirectoryMappings(final Element element) {
   if (myProject.isDefault()) {
     element.setAttribute(ATTRIBUTE_DEFAULT_PROJECT, Boolean.TRUE.toString());
   }
   for (VcsDirectoryMapping mapping : getDirectoryMappings()) {
     Element child = new Element(ELEMENT_MAPPING);
     child.setAttribute(ATTRIBUTE_DIRECTORY, mapping.getDirectory());
     child.setAttribute(ATTRIBUTE_VCS, mapping.getVcs());
     final VcsRootSettings rootSettings = mapping.getRootSettings();
     if (rootSettings != null) {
       Element rootSettingsElement = new Element(ELEMENT_ROOT_SETTINGS);
       rootSettingsElement.setAttribute(ATTRIBUTE_CLASS, rootSettings.getClass().getName());
       try {
         rootSettings.writeExternal(rootSettingsElement);
         child.addContent(rootSettingsElement);
       } catch (WriteExternalException e) {
         // don't add element
       }
     }
     element.addContent(child);
   }
 }
 private void updateIcon(AnAction action) {
   if (isToggleable()
       && (myPresentation.getIcon() == null
           || myInsideCheckedGroup
           || !UISettings.getInstance().SHOW_ICONS_IN_MENUS)) {
     action.update(myEvent);
     myToggled =
         Boolean.TRUE.equals(
             myEvent.getPresentation().getClientProperty(Toggleable.SELECTED_PROPERTY));
     if (ActionPlaces.MAIN_MENU.equals(myPlace) && SystemInfo.isMacSystemMenu
         || UIUtil.isUnderNimbusLookAndFeel()
         || UIUtil.isUnderWindowsLookAndFeel() && SystemInfo.isWin7OrNewer) {
       setState(myToggled);
     } else if (!(getUI() instanceof GtkMenuItemUI)) {
       if (myToggled) {
         setIcon(ourCheckedIcon);
         setDisabledIcon(IconLoader.getDisabledIcon(ourCheckedIcon));
       } else {
         setIcon(ourUncheckedIcon);
         setDisabledIcon(IconLoader.getDisabledIcon(ourUncheckedIcon));
       }
     }
   } else {
     if (UISettings.getInstance().SHOW_ICONS_IN_MENUS) {
       Icon icon = myPresentation.getIcon();
       if (action instanceof ToggleAction && ((ToggleAction) action).isSelected(myEvent)) {
         icon = new PoppedIcon(icon, 16, 16);
       }
       setIcon(icon);
       if (myPresentation.getDisabledIcon() != null) {
         setDisabledIcon(myPresentation.getDisabledIcon());
       } else {
         setDisabledIcon(IconLoader.getDisabledIcon(icon));
       }
     }
   }
 }