本文整理汇总了Java中com.intellij.codeInsight.CodeInsightUtilBase类的典型用法代码示例。如果您正苦于以下问题:Java CodeInsightUtilBase类的具体用法?Java CodeInsightUtilBase怎么用?Java CodeInsightUtilBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CodeInsightUtilBase类属于com.intellij.codeInsight包,在下文中一共展示了CodeInsightUtilBase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: invoke
import com.intellij.codeInsight.CodeInsightUtilBase; //导入依赖的package包/类
@Override
public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return;
PsiMethod method = canInsertSuper(project, editor, file);
try {
PsiMethod template = (PsiMethod)method.copy();
OverrideImplementUtil.setupMethodBody(template, method, method.getContainingClass());
PsiStatement superCall = template.getBody().getStatements()[0];
PsiCodeBlock body = method.getBody();
PsiElement toGo;
if (body.getLBrace() == null) {
toGo = body.addBefore(superCall, null);
}
else {
toGo = body.addAfter(superCall, body.getLBrace());
}
toGo = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(toGo);
editor.getCaretModel().moveToOffset(toGo.getTextOffset());
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
}
catch (IncorrectOperationException e) {
LOG.error(e);
}
}
示例2: invoke
import com.intellij.codeInsight.CodeInsightUtilBase; //导入依赖的package包/类
@Override
public final void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull PsiFile file) {
if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return;
if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)) {
return;
}
final PsiClass aClass = OverrideImplementUtil.getContextClass(project, editor, file, false);
if (aClass == null || aClass.isInterface()) return; //?
LOG.assertTrue(aClass.isValid());
LOG.assertTrue(aClass.getContainingFile() != null);
try {
final ClassMember[] members = chooseOriginalMembers(aClass, project, editor);
if (members == null) return;
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
doGenerate(project, editor, aClass, members);
}
});
}
finally {
cleanup();
}
}
示例3: invoke
import com.intellij.codeInsight.CodeInsightUtilBase; //导入依赖的package包/类
@Override
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException
{
if(!CodeInsightUtilBase.getInstance().prepareFileForWrite(file))
{
return;
}
final ASTNode fromText = JSChangeUtil.createJSTreeFromText(project, "override class A {}");
final JSAttributeList jsAttributeList = myNode.getAttributeList();
final JSAttributeList createdAttrList = ((JSClass) fromText.getPsi()).getAttributeList();
if(jsAttributeList != null)
{
jsAttributeList.add(createdAttrList.getFirstChild());
}
else
{
myNode.addBefore(createdAttrList, myNode.getFirstChild());
}
}
示例4: surroundExpression
import com.intellij.codeInsight.CodeInsightUtilBase; //导入依赖的package包/类
@Override
public TextRange surroundExpression(Project project, Editor editor, PsiExpression expr) throws IncorrectOperationException {
PsiManager manager = expr.getManager();
PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project);
@NonNls String text = "if(a){\nst;\n}";
PsiIfStatement ifStatement = (PsiIfStatement)factory.createStatementFromText(text, null);
ifStatement = (PsiIfStatement)codeStyleManager.reformat(ifStatement);
ifStatement.getCondition().replace(expr);
PsiExpressionStatement statement = (PsiExpressionStatement)expr.getParent();
ifStatement = (PsiIfStatement)statement.replace(ifStatement);
PsiCodeBlock block = ((PsiBlockStatement)ifStatement.getThenBranch()).getCodeBlock();
block = CodeInsightUtilBase.forcePsiPostprocessAndRestoreElement(block);
TextRange range = block.getStatements()[0].getTextRange();
editor.getDocument().deleteString(range.getStartOffset(), range.getEndOffset());
return new TextRange(range.getStartOffset(), range.getStartOffset());
}
示例5: surroundExpression
import com.intellij.codeInsight.CodeInsightUtilBase; //导入依赖的package包/类
@Override
public TextRange surroundExpression(Project project, Editor editor, PsiExpression expr) throws IncorrectOperationException {
PsiManager manager = expr.getManager();
PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project);
@NonNls String text = "if(a){\nst;\n}else{\n}";
PsiIfStatement ifStatement = (PsiIfStatement)factory.createStatementFromText(text, null);
ifStatement = (PsiIfStatement)codeStyleManager.reformat(ifStatement);
ifStatement.getCondition().replace(expr);
PsiExpressionStatement statement = (PsiExpressionStatement)expr.getParent();
ifStatement = (PsiIfStatement)statement.replace(ifStatement);
PsiCodeBlock block = ((PsiBlockStatement)ifStatement.getThenBranch()).getCodeBlock();
PsiStatement afterStatement = CodeInsightUtilBase.forcePsiPostprocessAndRestoreElement(block.getStatements()[0]);
TextRange range = afterStatement.getTextRange();
editor.getDocument().deleteString(range.getStartOffset(), range.getEndOffset());
return new TextRange(range.getStartOffset(), range.getStartOffset());
}
示例6: surroundExpression
import com.intellij.codeInsight.CodeInsightUtilBase; //导入依赖的package包/类
@Override
public TextRange surroundExpression(Project project, Editor editor, PsiExpression expr) throws IncorrectOperationException {
PsiManager manager = expr.getManager();
PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project);
PsiPrefixExpression prefixExpr = (PsiPrefixExpression)factory.createExpressionFromText("!(a instanceof Type)", null);
prefixExpr = (PsiPrefixExpression)codeStyleManager.reformat(prefixExpr);
PsiParenthesizedExpression parenthExpr = (PsiParenthesizedExpression)prefixExpr.getOperand();
PsiInstanceOfExpression instanceofExpr = (PsiInstanceOfExpression)parenthExpr.getExpression();
instanceofExpr.getOperand().replace(expr);
prefixExpr = (PsiPrefixExpression)expr.replace(prefixExpr);
parenthExpr = (PsiParenthesizedExpression)prefixExpr.getOperand();
instanceofExpr = (PsiInstanceOfExpression)parenthExpr.getExpression();
instanceofExpr = CodeInsightUtilBase.forcePsiPostprocessAndRestoreElement(instanceofExpr);
TextRange range = instanceofExpr.getCheckType().getTextRange();
editor.getDocument().deleteString(range.getStartOffset(), range.getEndOffset());
return new TextRange(range.getStartOffset(), range.getStartOffset());
}
示例7: invoke
import com.intellij.codeInsight.CodeInsightUtilBase; //导入依赖的package包/类
@Override
public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return;
PsiMethod method = canInsertSuper(project, editor, file);
try {
PsiMethod template = (PsiMethod)method.copy();
OverrideImplementUtil.setupMethodBody(template, method, method.getContainingClass());
PsiStatement superCall = template.getBody().getStatements()[0];
PsiCodeBlock body = method.getBody();
PsiElement toGo;
if (body.getLBrace() == null) {
toGo = body.addBefore(superCall, null);
}
else {
toGo = body.addAfter(superCall, body.getLBrace());
}
toGo = CodeInsightUtilBase.forcePsiPostprocessAndRestoreElement(toGo);
editor.getCaretModel().moveToOffset(toGo.getTextOffset());
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
}
catch (IncorrectOperationException e) {
LOG.error(e);
}
}
示例8: invoke
import com.intellij.codeInsight.CodeInsightUtilBase; //导入依赖的package包/类
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
if (!FileModificationService.getInstance().prepareFileForWrite(myVariable.getContainingFile())) return;
String initializerText = suggestInitializer();
PsiElementFactory factory = JavaPsiFacade.getInstance(myVariable.getProject()).getElementFactory();
PsiExpression initializer = factory.createExpressionFromText(initializerText, myVariable);
if (myVariable instanceof PsiLocalVariable) {
((PsiLocalVariable)myVariable).setInitializer(initializer);
}
else if (myVariable instanceof PsiField) {
((PsiField)myVariable).setInitializer(initializer);
}
else {
LOG.error("Unknown variable type: "+myVariable);
}
PsiVariable var = CodeInsightUtilBase.forcePsiPostprocessAndRestoreElement(myVariable);
TextRange range = var.getInitializer().getTextRange();
int offset = range.getStartOffset();
editor.getCaretModel().moveToOffset(offset);
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
editor.getSelectionModel().setSelection(range.getStartOffset(), range.getEndOffset());
}
示例9: beforeMove
import com.intellij.codeInsight.CodeInsightUtilBase; //导入依赖的package包/类
@Override
public void beforeMove(@NotNull final Editor editor, @NotNull final MoveInfo info, final boolean down) {
super.beforeMove(editor, info, down);
if (myEnumToInsertSemicolonAfter != null) {
TreeElement semicolon = Factory.createSingleLeafElement(JavaTokenType.SEMICOLON, ";", 0, 1, null, myEnumToInsertSemicolonAfter.getManager());
try {
PsiElement inserted = myEnumToInsertSemicolonAfter.getParent().addAfter(semicolon.getPsi(), myEnumToInsertSemicolonAfter);
inserted = CodeInsightUtilBase.forcePsiPostprocessAndRestoreElement(inserted);
final LogicalPosition position = editor.offsetToLogicalPosition(inserted.getTextRange().getEndOffset());
info.toMove2 = new LineRange(position.line + 1, position.line + 1);
}
catch (IncorrectOperationException e) {
LOG.error(e);
}
finally {
myEnumToInsertSemicolonAfter = null;
}
}
}
示例10: invoke
import com.intellij.codeInsight.CodeInsightUtilBase; //导入依赖的package包/类
public static void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file, Surrounder surrounder) {
if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return;
if (file instanceof PsiCompiledElement) {
HintManager.getInstance().showErrorHint(editor, "Can't modify decompiled code");
return;
}
List<AnAction> applicable = buildSurroundActions(project, editor, file, surrounder);
if (applicable != null) {
showPopup(editor, applicable);
}
else if (!ApplicationManager.getApplication().isUnitTestMode()) {
HintManager.getInstance().showErrorHint(editor, "Couldn't find Surround With variants applicable to the current context");
}
}
示例11: invoke
import com.intellij.codeInsight.CodeInsightUtilBase; //导入依赖的package包/类
@Override
public final void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull PsiFile file) {
if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return;
if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)){
return;
}
Language language = PsiUtilCore.getLanguageAtOffset(file, editor.getCaretModel().getOffset());
final LanguageCodeInsightActionHandler codeInsightActionHandler = CodeInsightActions.IMPLEMENT_METHOD.forLanguage(language);
if (codeInsightActionHandler != null) {
codeInsightActionHandler.invoke(project, editor, file);
}
}
示例12: invoke
import com.intellij.codeInsight.CodeInsightUtilBase; //导入依赖的package包/类
@Override
public final void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull PsiFile file) {
if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return;
if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)){
return;
}
Language language = PsiUtilCore.getLanguageAtOffset(file, editor.getCaretModel().getOffset());
final LanguageCodeInsightActionHandler codeInsightActionHandler = CodeInsightActions.DELEGATE_METHODS.forLanguage(language);
if (codeInsightActionHandler != null) {
codeInsightActionHandler.invoke(project, editor, file);
}
}
示例13: invoke
import com.intellij.codeInsight.CodeInsightUtilBase; //导入依赖的package包/类
@Override
public final void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull PsiFile file) {
if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return;
if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)){
return;
}
Language language = PsiUtilCore.getLanguageAtOffset(file, editor.getCaretModel().getOffset());
final LanguageCodeInsightActionHandler codeInsightActionHandler = CodeInsightActions.OVERRIDE_METHOD.forLanguage(language);
if (codeInsightActionHandler != null) {
codeInsightActionHandler.invoke(project, editor, file);
}
}
示例14: invoke
import com.intellij.codeInsight.CodeInsightUtilBase; //导入依赖的package包/类
@Override
public void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull final PsiFile file) {
if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return;
PsiDocumentManager.getInstance(project).commitAllDocuments();
if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)) {
return;
}
EmacsProcessingHandler emacsProcessingHandler = LanguageEmacsExtension.INSTANCE.forLanguage(file.getLanguage());
if (emacsProcessingHandler != null) {
EmacsProcessingHandler.Result result = emacsProcessingHandler.changeIndent(project, editor, file);
if (result == EmacsProcessingHandler.Result.STOP) {
return;
}
}
final Document document = editor.getDocument();
final int startOffset = editor.getCaretModel().getOffset();
final int line = editor.offsetToLogicalPosition(startOffset).line;
final int lineStart = document.getLineStartOffset(line);
try{
final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project);
final int newPos = codeStyleManager.adjustLineIndent(file, lineStart);
if (editor.getCaretModel().getOffset() < newPos) {
editor.getCaretModel().moveToOffset(newPos);
editor.getSelectionModel().removeSelection();
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
}
}
catch(IncorrectOperationException e){
LOG.error(e);
}
}
示例15: invoke
import com.intellij.codeInsight.CodeInsightUtilBase; //导入依赖的package包/类
@Override
public void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull PsiFile file) {
if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return;
if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)) {
return;
}
EditorUtil.fillVirtualSpaceUntilCaret(editor);
PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
int offset = editor.getCaretModel().getOffset();
List<TemplateImpl> applicableTemplates = TemplateManagerImpl.listApplicableTemplateWithInsertingDummyIdentifier(editor, file, false);
Map<TemplateImpl, String> matchingTemplates = filterTemplatesByPrefix(applicableTemplates, editor, offset, false, true);
MultiMap<String, CustomLiveTemplateLookupElement> customTemplatesLookupElements = getCustomTemplatesLookupItems(editor, file, offset);
if (matchingTemplates.isEmpty()) {
for (TemplateImpl template : applicableTemplates) {
matchingTemplates.put(template, null);
}
}
if (matchingTemplates.isEmpty() && customTemplatesLookupElements.isEmpty()) {
HintManager.getInstance().showErrorHint(editor, CodeInsightBundle.message("templates.no.defined"));
return;
}
showTemplatesLookup(project, editor, file, matchingTemplates, customTemplatesLookupElements);
}