本文整理汇总了Java中com.intellij.openapi.editor.ScrollType类的典型用法代码示例。如果您正苦于以下问题:Java ScrollType类的具体用法?Java ScrollType怎么用?Java ScrollType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ScrollType类属于com.intellij.openapi.editor包,在下文中一共展示了ScrollType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: genAnonymousBodyFor
import com.intellij.openapi.editor.ScrollType; //导入依赖的package包/类
public static Runnable genAnonymousBodyFor(PsiAnonymousClass parent,
final Editor editor,
final PsiFile file,
final Project project) {
try {
CodeStyleManager.getInstance(project).reformat(parent);
}
catch (IncorrectOperationException e) {
LOG.error(e);
}
int offset = parent.getTextRange().getEndOffset() - 1;
editor.getCaretModel().moveToOffset(offset);
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
editor.getSelectionModel().removeSelection();
final PsiReferenceParameterList parameterList = parent.getBaseClassReference().getParameterList();
final PsiTypeElement[] parameters = parameterList != null ? parameterList.getTypeParameterElements() : null;
if (shouldStartTypeTemplate(parameters)) {
startTemplate(parent, editor, createOverrideRunnable(editor, file, project), parameters);
return null;
}
return createOverrideRunnable(editor, file, project);
}
示例2: overrideOrImplement
import com.intellij.openapi.editor.ScrollType; //导入依赖的package包/类
public static List<PsiGenerationInfo<PsiMethod>> overrideOrImplement(PsiClass psiClass, @NotNull PsiMethod baseMethod) throws IncorrectOperationException {
FileEditorManager fileEditorManager = FileEditorManager.getInstance(baseMethod.getProject());
List<PsiGenerationInfo<PsiMethod>> results = new ArrayList<PsiGenerationInfo<PsiMethod>>();
try {
List<PsiGenerationInfo<PsiMethod>> prototypes = convert2GenerationInfos(overrideOrImplementMethod(psiClass, baseMethod, false));
if (prototypes.isEmpty()) return null;
PsiSubstitutor substitutor = TypeConversionUtil.getSuperClassSubstitutor(baseMethod.getContainingClass(), psiClass, PsiSubstitutor.EMPTY);
PsiElement anchor = getDefaultAnchorToOverrideOrImplement(psiClass, baseMethod, substitutor);
results = GenerateMembersUtil.insertMembersBeforeAnchor(psiClass, anchor, prototypes);
return results;
}
finally {
PsiFile psiFile = psiClass.getContainingFile();
Editor editor = fileEditorManager.openTextEditor(new OpenFileDescriptor(psiFile.getProject(), psiFile.getVirtualFile()), true);
if (editor != null && !results.isEmpty()) {
results.get(0).positionCaret(editor, true);
editor.getScrollingModel().scrollToCaret(ScrollType.CENTER);
}
}
}
示例3: invoke
import com.intellij.openapi.editor.ScrollType; //导入依赖的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);
}
}
示例4: invoke
import com.intellij.openapi.editor.ScrollType; //导入依赖的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());
}
示例5: doOrSplit
import com.intellij.openapi.editor.ScrollType; //导入依赖的package包/类
private static void doOrSplit(PsiIfStatement ifStatement, PsiPolyadicExpression expression, PsiJavaToken token, Editor editor) throws IncorrectOperationException {
PsiExpression lOperand = getLOperands(expression, token);
PsiExpression rOperand = getROperands(expression, token);
PsiIfStatement secondIf = (PsiIfStatement)ifStatement.copy();
PsiStatement elseBranch = ifStatement.getElseBranch();
if (elseBranch != null) { elseBranch = (PsiStatement)elseBranch.copy(); }
ifStatement.getCondition().replace(RefactoringUtil.unparenthesizeExpression(lOperand));
secondIf.getCondition().replace(RefactoringUtil.unparenthesizeExpression(rOperand));
ifStatement.setElseBranch(secondIf);
if (elseBranch != null) { secondIf.setElseBranch(elseBranch); }
int offset1 = ifStatement.getCondition().getTextOffset();
editor.getCaretModel().moveToOffset(offset1);
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
editor.getSelectionModel().removeSelection();
}
示例6: invoke
import com.intellij.openapi.editor.ScrollType; //导入依赖的package包/类
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
int offset = editor.getCaretModel().getOffset();
PsiElement element = file.findElementAt(offset);
while (true) {
if (element == null || element instanceof PsiFile) {
String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("error.wrong.caret.position.class"));
CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.EXTRACT_SUPERCLASS);
return;
}
if (element instanceof PsiClass) {
invoke(project, new PsiElement[]{element}, dataContext);
return;
}
element = element.getParent();
}
}
示例7: invoke
import com.intellij.openapi.editor.ScrollType; //导入依赖的package包/类
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
int offset = editor.getCaretModel().getOffset();
editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
PsiElement element = file.findElementAt(offset);
while (true) {
if (element == null || element instanceof PsiFile) {
String message = RefactoringBundle.getCannotRefactorMessage(
RefactoringBundle.message("the.caret.should.be.positioned.inside.a.class.to.push.members.from"));
CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.MEMBERS_PUSH_DOWN);
return;
}
if (element instanceof PsiClass || element instanceof PsiField || element instanceof PsiMethod) {
if (element instanceof JspClass) {
RefactoringMessageUtil.showNotSupportedForJspClassesError(project, editor, REFACTORING_NAME, HelpID.MEMBERS_PUSH_DOWN);
return;
}
invoke(project, new PsiElement[]{element}, dataContext);
return;
}
element = element.getParent();
}
}
示例8: invoke
import com.intellij.openapi.editor.ScrollType; //导入依赖的package包/类
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
if (element == null) {
element = file.findElementAt(editor.getCaretModel().getOffset());
}
if (element == null) return;
if (element instanceof PsiIdentifier) element = element.getParent();
if(!(element instanceof PsiMethod)) {
String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("error.wrong.caret.position.method"));
CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.CONVERT_TO_INSTANCE_METHOD);
return;
}
if(LOG.isDebugEnabled()) {
LOG.debug("MakeMethodStaticHandler invoked");
}
invoke(project, new PsiElement[]{element}, dataContext);
}
示例9: invoke
import com.intellij.openapi.editor.ScrollType; //导入依赖的package包/类
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
int offset = editor.getCaretModel().getOffset();
editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
PsiElement element = file.findElementAt(offset);
while (true) {
if (element == null || element instanceof PsiFile) {
String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("error.wrong.caret.position.class"));
CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.TURN_REFS_TO_SUPER);
return;
}
if (element instanceof PsiClass && !(element instanceof PsiAnonymousClass)) {
invoke(project, new PsiElement[]{element}, dataContext);
return;
}
element = element.getParent();
}
}
示例10: invoke
import com.intellij.openapi.editor.ScrollType; //导入依赖的package包/类
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
int offset = editor.getCaretModel().getOffset();
editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
PsiElement element = file.findElementAt(offset);
while (true) {
if (element == null || element instanceof PsiFile) {
String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("error.wrong.caret.position.class"));
CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.EXTRACT_INTERFACE);
return;
}
if (element instanceof PsiClass && !(element instanceof PsiAnonymousClass)) {
invoke(project, new PsiElement[]{element}, dataContext);
return;
}
element = element.getParent();
}
}
示例11: invoke
import com.intellij.openapi.editor.ScrollType; //导入依赖的package包/类
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
if (element == null) {
element = file.findElementAt(editor.getCaretModel().getOffset());
}
if (element == null) return;
if (element instanceof PsiIdentifier) element = element.getParent();
if (!(element instanceof PsiMethod)) {
String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("error.wrong.caret.position.method"));
CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.MOVE_INSTANCE_METHOD);
return;
}
if (LOG.isDebugEnabled()) {
LOG.debug("Move Instance Method invoked");
}
invoke(project, new PsiElement[]{element}, dataContext);
}
示例12: invoke
import com.intellij.openapi.editor.ScrollType; //导入依赖的package包/类
public void invoke(@NotNull final Project project, Editor editor, final PsiFile file, DataContext dataContext) {
if (!CommonRefactoringUtil.checkReadOnlyStatus(project, file)) return;
final int offset = editor.getCaretModel().getOffset();
editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
final PsiAnonymousClass anonymousClass = findAnonymousClass(file, offset);
if (anonymousClass == null) {
showErrorMessage(editor, RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("error.wrong.caret.position.anonymous")));
return;
}
final PsiElement parent = anonymousClass.getParent();
if (parent instanceof PsiEnumConstant) {
showErrorMessage(editor, RefactoringBundle.getCannotRefactorMessage("Enum constant can't be converted to inner class"));
return;
}
invoke(project, editor, anonymousClass);
}
示例13: invoke
import com.intellij.openapi.editor.ScrollType; //导入依赖的package包/类
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
if (element == null) {
element = file.findElementAt(editor.getCaretModel().getOffset());
}
if (element == null) return;
if (element instanceof PsiIdentifier) element = element.getParent();
if(!(element instanceof PsiTypeParameterListOwner)) {
String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("error.wrong.caret.position.method.or.class.name"));
CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.MAKE_METHOD_STATIC);
return;
}
if(LOG.isDebugEnabled()) {
LOG.debug("MakeStaticHandler invoked");
}
invoke(project, new PsiElement[]{element}, dataContext);
}
示例14: invoke
import com.intellij.openapi.editor.ScrollType; //导入依赖的package包/类
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
final int offset = TargetElementUtil.adjustOffset(file, editor.getDocument(), editor.getCaretModel().getOffset());
final PsiElement element = file.findElementAt(offset);
PsiTypeElement typeElement = PsiTreeUtil.getParentOfType(element, PsiTypeElement.class);
while (typeElement != null) {
final PsiElement parent = typeElement.getParent();
if (parent instanceof PsiVariable || (parent instanceof PsiMember && !(parent instanceof PsiClass)) || isClassArgument(parent)) {
invoke(project, parent, null, editor);
return;
}
typeElement = PsiTreeUtil.getParentOfType(parent, PsiTypeElement.class, false);
}
CommonRefactoringUtil.showErrorHint(project, editor,
"The caret should be positioned on type of field, variable, method or method parameter to be refactored",
REFACTORING_NAME, "refactoring.migrateType");
}
示例15: invoke
import com.intellij.openapi.editor.ScrollType; //导入依赖的package包/类
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
int offset = editor.getCaretModel().getOffset();
PsiElement element = file.findElementAt(offset);
while (true) {
if (element == null || element instanceof PsiFile) {
String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("error.wrong.caret.position.class"));
CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.INHERITANCE_TO_DELEGATION);
return;
}
if (element instanceof PsiClass && !(element instanceof PsiAnonymousClass)) {
invoke(project, new PsiElement[]{element}, dataContext);
return;
}
element = element.getParent();
}
}