@TestOnly
 public void clearCodeStyleSettings() {
   CodeStyleSettings cleanSettings = new CodeStyleSettings();
   copyFrom(cleanSettings);
   myAdditionalIndentOptions.clear(); // hack
   myLoadedAdditionalIndentOptions = false;
 }
예제 #2
0
  private static void cleanupSwingDataStructures() throws Exception {
    Class<?> aClass = Class.forName("javax.swing.KeyboardManager");

    Method get = aClass.getMethod("getCurrentManager");
    get.setAccessible(true);
    Object manager = get.invoke(null);
    {
      Field mapF = aClass.getDeclaredField("componentKeyStrokeMap");
      mapF.setAccessible(true);
      Object map = mapF.get(manager);
      ((Map) map).clear();
    }
    {
      Field mapF = aClass.getDeclaredField("containerMap");
      mapF.setAccessible(true);
      Object map = mapF.get(manager);
      ((Map) map).clear();
    }
  }
예제 #3
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);
   }
 }
예제 #4
0
 @Override
 public void dispose() {
   setRefreshVisible(false);
   InlineProgressIndicator[] indicators =
       getCurrentInlineIndicators().toArray(new InlineProgressIndicator[0]);
   for (InlineProgressIndicator indicator : indicators) {
     Disposer.dispose(indicator);
   }
   myInline2Original.clear();
   myOriginal2Inlines.clear();
 }
  public void reloadProjectImpl(@NotNull final Project p, final boolean clearCopyToRestore) {
    if (clearCopyToRestore) {
      mySavedCopies.clear();
      mySavedTimestamps.clear();
    }

    final Project[] project = {p};

    ProjectReloadState.getInstance(project[0]).onBeforeAutomaticProjectReload();
    final Application application = ApplicationManager.getApplication();

    application.invokeLater(
        new Runnable() {
          @Override
          public void run() {
            LOG.debug("Reloading project.");
            ProjectImpl projectImpl = (ProjectImpl) project[0];
            if (projectImpl.isDisposed()) return;
            IProjectStore projectStore = projectImpl.getStateStore();
            final String location = projectImpl.getPresentableUrl();

            final List<IFile> original;
            try {
              final IComponentStore.SaveSession saveSession = projectStore.startSave();
              original = saveSession.getAllStorageFiles(true);
              saveSession.finishSave();
            } catch (IOException e) {
              LOG.error(e);
              return;
            }

            if (project[0].isDisposed() || ProjectUtil.closeAndDispose(project[0])) {
              application.runWriteAction(
                  new Runnable() {
                    @Override
                    public void run() {
                      for (final IFile originalFile : original) {
                        restoreCopy(
                            LocalFileSystem.getInstance().refreshAndFindFileByIoFile(originalFile));
                      }
                    }
                  });

              project[0] = null; // Let it go.

              ProjectUtil.openProject(location, null, true);
            }
          }
        },
        ModalityState.NON_MODAL);
  }
  public void compile() throws CompilerException, CacheCorruptedException {
    Application application = ApplicationManager.getApplication();
    try {
      if (!myFilesToCompile.isEmpty()) {
        if (application.isUnitTestMode()) {
          saveTestData();
        }
        compileModules(buildModuleToFilesMap(myFilesToCompile));
      }
    } catch (SecurityException e) {
      throw new CompilerException(
          CompilerBundle.message("error.compiler.process.not.started", e.getMessage()), e);
    } catch (IllegalArgumentException e) {
      throw new CompilerException(e.getMessage(), e);
    } finally {
      for (final VirtualFile file : myModuleToTempDirMap.values()) {
        if (file != null) {
          final File ioFile = new File(file.getPath());
          FileUtil.asyncDelete(ioFile);
        }
      }
      myModuleToTempDirMap.clear();
    }

    if (!myFilesToCompile.isEmpty()
        && myCompileContext.getMessageCount(CompilerMessageCategory.ERROR) == 0) {
      // package-info.java hack
      final List<TranslatingCompiler.OutputItem> outputs =
          new ArrayList<TranslatingCompiler.OutputItem>();
      ApplicationManager.getApplication()
          .runReadAction(
              new Runnable() {
                public void run() {
                  for (final VirtualFile file : myFilesToCompile) {
                    if (PACKAGE_ANNOTATION_FILE_NAME.equals(file.getName())
                        && !myProcessedPackageInfos.contains(file)) {
                      outputs.add(new OutputItemImpl(file));
                    }
                  }
                }
              });
      if (!outputs.isEmpty()) {
        mySink.add(null, outputs, VirtualFile.EMPTY_ARRAY);
      }
    }
  }
  @Override
  @Nullable
  public Project newProject(
      final String projectName,
      @NotNull String filePath,
      boolean useDefaultProjectSettings,
      boolean isDummy) {
    filePath = toCanonicalName(filePath);

    //noinspection ConstantConditions
    if (LOG_PROJECT_LEAKAGE_IN_TESTS && ApplicationManager.getApplication().isUnitTestMode()) {
      for (int i = 0; i < 42; i++) {
        if (myProjects.size() < MAX_LEAKY_PROJECTS) break;
        System.gc();
        TimeoutUtil.sleep(100);
        System.gc();
      }

      if (myProjects.size() >= MAX_LEAKY_PROJECTS) {
        List<Project> copy = new ArrayList<Project>(myProjects.keySet());
        myProjects.clear();
        throw new TooManyProjectLeakedException(copy);
      }
    }

    ProjectImpl project =
        createProject(
            projectName, filePath, false, ApplicationManager.getApplication().isUnitTestMode());
    try {
      initProject(project, useDefaultProjectSettings ? (ProjectImpl) getDefaultProject() : null);
      if (LOG_PROJECT_LEAKAGE_IN_TESTS) {
        myProjects.put(project, null);
      }
      return project;
    } catch (final Exception e) {
      LOG.info(e);
      Messages.showErrorDialog(message(e), ProjectBundle.message("project.load.default.error"));
    }
    return null;
  }
  private void doRead(@NotNull final Element parentNode) {
    ApplicationManager.getApplication()
        .runReadAction(
            new Runnable() {
              @Override
              @SuppressWarnings({"HardCodedStringLiteral"})
              public void run() {
                final Map<String, Breakpoint> nameToBreakpointMap =
                    new THashMap<String, Breakpoint>();
                try {
                  final List groups = parentNode.getChildren();
                  for (final Object group1 : groups) {
                    final Element group = (Element) group1;
                    if (group.getName().equals(RULES_GROUP_NAME)) {
                      continue;
                    }
                    // skip already converted
                    if (group.getAttribute(CONVERTED_PARAM) != null) {
                      continue;
                    }
                    final String categoryName = group.getName();
                    final Key<Breakpoint> breakpointCategory =
                        BreakpointCategory.lookup(categoryName);
                    final String defaultPolicy =
                        group.getAttributeValue(DEFAULT_SUSPEND_POLICY_ATTRIBUTE_NAME);
                    final boolean conditionEnabled =
                        Boolean.parseBoolean(
                            group.getAttributeValue(
                                DEFAULT_CONDITION_STATE_ATTRIBUTE_NAME, "true"));
                    setBreakpointDefaults(
                        breakpointCategory,
                        new BreakpointDefaults(defaultPolicy, conditionEnabled));
                    Element anyExceptionBreakpointGroup;
                    if (!AnyExceptionBreakpoint.ANY_EXCEPTION_BREAKPOINT.equals(
                        breakpointCategory)) {
                      // for compatibility with previous format
                      anyExceptionBreakpointGroup =
                          group.getChild(
                              AnyExceptionBreakpoint.ANY_EXCEPTION_BREAKPOINT.toString());
                      // final BreakpointFactory factory =
                      // BreakpointFactory.getInstance(breakpointCategory);
                      // if (factory != null) {
                      for (Element breakpointNode : group.getChildren("breakpoint")) {
                        // Breakpoint breakpoint = factory.createBreakpoint(myProject,
                        // breakpointNode);
                        Breakpoint breakpoint = createBreakpoint(categoryName, breakpointNode);
                        breakpoint.readExternal(breakpointNode);
                        nameToBreakpointMap.put(breakpoint.getDisplayName(), breakpoint);
                      }
                      // }
                    } else {
                      anyExceptionBreakpointGroup = group;
                    }

                    if (anyExceptionBreakpointGroup != null) {
                      final Element breakpointElement = group.getChild("breakpoint");
                      if (breakpointElement != null) {
                        XBreakpointManager manager =
                            XDebuggerManager.getInstance(myProject).getBreakpointManager();
                        JavaExceptionBreakpointType type =
                            (JavaExceptionBreakpointType)
                                XDebuggerUtil.getInstance()
                                    .findBreakpointType(JavaExceptionBreakpointType.class);
                        XBreakpoint<JavaExceptionBreakpointProperties> xBreakpoint =
                            manager.getDefaultBreakpoint(type);
                        Breakpoint breakpoint = createJavaBreakpoint(xBreakpoint);
                        breakpoint.readExternal(breakpointElement);
                        addBreakpoint(breakpoint);
                      }
                    }
                  }
                } catch (InvalidDataException ignored) {
                }

                final Element rulesGroup = parentNode.getChild(RULES_GROUP_NAME);
                if (rulesGroup != null) {
                  final List<Element> rules = rulesGroup.getChildren("rule");
                  for (Element rule : rules) {
                    // skip already converted
                    if (rule.getAttribute(CONVERTED_PARAM) != null) {
                      continue;
                    }
                    final Element master = rule.getChild(MASTER_BREAKPOINT_TAGNAME);
                    if (master == null) {
                      continue;
                    }
                    final Element slave = rule.getChild(SLAVE_BREAKPOINT_TAGNAME);
                    if (slave == null) {
                      continue;
                    }
                    final Breakpoint masterBreakpoint =
                        nameToBreakpointMap.get(master.getAttributeValue("name"));
                    if (masterBreakpoint == null) {
                      continue;
                    }
                    final Breakpoint slaveBreakpoint =
                        nameToBreakpointMap.get(slave.getAttributeValue("name"));
                    if (slaveBreakpoint == null) {
                      continue;
                    }

                    boolean leaveEnabled =
                        "true".equalsIgnoreCase(rule.getAttributeValue("leaveEnabled"));
                    XDependentBreakpointManager dependentBreakpointManager =
                        ((XBreakpointManagerImpl) getXBreakpointManager())
                            .getDependentBreakpointManager();
                    dependentBreakpointManager.setMasterBreakpoint(
                        slaveBreakpoint.myXBreakpoint,
                        masterBreakpoint.myXBreakpoint,
                        leaveEnabled);
                    // addBreakpointRule(new EnableBreakpointRule(BreakpointManager.this,
                    // masterBreakpoint, slaveBreakpoint, leaveEnabled));
                  }
                }

                DebuggerInvocationUtil.invokeLater(
                    myProject,
                    new Runnable() {
                      @Override
                      public void run() {
                        updateBreakpointsUI();
                      }
                    });
              }
            });

    myUIProperties.clear();
    final Element props = parentNode.getChild("ui_properties");
    if (props != null) {
      final List children = props.getChildren("property");
      for (Object child : children) {
        Element property = (Element) child;
        final String name = property.getAttributeValue("name");
        final String value = property.getAttributeValue("value");
        if (name != null && value != null) {
          myUIProperties.put(name, value);
        }
      }
    }
  }
 public void clear() {
   myStorage.clear();
 }