Search in sources :

Example 16 with CodeStyleSettings

use of com.intellij.psi.codeStyle.CodeStyleSettings in project intellij-community by JetBrains.

the class XsltRefactoringTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    final CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(myFixture.getProject()).getCurrentSettings();
    XmlCodeStyleSettings xmlSettings = settings.getCustomSettings(XmlCodeStyleSettings.class);
    xmlSettings.XML_SPACE_INSIDE_EMPTY_TAG = true;
    settings.getIndentOptions(StdFileTypes.XML).INDENT_SIZE = 2;
}
Also used : XmlCodeStyleSettings(com.intellij.psi.formatter.xml.XmlCodeStyleSettings) CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings) XmlCodeStyleSettings(com.intellij.psi.formatter.xml.XmlCodeStyleSettings)

Example 17 with CodeStyleSettings

use of com.intellij.psi.codeStyle.CodeStyleSettings in project intellij-community by JetBrains.

the class Pep8ExternalAnnotator method collectInformation.

@Nullable
@Override
public State collectInformation(@NotNull PsiFile file) {
    VirtualFile vFile = file.getVirtualFile();
    if (vFile == null || vFile.getFileType() != PythonFileType.INSTANCE) {
        return null;
    }
    Sdk sdk = PythonSdkType.findLocalCPython(ModuleUtilCore.findModuleForPsiElement(file));
    if (sdk == null) {
        if (!myReportedMissingInterpreter) {
            myReportedMissingInterpreter = true;
            reportMissingInterpreter();
        }
        return null;
    }
    final String homePath = sdk.getHomePath();
    if (homePath == null) {
        if (!myReportedMissingInterpreter) {
            myReportedMissingInterpreter = true;
            LOG.info("Could not find home path for interpreter " + homePath);
        }
        return null;
    }
    final InspectionProfile profile = InspectionProjectProfileManager.getInstance(file.getProject()).getCurrentProfile();
    final HighlightDisplayKey key = HighlightDisplayKey.find(PyPep8Inspection.INSPECTION_SHORT_NAME);
    if (!profile.isToolEnabled(key, file)) {
        return null;
    }
    if (file instanceof PyFileImpl && !((PyFileImpl) file).isAcceptedFor(PyPep8Inspection.class)) {
        return null;
    }
    final PyPep8Inspection inspection = (PyPep8Inspection) profile.getUnwrappedTool(PyPep8Inspection.KEY.toString(), file);
    final CodeStyleSettings commonSettings = CodeStyleSettingsManager.getInstance(file.getProject()).getCurrentSettings();
    final PyCodeStyleSettings customSettings = commonSettings.getCustomSettings(PyCodeStyleSettings.class);
    final List<String> ignoredErrors = Lists.newArrayList(inspection.ignoredErrors);
    if (!customSettings.SPACE_AFTER_NUMBER_SIGN) {
        // Block comment should start with a space
        ignoredErrors.add("E262");
        // Inline comment should start with a space
        ignoredErrors.add("E265");
    }
    if (!customSettings.SPACE_BEFORE_NUMBER_SIGN) {
        // At least two spaces before inline comment
        ignoredErrors.add("E261");
    }
    final int margin = commonSettings.getRightMargin(file.getLanguage());
    return new State(homePath, file.getText(), profile.getErrorLevel(key, file), ignoredErrors, margin, customSettings.HANG_CLOSING_BRACKETS);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings) CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings) PyCodeStyleSettings(com.jetbrains.python.formatter.PyCodeStyleSettings) InspectionProfile(com.intellij.codeInspection.InspectionProfile) HighlightDisplayKey(com.intellij.codeInsight.daemon.HighlightDisplayKey) PyCodeStyleSettings(com.jetbrains.python.formatter.PyCodeStyleSettings) Sdk(com.intellij.openapi.projectRoots.Sdk) PyFileImpl(com.jetbrains.python.psi.impl.PyFileImpl) PyPep8Inspection(com.jetbrains.python.inspections.PyPep8Inspection) Nullable(org.jetbrains.annotations.Nullable)

Example 18 with CodeStyleSettings

use of com.intellij.psi.codeStyle.CodeStyleSettings in project intellij-community by JetBrains.

the class XmlCompletionTest method testInsertExtraRequiredAttributeSingleQuote.

public void testInsertExtraRequiredAttributeSingleQuote() throws Exception {
    final CodeStyleSettings settings = getCurrentCodeStyleSettings();
    final CodeStyleSettings.QuoteStyle quote = settings.HTML_QUOTE_STYLE;
    try {
        settings.HTML_QUOTE_STYLE = CodeStyleSettings.QuoteStyle.Single;
        configureByFile(getTestName(true) + ".html");
        checkResultByFile(getTestName(true) + "_after.html");
    } finally {
        CodeStyleSchemes.getInstance().getCurrentScheme().getCodeStyleSettings().HTML_QUOTE_STYLE = quote;
    }
}
Also used : CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings)

Example 19 with CodeStyleSettings

use of com.intellij.psi.codeStyle.CodeStyleSettings in project intellij-community by JetBrains.

the class LightPlatformTestCase method doSetup.

