Search in sources :

Example 6 with CodeStyleSettingsManager

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

the class ExtractClassProcessor method calculateDelegateFieldName.

private String calculateDelegateFieldName() {
    final Project project = sourceClass.getProject();
    final CodeStyleSettingsManager settingsManager = CodeStyleSettingsManager.getInstance(project);
    final CodeStyleSettings settings = settingsManager.getCurrentSettings();
    final String baseName = settings.FIELD_NAME_PREFIX.length() == 0 ? StringUtil.decapitalize(newClassName) : newClassName;
    String name = settings.FIELD_NAME_PREFIX + baseName + settings.FIELD_NAME_SUFFIX;
    if (!existsFieldWithName(name) && !PsiNameHelper.getInstance(project).isKeyword(name)) {
        return name;
    }
    int counter = 1;
    while (true) {
        name = settings.FIELD_NAME_PREFIX + baseName + counter + settings.FIELD_NAME_SUFFIX;
        if (!existsFieldWithName(name) && !PsiNameHelper.getInstance(project).isKeyword(name)) {
            return name;
        }
        counter++;
    }
}
Also used : Project(com.intellij.openapi.project.Project) CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings) CodeStyleSettingsManager(com.intellij.psi.codeStyle.CodeStyleSettingsManager)

Example 7 with CodeStyleSettingsManager

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

the class AnnotationFormatterTest method setUp.

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

Example 8 with CodeStyleSettingsManager

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

the class HighlighterUtil method formatTooltip.

private static Object formatTooltip(Editor e, PsiElement element) {
    if (!(element instanceof XmlTag)) {
        final String text = element.getText();
        if ((text == null || text.length() == 0) && MyPsiUtil.isNameElement(element)) {
            final XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class, true);
            if (tag != null) {
                return tag.getName();
            }
        }
        return text;
    }
    // have to use html/preformatted or else the tooltip gets formatted totally weird.
    final CodeStyleSettingsManager instance = CodeStyleSettingsManager.getInstance(element.getProject());
    final int tabSize = instance.getCurrentSettings().getTabSize(FileTypeManager.getInstance().getFileTypeByExtension("xml"));
    final char[] spaces = new char[tabSize];
    for (int i = 0; i < spaces.length; i++) {
        spaces[i] = ' ';
    }
    final int textOffset = element.getTextOffset();
    final int lineStartOffset = e.logicalPositionToOffset(new LogicalPosition(e.offsetToLogicalPosition(textOffset).line, 0));
    final CharSequence chars = e.getDocument().getCharsSequence();
    int indent = 0;
    for (int i = lineStartOffset; i < textOffset; i++) {
        if (chars.charAt(i) == ' ') {
            indent++;
        } else if (chars.charAt(i) == '\t') {
            indent += ((indent + tabSize) / tabSize) * tabSize - indent;
        } else {
            break;
        }
    }
    final String text = element.getText().replaceAll("\\t", new String(spaces)).replaceAll("&", "&amp;").replaceAll("<", "&lt;");
    final Pattern indentPattern = Pattern.compile("^(\\s*).+");
    final StringBuilder sb = new StringBuilder("<html><pre>");
    final String[] lines = text.split("\\n");
    for (String line : lines) {
        final Matcher matcher = indentPattern.matcher(line);
        if (matcher.matches()) {
            // strip off the amount of spaces the top-level element is indented with
            line = line.substring(Math.min(matcher.group(1).length(), indent));
        }
        sb.append(line).append("\n");
    }
    return sb.append("</pre></html>").toString();
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) Pattern(java.util.regex.Pattern) CodeStyleSettingsManager(com.intellij.psi.codeStyle.CodeStyleSettingsManager) Matcher(java.util.regex.Matcher) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

CodeStyleSettingsManager (com.intellij.psi.codeStyle.CodeStyleSettingsManager)8 CodeStyleSettings (com.intellij.psi.codeStyle.CodeStyleSettings)4 AnAction (com.intellij.openapi.actionSystem.AnAction)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 LogicalPosition (com.intellij.openapi.editor.LogicalPosition)1 Project (com.intellij.openapi.project.Project)1 CodeStyleScheme (com.intellij.psi.codeStyle.CodeStyleScheme)1 CommonCodeStyleSettings (com.intellij.psi.codeStyle.CommonCodeStyleSettings)1 XmlTag (com.intellij.psi.xml.XmlTag)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1