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++;
}
}
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());
}
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("&", "&").replaceAll("<", "<");
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();
}
Aggregations