本文整理汇总了Java中com.intellij.codeInsight.CodeInsightUtilCore类的典型用法代码示例。如果您正苦于以下问题:Java CodeInsightUtilCore类的具体用法?Java CodeInsightUtilCore怎么用?Java CodeInsightUtilCore使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CodeInsightUtilCore类属于com.intellij.codeInsight包,在下文中一共展示了CodeInsightUtilCore类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: surroundExpression
import com.intellij.codeInsight.CodeInsightUtilCore; //导入依赖的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}elseif(){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 = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(block.getStatements()[0]);
TextRange range = afterStatement.getTextRange();
editor.getDocument().deleteString(range.getStartOffset(), range.getEndOffset());
return new TextRange(range.getStartOffset(), range.getStartOffset());
}
开发者ID:cesards,项目名称:HakunaMatataIntelliJPlugin,代码行数:24,代码来源:JavaWithIfElseIfExpressionSurrounder.java
示例2: surroundExpression
import com.intellij.codeInsight.CodeInsightUtilCore; //导入依赖的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 = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(block.getStatements()[0]);
TextRange range = afterStatement.getTextRange();
editor.getDocument().deleteString(range.getStartOffset(), range.getEndOffset());
return new TextRange(range.getStartOffset(), range.getStartOffset());
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:JavaWithIfElseExpressionSurrounder.java
示例3: surroundExpression
import com.intellij.codeInsight.CodeInsightUtilCore; //导入依赖的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 = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(instanceofExpr);
TextRange range = instanceofExpr.getCheckType().getTextRange();
editor.getDocument().deleteString(range.getStartOffset(), range.getEndOffset());
return new TextRange(range.getStartOffset(), range.getStartOffset());
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:JavaWithNotInstanceofSurrounder.java
示例4: invoke
import com.intellij.codeInsight.CodeInsightUtilCore; //导入依赖的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);
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:GenerateSuperMethodCallHandler.java
示例5: invoke
import com.intellij.codeInsight.CodeInsightUtilCore; //导入依赖的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 = CodeInsightUtilCore.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());
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:AddVariableInitializerFix.java
示例6: beforeMove
import com.intellij.codeInsight.CodeInsightUtilCore; //导入依赖的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 = CodeInsightUtilCore.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;
}
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:DeclarationMover.java
示例7: showTemplateBuilder
import com.intellij.codeInsight.CodeInsightUtilCore; //导入依赖的package包/类
private static void showTemplateBuilder(PyFunction method, @NotNull final PsiFile file) {
method = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(method);
final TemplateBuilder builder = TemplateBuilderFactory.getInstance().createTemplateBuilder(method);
ParamHelper.walkDownParamArray(
method.getParameterList().getParameters(),
new ParamHelper.ParamVisitor() {
public void visitNamedParameter(PyNamedParameter param, boolean first, boolean last) {
builder.replaceElement(param, param.getName());
}
}
);
// TODO: detect expected return type from call site context: PY-1863
builder.replaceElement(method.getStatementList(), "return None");
final VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile == null) return;
final Editor editor = FileEditorManager.getInstance(file.getProject()).openTextEditor(
new OpenFileDescriptor(file.getProject(), virtualFile), true);
if (editor == null) return;
builder.run(editor, false);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:AddFunctionQuickFix.java
示例8: applyFix
import com.intellij.codeInsight.CodeInsightUtilCore; //导入依赖的package包/类
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
final PsiElement element = descriptor.getPsiElement();
final PyElementGenerator elementGenerator = PyElementGenerator.getInstance(project);
final PyNamedParameter parameter = elementGenerator.createParameter(element.getText() + "=None");
final PyFunction function = PsiTreeUtil.getParentOfType(element, PyFunction.class);
if (function != null) {
final PyParameterList parameterList = function.getParameterList();
parameterList.addParameter(parameter);
CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(parameterList);
final TemplateBuilder builder = TemplateBuilderFactory.getInstance().createTemplateBuilder(parameter);
builder.replaceRange(TextRange.create(parameter.getTextLength() - 4, parameter.getTextLength()), "None");
final VirtualFile virtualFile = function.getContainingFile().getVirtualFile();
if (virtualFile == null) return;
final Editor editor = FileEditorManager.getInstance(project).openTextEditor(new OpenFileDescriptor(project, virtualFile), true);
if (editor == null) return;
builder.run(editor, false);
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:UnresolvedReferenceAddParameterQuickFix.java
示例9: showTemplateBuilder
import com.intellij.codeInsight.CodeInsightUtilCore; //导入依赖的package包/类
private void showTemplateBuilder(PsiElement initStatement, @NotNull final PsiFile file) {
initStatement = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(initStatement);
if (initStatement instanceof PyAssignmentStatement) {
final TemplateBuilder builder = TemplateBuilderFactory.getInstance().createTemplateBuilder(initStatement);
final PyExpression assignedValue = ((PyAssignmentStatement)initStatement).getAssignedValue();
final PyExpression leftExpression = ((PyAssignmentStatement)initStatement).getLeftHandSideExpression();
if (assignedValue != null && leftExpression != null) {
if (replaceInitializer)
builder.replaceElement(assignedValue, myInitializer);
else
builder.replaceElement(leftExpression.getLastChild(), myIdentifier);
final VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile == null) return;
final Editor editor = FileEditorManager.getInstance(file.getProject()).openTextEditor(
new OpenFileDescriptor(file.getProject(), virtualFile), true);
if (editor == null) return;
builder.run(editor, false);
}
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:AddFieldQuickFix.java
示例10: showTemplateBuilder
import com.intellij.codeInsight.CodeInsightUtilCore; //导入依赖的package包/类
private static void showTemplateBuilder(@NotNull PyFunction method) {
method = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(method);
final PsiFile file = method.getContainingFile();
if (file == null) return;
final TemplateBuilder builder = TemplateBuilderFactory.getInstance().createTemplateBuilder(method);
ParamHelper.walkDownParamArray(
method.getParameterList().getParameters(),
new ParamHelper.ParamVisitor() {
public void visitNamedParameter(PyNamedParameter param, boolean first, boolean last) {
builder.replaceElement(param, param.getName());
}
}
);
final PyStatementList statementList = method.getStatementList();
builder.replaceElement(statementList, PyNames.PASS);
final VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile == null) return;
final Editor editor = FileEditorManager.getInstance(file.getProject()).openTextEditor(
new OpenFileDescriptor(file.getProject(), virtualFile), true);
if (editor == null) return;
builder.run(editor, false);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:AddMethodQuickFix.java
示例11: surroundStatement
import com.intellij.codeInsight.CodeInsightUtilCore; //导入依赖的package包/类
@Override
@Nullable
protected TextRange surroundStatement(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement[] elements)
throws IncorrectOperationException {
PyIfStatement ifStatement = PyElementGenerator.getInstance(project).createFromText(LanguageLevel.getDefault(), PyIfStatement.class, "if True:\n ");
final PsiElement parent = elements[0].getParent();
final PyStatementList statementList = ifStatement.getIfPart().getStatementList();
statementList.addRange(elements[0], elements[elements.length - 1]);
ifStatement = (PyIfStatement) parent.addBefore(ifStatement, elements[0]);
parent.deleteChildRange(elements[0], elements[elements.length - 1]);
ifStatement = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(ifStatement);
if (ifStatement == null) {
return null;
}
final PyExpression condition = ifStatement.getIfPart().getCondition();
return condition != null ? condition.getTextRange() : null;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:PyWithIfSurrounder.java
示例12: surroundStatement
import com.intellij.codeInsight.CodeInsightUtilCore; //导入依赖的package包/类
@Override
@Nullable
protected TextRange surroundStatement(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement[] elements)
throws IncorrectOperationException {
PyWhileStatement whileStatement =
PyElementGenerator.getInstance(project).createFromText(LanguageLevel.getDefault(), PyWhileStatement.class, "while True:\n \nelse:\n");
final PsiElement parent = elements[0].getParent();
whileStatement.addRange(elements[0], elements[elements.length - 1]);
whileStatement = (PyWhileStatement) parent.addBefore(whileStatement, elements[0]);
parent.deleteChildRange(elements[0], elements[elements.length - 1]);
whileStatement = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(whileStatement);
if (whileStatement == null) {
return null;
}
return whileStatement.getTextRange();
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:PyWithWhileElseSurrounder.java
示例13: surroundStatement
import com.intellij.codeInsight.CodeInsightUtilCore; //导入依赖的package包/类
@Override
@Nullable
protected TextRange surroundStatement(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement[] elements)
throws IncorrectOperationException {
PyIfStatement ifStatement =
PyElementGenerator.getInstance(project).createFromText(LanguageLevel.getDefault(), PyIfStatement.class, "if True:\n pass\nelse: pass\n");
final PsiElement parent = elements[0].getParent();
final PyStatementList statementList = ifStatement.getIfPart().getStatementList();
statementList.addRange(elements[0], elements[elements.length - 1]);
statementList.deleteChildRange(statementList.getFirstChild(), statementList.getFirstChild());
ifStatement = (PyIfStatement) parent.addBefore(ifStatement, elements[0]);
parent.deleteChildRange(elements[0], elements[elements.length - 1]);
ifStatement = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(ifStatement);
if (ifStatement == null) {
return null;
}
return ifStatement.getTextRange();
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:PyWithIfElseSurrounder.java
示例14: invokeInplaceRename
import com.intellij.codeInsight.CodeInsightUtilCore; //导入依赖的package包/类
private static void invokeInplaceRename(PsiNameIdentifierOwner nameIdentifierOwner, final String... suggestedNames) {
final PsiNameIdentifierOwner elementToRename = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(nameIdentifierOwner);
final Editor editor = FileEditorManager.getInstance(nameIdentifierOwner.getProject()).getSelectedTextEditor();
if (editor == null) {
return;
}
final PsiElement identifier = elementToRename.getNameIdentifier();
if (identifier == null) {
return;
}
editor.getCaretModel().moveToOffset(identifier.getTextOffset());
final RenamePsiElementProcessor processor = RenamePsiElementProcessor.forElement(elementToRename);
if (!processor.isInplaceRenameSupported()) {
return;
}
processor.substituteElementToRename(elementToRename, editor, new Pass<PsiElement>() {
@Override
public void pass(PsiElement substitutedElement) {
final MemberInplaceRenamer renamer = new MemberInplaceRenamer(elementToRename, substitutedElement, editor);
final LinkedHashSet<String> nameSuggestions = new LinkedHashSet<String>(Arrays.asList(suggestedNames));
renamer.performInplaceRefactoring(nameSuggestions);
}
});
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:NonThreadSafeLazyInitializationInspection.java
示例15: surroundExpression
import com.intellij.codeInsight.CodeInsightUtilCore; //导入依赖的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 = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(block);
TextRange range = block.getStatements()[0].getTextRange();
editor.getDocument().deleteString(range.getStartOffset(), range.getEndOffset());
return new TextRange(range.getStartOffset(), range.getStartOffset());
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:22,代码来源:JavaWithIfExpressionSurrounder.java
示例16: performRefactoring
import com.intellij.codeInsight.CodeInsightUtilCore; //导入依赖的package包/类
@Nullable
protected PsiElement performRefactoring(@NotNull CSharpIntroduceOperation operation)
{
PsiElement anchor = operation.isReplaceAll() ? findAnchor(operation.getOccurrences()) : findAnchor(operation.getInitializer());
if(anchor == null)
{
CommonRefactoringUtil.showErrorHint(operation.getProject(), operation.getEditor(), RefactoringBundle.getCannotRefactorMessage(null), RefactoringBundle.getCannotRefactorMessage(null),
null);
return null;
}
PsiElement declaration = createDeclaration(operation);
if(declaration == null)
{
showCannotPerformError(operation.getProject(), operation.getEditor());
return null;
}
declaration = performReplace(declaration, operation);
if(declaration != null)
{
declaration = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(declaration);
}
return declaration;
}
开发者ID:consulo,项目名称:consulo-csharp,代码行数:25,代码来源:CSharpIntroduceHandler.java
示例17: surroundStatements
import com.intellij.codeInsight.CodeInsightUtilCore; //导入依赖的package包/类
@Override
public TextRange surroundStatements(Project project, Editor editor, PsiElement container, PsiElement[] statements) throws IncorrectOperationException{
PsiManager manager = PsiManager.getInstance(project);
PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project);
statements = SurroundWithUtil.moveDeclarationsOut(container, statements, false);
if (statements.length == 0){
return null;
}
@NonNls String text = "synchronized(a){\n}";
PsiSynchronizedStatement synchronizedStatement = (PsiSynchronizedStatement)factory.createStatementFromText(text, null);
synchronizedStatement = (PsiSynchronizedStatement)codeStyleManager.reformat(synchronizedStatement);
synchronizedStatement = (PsiSynchronizedStatement)container.addAfter(synchronizedStatement, statements[statements.length - 1]);
PsiCodeBlock synchronizedBlock = synchronizedStatement.getBody();
if (synchronizedBlock == null) {
return null;
}
SurroundWithUtil.indentCommentIfNecessary(synchronizedBlock, statements);
synchronizedBlock.addRange(statements[0], statements[statements.length - 1]);
container.deleteChildRange(statements[0], statements[statements.length - 1]);
synchronizedStatement = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(synchronizedStatement);
PsiExpression lockExpression = synchronizedStatement.getLockExpression();
if (lockExpression == null) {
return null;
}
TextRange range = lockExpression.getTextRange();
editor.getDocument().deleteString(range.getStartOffset(), range.getEndOffset());
return new TextRange(range.getStartOffset(), range.getStartOffset());
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:35,代码来源:JavaWithSynchronizedSurrounder.java
示例18: surroundExpression
import com.intellij.codeInsight.CodeInsightUtilCore; //导入依赖的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);
PsiExpression condition = ifStatement.getCondition();
if (condition != null) {
condition.replace(expr);
}
PsiExpressionStatement statement = (PsiExpressionStatement)expr.getParent();
ifStatement = (PsiIfStatement)statement.replace(ifStatement);
PsiStatement thenBranch = ifStatement.getThenBranch();
if (thenBranch != null && thenBranch instanceof PsiBlockStatement) {
PsiCodeBlock block = ((PsiBlockStatement)thenBranch).getCodeBlock();
block = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(block);
TextRange range = block.getStatements()[0].getTextRange();
editor.getDocument().deleteString(range.getStartOffset(), range.getEndOffset());
return TextRange.from(range.getStartOffset(), 0);
}
return TextRange.from(editor.getCaretModel().getOffset(), 0);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:29,代码来源:JavaWithIfExpressionSurrounder.java
示例19: surroundStatements
import com.intellij.codeInsight.CodeInsightUtilCore; //导入依赖的package包/类
@Override
public TextRange surroundStatements(Project project, Editor editor, PsiElement container, PsiElement[] statements) throws IncorrectOperationException{
PsiManager manager = PsiManager.getInstance(project);
PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project);
statements = SurroundWithUtil.moveDeclarationsOut(container, statements, false);
if (statements.length == 0){
return null;
}
@NonNls String text = "if(a){\n}else{\n}";
PsiIfStatement ifStatement = (PsiIfStatement)factory.createStatementFromText(text, null);
ifStatement = (PsiIfStatement)codeStyleManager.reformat(ifStatement);
ifStatement = (PsiIfStatement)container.addAfter(ifStatement, statements[statements.length - 1]);
PsiStatement thenBranch = ifStatement.getThenBranch();
if (!(thenBranch instanceof PsiBlockStatement)) {
return null;
}
PsiCodeBlock thenBlock = ((PsiBlockStatement)thenBranch).getCodeBlock();
SurroundWithUtil.indentCommentIfNecessary(thenBlock, statements);
thenBlock.addRange(statements[0], statements[statements.length - 1]);
container.deleteChildRange(statements[0], statements[statements.length - 1]);
ifStatement = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(ifStatement);
PsiExpression condition = ifStatement.getCondition();
if (condition == null) {
return null;
}
TextRange range = condition.getTextRange();
editor.getDocument().deleteString(range.getStartOffset(), range.getEndOffset());
return new TextRange(range.getStartOffset(), range.getStartOffset());
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:35,代码来源:JavaWithIfElseSurrounder.java
示例20: surroundStatements
import com.intellij.codeInsight.CodeInsightUtilCore; //导入依赖的package包/类
@Override
public TextRange surroundStatements(Project project, Editor editor, PsiElement container, PsiElement[] statements) throws IncorrectOperationException{
PsiManager manager = PsiManager.getInstance(project);
PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project);
statements = SurroundWithUtil.moveDeclarationsOut(container, statements, true);
if (statements.length == 0){
return null;
}
@NonNls String text = "if(a){\n}";
PsiIfStatement ifStatement = (PsiIfStatement)factory.createStatementFromText(text, null);
ifStatement = (PsiIfStatement)codeStyleManager.reformat(ifStatement);
ifStatement = (PsiIfStatement)container.addAfter(ifStatement, statements[statements.length - 1]);
final PsiStatement thenBranch = ifStatement.getThenBranch();
if (thenBranch != null) {
PsiCodeBlock thenBlock = ((PsiBlockStatement)thenBranch).getCodeBlock();
SurroundWithUtil.indentCommentIfNecessary(thenBlock, statements);
thenBlock.addRange(statements[0], statements[statements.length - 1]);
container.deleteChildRange(statements[0], statements[statements.length - 1]);
}
ifStatement = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(ifStatement);
if (ifStatement == null) {
return null;
}
final PsiExpression condition = ifStatement.getCondition();
if (condition != null) {
TextRange range = condition.getTextRange();
TextRange textRange = new TextRange(range.getStartOffset(), range.getStartOffset());
editor.getDocument().deleteString(range.getStartOffset(), range.getEndOffset());
return textRange;
}
return ifStatement.getTextRange();
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:40,代码来源:JavaWithIfSurrounder.java
注:本文中的com.intellij.codeInsight.CodeInsightUtilCore类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论