Search in sources :

Example 6 with CodeStyleSettings

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

the class JavaFXQuickfixTest method doTestWithDefaultVisibility.

private void doTestWithDefaultVisibility(final String actionName, final String inputName, final String defaultVisibility, final String extension) throws Exception {
    CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
    String savedVisibility = settings.VISIBILITY;
    try {
        settings.VISIBILITY = defaultVisibility;
        doTest(actionName, inputName, getTestName(false), extension);
    } finally {
        settings.VISIBILITY = savedVisibility;
    }
}
Also used : CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings)

Example 7 with CodeStyleSettings

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

the class GroovyMethodSignatureInsertHandler method handleInsert.

@Override
public void handleInsert(InsertionContext context, LookupElement item) {
    if (!(item.getObject() instanceof PsiMethod)) {
        return;
    }
    PsiDocumentManager.getInstance(context.getProject()).commitDocument(context.getEditor().getDocument());
    final Editor editor = context.getEditor();
    final PsiMethod method = (PsiMethod) item.getObject();
    final PsiParameter[] parameters = method.getParameterList().getParameters();
    final StringBuilder buffer = new StringBuilder();
    final CharSequence chars = editor.getDocument().getCharsSequence();
    int endOffset = editor.getCaretModel().getOffset();
    final Project project = context.getProject();
    int afterSharp = CharArrayUtil.shiftBackwardUntil(chars, endOffset - 1, "#") + 1;
    int signatureOffset = afterSharp;
    PsiElement element = context.getFile().findElementAt(signatureOffset - 1);
    final CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(element.getProject());
    PsiDocTag tag = PsiTreeUtil.getParentOfType(element, PsiDocTag.class);
    if (context.getCompletionChar() == Lookup.REPLACE_SELECT_CHAR) {
        final PsiDocTagValue value = tag.getValueElement();
        endOffset = value.getTextRange().getEndOffset();
    }
    editor.getDocument().deleteString(afterSharp, endOffset);
    editor.getCaretModel().moveToOffset(signatureOffset);
    editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
    editor.getSelectionModel().removeSelection();
    buffer.append(method.getName()).append("(");
    final int afterParenth = afterSharp + buffer.length();
    for (int i = 0; i < parameters.length; i++) {
        final PsiType type = TypeConversionUtil.erasure(parameters[i].getType());
        buffer.append(type.getCanonicalText());
        if (i < parameters.length - 1) {
            buffer.append(",");
            if (styleSettings.SPACE_AFTER_COMMA)
                buffer.append(" ");
        }
    }
    buffer.append(")");
    if (!(tag instanceof PsiInlineDocTag)) {
        buffer.append(" ");
    } else {
        final int currentOffset = editor.getCaretModel().getOffset();
        if (chars.charAt(currentOffset) == '}') {
            afterSharp++;
        } else {
            buffer.append("} ");
        }
    }
    String insertString = buffer.toString();
    EditorModificationUtil.insertStringAtCaret(editor, insertString);
    editor.getCaretModel().moveToOffset(afterSharp + buffer.length());
    editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
    PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
    shortenReferences(project, editor, context, afterParenth);
}
Also used : PsiDocTag(com.intellij.psi.javadoc.PsiDocTag) PsiDocTagValue(com.intellij.psi.javadoc.PsiDocTagValue) Project(com.intellij.openapi.project.Project) CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings) PsiInlineDocTag(com.intellij.psi.javadoc.PsiInlineDocTag) Editor(com.intellij.openapi.editor.Editor)

Example 8 with CodeStyleSettings

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

the class JavaFxEventHandlerInspectionTest method testQuickfixNoFieldNested.

public void testQuickfixNoFieldNested() throws Exception {
    final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
    final boolean oldImports = settings.INSERT_INNER_CLASS_IMPORTS;
    try {
        settings.INSERT_INNER_CLASS_IMPORTS = true;
        doQuickfixTest("Create method 'void onColumnEditStart(CellEditEvent)'");
    } finally {
        settings.INSERT_INNER_CLASS_IMPORTS = oldImports;
    }
}
Also used : CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings)

Example 9 with CodeStyleSettings

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

the class PyWrapTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    final CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(myFixture.getProject()).getCurrentSettings();
    final CommonCodeStyleSettings pythonSettings = settings.getCommonSettings(PythonLanguage.getInstance());
    myOldWrap = settings.WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN;
    myOldMargin = pythonSettings.RIGHT_MARGIN;
    settings.WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN = true;
    pythonSettings.RIGHT_MARGIN = 80;
}
Also used : CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings) CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings) CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings)

Example 10 with CodeStyleSettings

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

the class PyWrapTest method tearDown.

@Override
protected void tearDown() throws Exception {
    final CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(myFixture.getProject()).getCurrentSettings();
    final CommonCodeStyleSettings pythonSettings = settings.getCommonSettings(PythonLanguage.getInstance());
    settings.WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN = myOldWrap;
    pythonSettings.RIGHT_MARGIN = myOldMargin;
    super.tearDown();
}
Also used : CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings) CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings) CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings)

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