本文整理汇总了Java中com.intellij.refactoring.util.CommonRefactoringUtil类的典型用法代码示例。如果您正苦于以下问题:Java CommonRefactoringUtil类的具体用法?Java CommonRefactoringUtil怎么用?Java CommonRefactoringUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CommonRefactoringUtil类属于com.intellij.refactoring.util包,在下文中一共展示了CommonRefactoringUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isWritable
import com.intellij.refactoring.util.CommonRefactoringUtil; //导入依赖的package包/类
private boolean isWritable() {
final Collection<PyMemberInfo<PyElement>> infos = myView.getSelectedMemberInfos();
if (infos.isEmpty()) {
return true;
}
final PyElement element = infos.iterator().next().getMember();
final Project project = element.getProject();
if (!CommonRefactoringUtil.checkReadOnlyStatus(project, myView.getSelectedParent())) return false;
final PyClass container = PyUtil.getContainingClassOrSelf(element);
if (container == null || !CommonRefactoringUtil.checkReadOnlyStatus(project, container)) return false;
for (final PyMemberInfo<PyElement> info : infos) {
final PyElement member = info.getMember();
if (!CommonRefactoringUtil.checkReadOnlyStatus(project, member)) return false;
}
return true;
}
示例2: doAction
import com.intellij.refactoring.util.CommonRefactoringUtil; //导入依赖的package包/类
protected void doAction() {
if (myTable.isEditing()) {
TableCellEditor editor = myTable.getCellEditor();
if (editor != null) {
editor.stopCellEditing();
}
}
String errorString = validateData();
if (errorString != null) { // were errors
CommonRefactoringUtil.showErrorMessage(REFACTORING_NAME, errorString, HelpID.ENCAPSULATE_FIELDS, myProject);
return;
}
if (getCheckedRows().length == 0) {
CommonRefactoringUtil.showErrorMessage(REFACTORING_NAME, "Nothing found to encapsulate", HelpID.ENCAPSULATE_FIELDS, myProject);
return;
}
invokeRefactoring(new EncapsulateFieldsProcessor(myProject, this));
JavaRefactoringSettings settings = JavaRefactoringSettings.getInstance();
settings.ENCAPSULATE_FIELDS_USE_ACCESSORS_WHEN_ACCESSIBLE = myCbUseAccessorsWhenAccessible.isSelected();
}
示例3: invoke
import com.intellij.refactoring.util.CommonRefactoringUtil; //导入依赖的package包/类
private void invoke(PsiClass aClass, Editor editor) {
String qualifiedName = aClass.getQualifiedName();
if(qualifiedName == null) {
showJspOrLocalClassMessage(editor);
return;
}
if (!checkAbstractClassOrInterfaceMessage(aClass, editor)) return;
final PsiMethod[] constructors = aClass.getConstructors();
if (constructors.length > 0) {
String message =
RefactoringBundle.message("class.does.not.have.implicit.default.constructor", aClass.getQualifiedName()) ;
CommonRefactoringUtil.showErrorHint(myProject, editor, message, REFACTORING_NAME, HelpID.REPLACE_CONSTRUCTOR_WITH_FACTORY);
return;
}
final int answer = Messages.showYesNoDialog(myProject,
RefactoringBundle.message("would.you.like.to.replace.default.constructor.of.0.with.factory.method", aClass.getQualifiedName()),
REFACTORING_NAME, Messages.getQuestionIcon()
);
if (answer != Messages.YES) return;
if (!CommonRefactoringUtil.checkReadOnlyStatus(myProject, aClass)) return;
new ReplaceConstructorWithFactoryDialog(myProject, null, aClass).show();
}
示例4: GroovyInplaceFieldValidator
import com.intellij.refactoring.util.CommonRefactoringUtil; //导入依赖的package包/类
public GroovyInplaceFieldValidator(GrIntroduceContext context) {
super(context, new ConflictReporter() {
@Override
public void check(PsiElement toCheck, MultiMap<PsiElement, String> conflicts, String varName) {
if (toCheck instanceof GrVariable && varName.equals(((GrVariable)toCheck).getName())) {
conflicts.putValue(toCheck, GroovyRefactoringBundle.message("field.0.is.already.defined", CommonRefactoringUtil.htmlEmphasize(varName)));
}
if (toCheck instanceof GrMethod) {
if (GroovyPropertyUtils.isSimplePropertyAccessor((PsiMethod)toCheck) &&
varName.equals(GroovyPropertyUtils.getPropertyNameByAccessorName(((PsiMethod)toCheck).getName()))) {
conflicts.putValue(toCheck, GroovyRefactoringBundle
.message("access.to.created.field.0.will.be.overriden.by.method.1", CommonRefactoringUtil.htmlEmphasize(varName),
CommonRefactoringUtil.htmlEmphasize(DescriptiveNameUtil.getDescriptiveName(toCheck))));
}
}
}
});
}
示例5: invoke
import com.intellij.refactoring.util.CommonRefactoringUtil; //导入依赖的package包/类
private void invoke(final Project project, PsiMethod method, Editor editor) {
if(method.isConstructor()){
CommonRefactoringUtil.showErrorHint(project, editor, RefactorJBundle.message("cannot.perform.the.refactoring") + RefactorJBundle.message("constructor.returns.can.not.be.wrapped"), null,
this.getHelpID());
return;
}
final PsiType returnType = method.getReturnType();
if(PsiType.VOID.equals(returnType)){
CommonRefactoringUtil.showErrorHint(project, editor, RefactorJBundle.message("cannot.perform.the.refactoring") + RefactorJBundle.message("method.selected.returns.void"), null, this.getHelpID());
return;
}
method = SuperMethodWarningUtil.checkSuperMethod(method, RefactoringBundle.message("to.refactor"));
if (method == null) return;
if(method instanceof PsiCompiledElement){
CommonRefactoringUtil.showErrorHint(project, editor, RefactorJBundle.message("cannot.perform.the.refactoring") + RefactorJBundle.message(
"the.selected.method.cannot.be.wrapped.because.it.is.defined.in.a.non.project.class"), null, this.getHelpID());
return;
}
new WrapReturnValueDialog(method).show();
}
示例6: invoke
import com.intellij.refactoring.util.CommonRefactoringUtil; //导入依赖的package包/类
@Override
public void invoke(@NotNull final Project project, Editor editor, PsiFile file, DataContext dataContext) {
editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
if (element == null) {
element = BaseRefactoringAction.getElementAtCaret(editor, file);
}
if (element != null) {
for(InlineActionHandler handler: Extensions.getExtensions(InlineActionHandler.EP_NAME)) {
if (handler.canInlineElementInEditor(element, editor)) {
handler.inlineElement(project, editor, element);
return;
}
}
if (invokeInliner(editor, element)) return;
String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("error.wrong.caret.position.method.or.local.name"));
CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, null);
}
}
示例7: invoke
import com.intellij.refactoring.util.CommonRefactoringUtil; //导入依赖的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: GroovyVariableValidator
import com.intellij.refactoring.util.CommonRefactoringUtil; //导入依赖的package包/类
public GroovyVariableValidator(GrIntroduceContext context) {
super(context, new ConflictReporter() {
@Override
public void check(PsiElement element, MultiMap<PsiElement, String> conflicts, String varName) {
if (!(element instanceof GrVariable)) return;
final GrVariable var = (GrVariable)element;
if (var instanceof GrField) return;
if (var instanceof GrParameter && varName.equals(var.getName())) {
conflicts.putValue(var, GroovyRefactoringBundle
.message("introduced.variable.conflicts.with.parameter.0", CommonRefactoringUtil.htmlEmphasize(varName)));
}
else if (varName.equals(var.getName())) {
conflicts.putValue(var, GroovyRefactoringBundle
.message("introduced.variable.conflicts.with.variable.0", CommonRefactoringUtil.htmlEmphasize(varName)));
}
}
});
}
示例9: invoke
import com.intellij.refactoring.util.CommonRefactoringUtil; //导入依赖的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: doAction
import com.intellij.refactoring.util.CommonRefactoringUtil; //导入依赖的package包/类
protected void doAction() {
TableUtil.stopEditing(myTable);
final String className;
final String packageName;
if (myCreateBuilderClassRadioButton.isSelected()) {
className = myNewClassName.getText().trim();
packageName = myPackageTextField.getText().trim();
} else {
final String fqName = myExistentClassTF.getText().trim();
className = StringUtil.getShortName(fqName);
packageName = StringUtil.getPackageName(fqName);
final PsiClass builderClass = JavaPsiFacade.getInstance(myProject).findClass(StringUtil.getQualifiedName(packageName, className), GlobalSearchScope.projectScope(myProject));
if (builderClass != null && !CommonRefactoringUtil.checkReadOnlyStatus(myProject, builderClass)) return;
}
invokeRefactoring(new ReplaceConstructorWithBuilderProcessor(getProject(), myConstructors, myParametersMap, className, packageName,
((DestinationFolderComboBox)myDestinationCb).selectDirectory(new PackageWrapper(myConstructors[0].getManager(), packageName), false),
myCreateBuilderClassRadioButton.isSelected()));
}
示例11: invoke
import com.intellij.refactoring.util.CommonRefactoringUtil; //导入依赖的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();
}
}
示例12: invoke
import com.intellij.refactoring.util.CommonRefactoringUtil; //导入依赖的package包/类
private static void invoke(final PsiField field, Editor editor) {
final Project project = field.getProject();
final Set<PsiMethod> delegating = DelegationUtils.getDelegatingMethodsForField(field);
if (delegating.isEmpty()) {
final String message =
RefactorJBundle.message("cannot.perform.the.refactoring") + RefactorJBundle.message("field.selected.is.not.used.as.a.delegate");
CommonRefactoringUtil.showErrorHint(project, editor, message, null, getHelpID());
return;
}
MemberInfo[] infos = new MemberInfo[delegating.size()];
int i = 0;
for (PsiMethod method : delegating) {
final MemberInfo memberInfo = new MemberInfo(method);
memberInfo.setChecked(true);
memberInfo.setToAbstract(method.findDeepestSuperMethods().length == 0);
infos[i++] = memberInfo;
}
new RemoveMiddlemanDialog(field, infos).show();
}
示例13: invoke
import com.intellij.refactoring.util.CommonRefactoringUtil; //导入依赖的package包/类
@Override
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.pull.members.from"));
CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.MEMBERS_PULL_UP);
return;
}
if (!CommonRefactoringUtil.checkReadOnlyStatus(project, element)) return;
if (element instanceof GrTypeDefinition || element instanceof GrField || element instanceof GrMethod) {
invoke(project, new PsiElement[]{element}, dataContext);
return;
}
element = element.getParent();
}
}
示例14: invoke
import com.intellij.refactoring.util.CommonRefactoringUtil; //导入依赖的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);
}
示例15: invoke
import com.intellij.refactoring.util.CommonRefactoringUtil; //导入依赖的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);
}