本文整理汇总了Java中com.intellij.psi.PsiModifierList.getTextOffset方法的典型用法代码示例。如果您正苦于以下问题:Java PsiModifierList.getTextOffset方法的具体用法?Java PsiModifierList.getTextOffset怎么用?Java PsiModifierList.getTextOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.PsiModifierList
的用法示例。
在下文中一共展示了PsiModifierList.getTextOffset方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: perform
import com.intellij.psi.PsiModifierList; //导入方法依赖的package包/类
/**
* to be performed in write action
*/
public void perform(final PsiVariable variable) {
ApplicationManager.getApplication().assertWriteAccessAllowed();
final Document document = myEditor.getDocument();
LOG.assertTrue(variable != null);
final PsiModifierList modifierList = variable.getModifierList();
LOG.assertTrue(modifierList != null);
int textOffset = modifierList.getTextOffset();
final String modifierListText = modifierList.getText();
int length = PsiModifier.PUBLIC.length();
int idx = modifierListText.indexOf(PsiModifier.PUBLIC);
if (idx == -1) {
idx = modifierListText.indexOf(PsiModifier.PROTECTED);
length = PsiModifier.PROTECTED.length();
}
if (idx == -1) {
idx = modifierListText.indexOf(PsiModifier.PRIVATE);
length = PsiModifier.PRIVATE.length();
}
String visibility = getVisibility();
if (visibility == PsiModifier.PACKAGE_LOCAL) {
visibility = "";
}
final boolean wasPackageLocal = idx == -1;
final boolean isPackageLocal = visibility.isEmpty();
final int startOffset = textOffset + (wasPackageLocal ? 0 : idx);
final int endOffset;
if (wasPackageLocal) {
endOffset = startOffset;
}
else {
endOffset = textOffset + length + (isPackageLocal ? 1 : 0);
}
final String finalVisibility = visibility + (wasPackageLocal ? " " : "");
Runnable runnable = new Runnable() {
@Override
public void run() {
document.replaceString(startOffset, endOffset, finalVisibility);
}
};
final LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(myEditor);
if (lookup != null) {
lookup.performGuardedChange(runnable);
} else {
runnable.run();
}
}