public static void doSetup(@NotNull LightProjectDescriptor descriptor, @NotNull LocalInspectionTool[] localInspectionTools, @NotNull Disposable parentDisposable) throws Exception {
    assertNull("Previous test " + ourTestCase + " hasn't called tearDown(). Probably overridden without super call.", ourTestCase);
    IdeaLogger.ourErrorsOccurred = null;
    ApplicationManager.getApplication().assertIsDispatchThread();
    boolean reusedProject = true;
    if (ourProject == null || ourProjectDescriptor == null || !ourProjectDescriptor.equals(descriptor)) {
        initProject(descriptor);
        reusedProject = false;
    }
    ProjectManagerEx projectManagerEx = ProjectManagerEx.getInstanceEx();
    projectManagerEx.openTestProject(ourProject);
    if (reusedProject) {
        DumbService.getInstance(ourProject).queueTask(new UnindexedFilesUpdater(ourProject));
    }
    MessageBusConnection connection = ourProject.getMessageBus().connect(parentDisposable);
    connection.subscribe(ProjectTopics.MODULES, new ModuleListener() {

        @Override
        public void moduleAdded(@NotNull Project project, @NotNull Module module) {
            fail("Adding modules is not permitted in LightIdeaTestCase.");
        }
    });
    clearUncommittedDocuments(getProject());
    InspectionsKt.configureInspections(localInspectionTools, getProject(), parentDisposable);
    assertFalse(getPsiManager().isDisposed());
    Boolean passed = null;
    try {
        passed = StartupManagerEx.getInstanceEx(getProject()).startupActivityPassed();
    } catch (Exception ignored) {
    }
    assertTrue("open: " + getProject().isOpen() + "; disposed:" + getProject().isDisposed() + "; startup passed:" + passed + "; all open projects: " + Arrays.asList(ProjectManager.getInstance().getOpenProjects()), getProject().isInitialized());
    CodeStyleSettingsManager.getInstance(getProject()).setTemporarySettings(new CodeStyleSettings());
    final FileDocumentManager manager = FileDocumentManager.getInstance();
    if (manager instanceof FileDocumentManagerImpl) {
        Document[] unsavedDocuments = manager.getUnsavedDocuments();
        manager.saveAllDocuments();
        ApplicationManager.getApplication().runWriteAction(((FileDocumentManagerImpl) manager)::dropAllUnsavedDocuments);
        assertEmpty("There are unsaved documents", Arrays.asList(unsavedDocuments));
    }
    // startup activities
    UIUtil.dispatchAllInvocationEvents();
    ((FileTypeManagerImpl) FileTypeManager.getInstance()).drainReDetectQueue();
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ModuleListener(com.intellij.openapi.project.ModuleListener) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) FileDocumentManagerImpl(com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl) Document(com.intellij.openapi.editor.Document) FileTypeManagerImpl(com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl) IncorrectOperationException(com.intellij.util.IncorrectOperationException) IOException(java.io.IOException) Project(com.intellij.openapi.project.Project) CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings) Module(com.intellij.openapi.module.Module) ProjectManagerEx(com.intellij.openapi.project.ex.ProjectManagerEx) UnindexedFilesUpdater(com.intellij.util.indexing.UnindexedFilesUpdater)

Example 20 with CodeStyleSettings

use of com.intellij.psi.codeStyle.CodeStyleSettings in project intellij-community by JetBrains.

the class AbstractRearrangerTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    CodeStyleSettingsManager.getInstance(myFixture.getProject()).setTemporarySettings(new CodeStyleSettings());
}
Also used : CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings) CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings)

Aggregations

CodeStyleSettings (com.intellij.psi.codeStyle.CodeStyleSettings)194 CommonCodeStyleSettings (com.intellij.psi.codeStyle.CommonCodeStyleSettings)85 Project (com.intellij.openapi.project.Project)13 XmlCodeStyleSettings (com.intellij.psi.formatter.xml.XmlCodeStyleSettings)12 Document (com.intellij.openapi.editor.Document)10 ECMA4CodeStyleSettings (com.intellij.lang.javascript.formatter.ECMA4CodeStyleSettings)9 JSCodeStyleSettings (com.intellij.lang.javascript.formatter.JSCodeStyleSettings)9 JavaCodeStyleSettings (com.intellij.psi.codeStyle.JavaCodeStyleSettings)9 NotNull (org.jetbrains.annotations.NotNull)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 PsiFile (com.intellij.psi.PsiFile)5 Nullable (org.jetbrains.annotations.Nullable)5 FormattingModel (com.intellij.formatting.FormattingModel)4 PsiElement (com.intellij.psi.PsiElement)4 CodeStyleSettingsManager (com.intellij.psi.codeStyle.CodeStyleSettingsManager)4 File (java.io.File)4 IOException (java.io.IOException)4 CodeStyleAbstractConfigurable (com.intellij.application.options.CodeStyleAbstractConfigurable)3 TabbedLanguageCodeStylePanel (com.intellij.application.options.TabbedLanguageCodeStylePanel)3 FormattingModelBuilder (com.intellij.formatting.FormattingModelBuilder)3