public ProjectEnvironment(CoreProjectEnvironment projectEnvironment) {
   projectEnvironment
       .getProject()
       .registerService(
           XmlElementFactory.class, new XmlElementFactoryImpl(projectEnvironment.getProject()));
   projectEnvironment
       .getProject()
       .registerService(
           ExternalResourceManagerExImpl.class,
           new ProjectResources(PathMacrosImpl.getInstanceEx()));
 }
  private void registerMacro(Macro macro) {
    assert PathMacrosImpl.getToolMacroNames().contains(macro.getName())
        : "Macro '" + macro.getName() + "' should be registered in PathMacros!";

    myMacrosMap.put(macro.getName(), macro);
  }
    public ApplicationEnvironment(CoreApplicationEnvironment appEnvironment) {
      appEnvironment.registerFileType(HtmlFileType.INSTANCE, "html;htm;sht;shtm;shtml");
      appEnvironment.registerFileType(XHtmlFileType.INSTANCE, "xhtml");
      appEnvironment.registerFileType(DTDFileType.INSTANCE, "dtd;ent;mod;elt");

      appEnvironment.registerFileType(
          XmlFileType.INSTANCE, "xml;xsd;tld;xsl;jnlp;wsdl;jhm;ant;xul;xslt;rng;fxml");

      SyntaxHighlighterFactory.LANGUAGE_FACTORY.addExplicitExtension(
          XMLLanguage.INSTANCE, new XmlSyntaxHighlighterFactory());
      SyntaxHighlighterFactory.LANGUAGE_FACTORY.addExplicitExtension(
          DTDLanguage.INSTANCE, new DtdSyntaxHighlighterFactory());
      SyntaxHighlighterFactory.LANGUAGE_FACTORY.addExplicitExtension(
          HTMLLanguage.INSTANCE, new HtmlSyntaxHighlighterFactory());
      SyntaxHighlighterFactory.LANGUAGE_FACTORY.addExplicitExtension(
          XHTMLLanguage.INSTANCE, new XhtmlSyntaxHighlighterFactory());

      appEnvironment.addExplicitExtension(
          LanguageParserDefinitions.INSTANCE, XMLLanguage.INSTANCE, new XMLParserDefinition());
      appEnvironment.addExplicitExtension(
          LanguageParserDefinitions.INSTANCE, DTDLanguage.INSTANCE, new DTDParserDefinition());
      appEnvironment.addExplicitExtension(
          LanguageParserDefinitions.INSTANCE, HTMLLanguage.INSTANCE, new HTMLParserDefinition());
      appEnvironment.addExplicitExtension(
          LanguageParserDefinitions.INSTANCE, XHTMLLanguage.INSTANCE, new XHTMLParserDefinition());

      appEnvironment.addExplicitExtension(
          IdIndexers.INSTANCE, XmlFileType.INSTANCE, new XmlIdIndexer());
      appEnvironment.addExplicitExtension(
          IdIndexers.INSTANCE, DTDFileType.INSTANCE, new XmlIdIndexer());
      appEnvironment.addExplicitExtension(
          TodoIndexers.INSTANCE, XmlFileType.INSTANCE, new XmlTodoIndexer());
      appEnvironment.addExplicitExtension(
          TodoIndexers.INSTANCE, DTDFileType.INSTANCE, new XmlTodoIndexer());
      appEnvironment.addExplicitExtension(
          TodoIndexers.INSTANCE, XHtmlFileType.INSTANCE, new XHtmlTodoIndexer());

      CoreApplicationEnvironment.registerExtensionPoint(
          Extensions.getRootArea(), ReadWriteAccessDetector.EP_NAME, ReadWriteAccessDetector.class);
      appEnvironment.addExtension(
          ReadWriteAccessDetector.EP_NAME, new XmlReadWriteAccessDetector());

      CoreApplicationEnvironment.registerExtensionPoint(
          Extensions.getRootArea(), XmlFileNSInfoProvider.EP_NAME, XmlFileNSInfoProvider.class);
      appEnvironment.addExtension(XmlFileNSInfoProvider.EP_NAME, new HtmlFileNSInfoProvider());

      CoreApplicationEnvironment.registerExtensionPoint(
          Extensions.getRootArea(),
          StartTagEndTokenProvider.EP_NAME,
          StartTagEndTokenProvider.class);
      CoreApplicationEnvironment.registerExtensionPoint(
          Extensions.getRootArea(), XmlSuppressionProvider.EP_NAME, XmlSuppressionProvider.class);
      CoreApplicationEnvironment.registerExtensionPoint(
          Extensions.getRootArea(), XmlSchemaProvider.EP_NAME, XmlSchemaProvider.class);
      CoreApplicationEnvironment.registerExtensionPoint(
          Extensions.getRootArea(),
          ImplicitNamespaceDescriptorProvider.EP_NAME,
          ImplicitNamespaceDescriptorProvider.class);
      CoreApplicationEnvironment.registerExtensionPoint(
          Extensions.getRootArea(),
          XmlElementDescriptorProvider.EP_NAME,
          XmlElementDescriptorProvider.class);
      CoreApplicationEnvironment.registerExtensionPoint(
          Extensions.getRootArea(), Html5SchemaProvider.EP_NAME, Html5SchemaProvider.class);
      CoreApplicationEnvironment.registerExtensionPoint(
          Extensions.getRootArea(),
          XmlAttributeDescriptorsProvider.EP_NAME,
          XmlAttributeDescriptorsProvider.class);
      CoreApplicationEnvironment.registerExtensionPoint(
          Extensions.getRootArea(), XmlExtension.EP_NAME, XmlExtension.class);
      CoreApplicationEnvironment.registerExtensionPoint(
          Extensions.getRootArea(),
          HtmlEmbeddedTokenTypesProvider.EXTENSION_POINT_NAME,
          HtmlEmbeddedTokenTypesProvider.class);
      CoreApplicationEnvironment.registerExtensionPoint(
          Extensions.getRootArea(),
          StandardResourceProvider.EP_NAME,
          StandardResourceProvider.class);
      CoreApplicationEnvironment.registerExtensionPoint(
          Extensions.getRootArea(), StandardResourceEP.EP_NAME, StandardResourceEP.class);

      appEnvironment.addExtension(MetaDataContributor.EP_NAME, new XmlApplicationComponent());
      appEnvironment.addExtension(
          FileBasedIndexExtension.EXTENSION_POINT_NAME, new XmlNamespaceIndex());
      appEnvironment.addExtension(
          FileBasedIndexExtension.EXTENSION_POINT_NAME, new SchemaTypeInheritanceIndex());
      appEnvironment.addExtension(
          FileBasedIndexExtension.EXTENSION_POINT_NAME, new XmlTagNamesIndex());
      appEnvironment.addExtension(StandardResourceProvider.EP_NAME, new InternalResourceProvider());

      appEnvironment.registerApplicationComponent(PathMacros.class, new PathMacrosImpl());
      appEnvironment.registerApplicationService(
          ExternalResourceManager.class,
          new ExternalResourceManagerExImpl(PathMacrosImpl.getInstanceEx()));
      appEnvironment.registerApplicationService(XmlFoldingSettings.class, new XmlFoldingSettings());
      Language[] myLanguages =
          new Language[] {
            XMLLanguage.INSTANCE,
            HTMLLanguage.INSTANCE,
            XHTMLLanguage.INSTANCE,
            DTDLanguage.INSTANCE
          };
      for (Language myLanguage : myLanguages) {
        appEnvironment.addExplicitExtension(
            LanguageFolding.INSTANCE, myLanguage, new XmlFoldingBuilder());
        appEnvironment.addExplicitExtension(
            LanguageFindUsages.INSTANCE, myLanguage, new XmlFindUsagesProvider());
        appEnvironment.addExplicitExtension(
            LanguageASTFactory.INSTANCE, myLanguage, new XmlASTFactory());
      }
    }
  private static CmdlineRemoteProto.Message.ControllerMessage.GlobalSettings buildGlobalSettings() {
    final Map<String, String> data = new HashMap<String, String>();

    for (Map.Entry<String, String> entry : PathMacrosImpl.getGlobalSystemMacros().entrySet()) {
      data.put(entry.getKey(), FileUtil.toSystemIndependentName(entry.getValue()));
    }

    final PathMacros pathVars = PathMacros.getInstance();
    for (String name : pathVars.getAllMacroNames()) {
      final String path = pathVars.getValue(name);
      if (path != null) {
        data.put(name, FileUtil.toSystemIndependentName(path));
      }
    }

    final List<GlobalLibrary> globals = new ArrayList<GlobalLibrary>();

    fillSdks(globals);
    fillGlobalLibraries(globals);

    final CmdlineRemoteProto.Message.ControllerMessage.GlobalSettings.Builder cmdBuilder =
        CmdlineRemoteProto.Message.ControllerMessage.GlobalSettings.newBuilder();

    if (!data.isEmpty()) {
      for (Map.Entry<String, String> entry : data.entrySet()) {
        final String var = entry.getKey();
        final String value = entry.getValue();
        if (var != null && value != null) {
          cmdBuilder.addPathVariable(CmdlineProtoUtil.createPair(var, value));
        }
      }
    }

    if (!globals.isEmpty()) {
      for (GlobalLibrary lib : globals) {
        final CmdlineRemoteProto.Message.ControllerMessage.GlobalSettings.GlobalLibrary.Builder
            libBuilder =
                CmdlineRemoteProto.Message.ControllerMessage.GlobalSettings.GlobalLibrary
                    .newBuilder();
        libBuilder.setName(lib.getName()).addAllPath(lib.getPaths());
        if (lib instanceof SdkLibrary) {
          final SdkLibrary sdk = (SdkLibrary) lib;
          libBuilder.setHomePath(sdk.getHomePath());
          libBuilder.setTypeName(sdk.getTypeName());
          final String additional = sdk.getAdditionalDataXml();
          if (additional != null) {
            libBuilder.setAdditionalDataXml(additional);
          }
          final String version = sdk.getVersion();
          if (version != null) {
            libBuilder.setVersion(version);
          }
        }
        cmdBuilder.addGlobalLibrary(libBuilder.build());
      }
    }

    final String defaultCharset = EncodingManager.getInstance().getDefaultCharsetName();
    if (defaultCharset != null) {
      cmdBuilder.setGlobalEncoding(defaultCharset);
    }

    final String ignoredFilesList = FileTypeManager.getInstance().getIgnoredFilesList();
    cmdBuilder.setIgnoredFilesPatterns(ignoredFilesList);
    return cmdBuilder.build();
  }