本文整理汇总了Java中com.intellij.refactoring.rename.inplace.VariableInplaceRenamer类的典型用法代码示例。如果您正苦于以下问题:Java VariableInplaceRenamer类的具体用法?Java VariableInplaceRenamer怎么用?Java VariableInplaceRenamer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
VariableInplaceRenamer类属于com.intellij.refactoring.rename.inplace包,在下文中一共展示了VariableInplaceRenamer类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createRenamer
import com.intellij.refactoring.rename.inplace.VariableInplaceRenamer; //导入依赖的package包/类
@Override
protected VariableInplaceRenamer createRenamer(@NotNull PsiElement elementToRename, Editor editor) {
PossiblePrefixReference reference = getReference(elementToRename.getContainingFile(), editor);
if (reference != null) {
PsiElement prefix = reference.resolve();
if (prefix instanceof SchemaPrefix) {
return new VariableInplaceRenamer((PsiNamedElement)prefix, editor) {
@Override
protected void addReferenceAtCaret(Collection<PsiReference> refs) {}
@Override
protected boolean isReferenceAtCaret(PsiElement selectedElement, PsiReference ref) {
return false;
}
};
}
}
return null;
}
示例2: createRenamer
import com.intellij.refactoring.rename.inplace.VariableInplaceRenamer; //导入依赖的package包/类
@Override
protected VariableInplaceRenamer createRenamer(@NotNull PsiElement elementToRename, Editor editor) {
PossiblePrefixReference reference = getReference(elementToRename.getContainingFile(), editor);
if (reference != null) {
PsiElement prefix = reference.resolve();
if (prefix instanceof SchemaPrefix) {
return new VariableInplaceRenamer((PsiNamedElement)prefix, editor) {
@Override
protected void addReferenceAtCaret(Collection<PsiReference> refs) {}
@Override
protected boolean isReferenceAtCaret(PsiElement selectedElement, PsiReference ref) {
return false;
}
};
}
}
if (ApplicationManager.getApplication().isUnitTestMode()) {
System.out.println("Reference: " + reference);
if (reference != null) {
System.out.println("Resolved: " + reference.resolve());
}
}
return null;
}
示例3: applyFix
import com.intellij.refactoring.rename.inplace.VariableInplaceRenamer; //导入依赖的package包/类
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
PsiElement element = descriptor.getPsiElement();
if (element instanceof PyReferenceExpression) {
final PsiReference reference = element.getReference();
if (reference == null) return;
element = reference.resolve();
}
final PsiNameIdentifierOwner nameOwner = element instanceof PsiNameIdentifierOwner ?
(PsiNameIdentifierOwner)element :
PsiTreeUtil.getParentOfType(element, PsiNameIdentifierOwner.class, true);
if (nameOwner != null) {
final VirtualFile virtualFile = nameOwner.getContainingFile().getVirtualFile();
if (virtualFile != null) {
final Editor editor = FileEditorManager.getInstance(project).openTextEditor(new OpenFileDescriptor(project, virtualFile), true);
if (ApplicationManager.getApplication().isUnitTestMode()) {
renameInUnitTestMode(project, nameOwner, editor);
}
else {
if (checkLocalScope(element) != null && (nameOwner instanceof PyNamedParameter || nameOwner instanceof PyTargetExpression)) {
new VariableInplaceRenamer(nameOwner, editor).performInplaceRename();
}
else {
PsiElementRenameHandler.invoke(nameOwner, project, ScopeUtil.getScopeOwner(nameOwner), editor);
}
}
}
}
}
示例4: surroundStatements
import com.intellij.refactoring.rename.inplace.VariableInplaceRenamer; //导入依赖的package包/类
@Override
public TextRange surroundStatements(Project project, final Editor editor, PsiElement container, PsiElement[] statements) throws IncorrectOperationException{
PsiManager manager = container.getManager();
PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project);
final String baseName = "runnable";
final String uniqueName = JavaCodeStyleManager.getInstance(project).suggestUniqueVariableName(baseName, container, false);
@NonNls String text = "Runnable runnable = new Runnable(){\npublic void run(){\n}};";
PsiDeclarationStatement declarationStatement = (PsiDeclarationStatement)factory.createStatementFromText(text, null);
declarationStatement = (PsiDeclarationStatement)codeStyleManager.reformat(declarationStatement);
declarationStatement = (PsiDeclarationStatement)container.addAfter(declarationStatement, statements[statements.length - 1]);
final PsiVariable variable = (PsiVariable)declarationStatement.getDeclaredElements()[0];
if (!Comparing.strEqual(uniqueName, baseName)) {
variable.setName(uniqueName);
}
PsiNewExpression newExpression = (PsiNewExpression)variable.getInitializer();
PsiElement[] children = newExpression.getChildren();
PsiAnonymousClass anonymousClass = (PsiAnonymousClass)children[children.length - 1];
PsiMethod method = anonymousClass.getMethods()[0];
PsiCodeBlock body = method.getBody();
body.addRange(statements[0], statements[statements.length - 1]);
container.deleteChildRange(statements[0], statements[statements.length - 1]);
makeVariablesFinal(body, body);
final int textOffset = variable.getNameIdentifier().getTextOffset();
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument());
editor.getCaretModel().moveToOffset(textOffset);
editor.getSelectionModel().removeSelection();
new VariableInplaceRenamer(variable, editor){
@Override
protected boolean shouldSelectAll() {
return true;
}
@Override
protected void moveOffsetAfter(boolean success) {
super.moveOffsetAfter(success);
if (success) {
final PsiNamedElement renamedVariable = getVariable();
if (renamedVariable != null) {
editor.getCaretModel().moveToOffset(renamedVariable.getTextRange().getEndOffset());
}
}
}
}.performInplaceRename();
return null;
}
示例5: onRenameTemplateStarted
import com.intellij.refactoring.rename.inplace.VariableInplaceRenamer; //导入依赖的package包/类
@Override
protected void onRenameTemplateStarted() {
final ResolveSnapshotProvider resolveSnapshotProvider = VariableInplaceRenamer.INSTANCE.forLanguage(myScope.getLanguage());
myConflictResolver = resolveSnapshotProvider != null ? resolveSnapshotProvider.createSnapshot(myScope) : null;
}
示例6: processIntention
import com.intellij.refactoring.rename.inplace.VariableInplaceRenamer; //导入依赖的package包/类
@Override
protected void processIntention(@NotNull PsiElement element, Project project, Editor editor) throws IncorrectOperationException {
final GrMethodCallExpression expression = (GrMethodCallExpression)element;
final GrClosableBlock block = expression.getClosureArguments()[0];
final GrParameterList parameterList = block.getParameterList();
final GrParameter[] parameters = parameterList.getParameters();
String var;
if (parameters.length == 1) {
var = parameters[0].getText();
var = StringUtil.replace(var, GrModifier.DEF, "");
}
else {
var = "it";
}
final GrExpression invokedExpression = expression.getInvokedExpression();
GrExpression qualifier = ((GrReferenceExpression)invokedExpression).getQualifierExpression();
final GroovyPsiElementFactory elementFactory = GroovyPsiElementFactory.getInstance(element.getProject());
if (qualifier == null) {
qualifier = elementFactory.createExpressionFromText("this");
}
StringBuilder builder = new StringBuilder();
builder.append("for (").append(var).append(" in ").append(qualifier.getText()).append(") {\n");
String text = block.getText();
final PsiElement blockArrow = block.getArrow();
int index;
if (blockArrow != null) {
index = blockArrow.getStartOffsetInParent() + blockArrow.getTextLength();
}
else {
index = 1;
}
while (index < text.length() && Character.isWhitespace(text.charAt(index))) index++;
text = text.substring(index, text.length() - 1);
builder.append(text);
builder.append("}");
final GrStatement statement = elementFactory.createStatementFromText(builder.toString());
GrForStatement forStatement = (GrForStatement)expression.replaceWithStatement(statement);
final GrForClause clause = forStatement.getClause();
GrVariable variable = clause.getDeclaredVariable();
forStatement = updateReturnStatements(forStatement);
if (variable == null) return;
if (ApplicationManager.getApplication().isUnitTestMode()) return;
final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
final Document doc = documentManager.getDocument(element.getContainingFile());
if (doc == null) return;
documentManager.doPostponedOperationsAndUnblockDocument(doc);
editor.getCaretModel().moveToOffset(variable.getTextOffset());
new VariableInplaceRenamer(variable, editor).performInplaceRename();
}
示例7: createRenamer
import com.intellij.refactoring.rename.inplace.VariableInplaceRenamer; //导入依赖的package包/类
@Override
protected VariableInplaceRenamer createRenamer(@NotNull PsiElement elementToRename, Editor editor) {
return new GrVariableInplaceRenamer((PsiNameIdentifierOwner)elementToRename, editor);
}
示例8: beforeTemplateStart
import com.intellij.refactoring.rename.inplace.VariableInplaceRenamer; //导入依赖的package包/类
@Override
protected void beforeTemplateStart() {
super.beforeTemplateStart();
final ResolveSnapshotProvider resolveSnapshotProvider = VariableInplaceRenamer.INSTANCE.forLanguage(myScope.getLanguage());
myConflictResolver = resolveSnapshotProvider != null ? resolveSnapshotProvider.createSnapshot(myScope) : null;
}
示例9: processIntention
import com.intellij.refactoring.rename.inplace.VariableInplaceRenamer; //导入依赖的package包/类
@Override
protected void processIntention(@NotNull PsiElement element, Project project, Editor editor) throws IncorrectOperationException {
final GrMethodCallExpression expression = (GrMethodCallExpression)element;
final GrClosableBlock block = expression.getClosureArguments()[0];
final GrParameterList parameterList = block.getParameterList();
final GrParameter[] parameters = parameterList.getParameters();
String var;
if (parameters.length == 1) {
var = parameters[0].getText();
var = StringUtil.replace(var, GrModifier.DEF, "");
}
else {
var = "it";
}
final GrExpression invokedExpression = expression.getInvokedExpression();
GrExpression qualifier = ((GrReferenceExpression)invokedExpression).getQualifierExpression();
final GroovyPsiElementFactory elementFactory = GroovyPsiElementFactory.getInstance(element.getProject());
if (qualifier == null) {
qualifier = elementFactory.createExpressionFromText("this");
}
StringBuilder builder = new StringBuilder();
builder.append("for (").append(var).append(" in ").append(qualifier.getText()).append(") {\n");
String text = block.getText();
final PsiElement blockArrow = block.getArrow();
int index;
if (blockArrow != null) {
index = blockArrow.getStartOffsetInParent() + blockArrow.getTextLength();
}
else {
index = 1;
}
while (index < text.length() && Character.isWhitespace(text.charAt(index))) index++;
text = text.substring(index, text.length() - 1);
builder.append(text);
builder.append("}");
final GrStatement statement = elementFactory.createStatementFromText(builder.toString());
final GrForStatement forStatement = (GrForStatement)expression.replaceWithStatement(statement);
final GrForClause clause = forStatement.getClause();
GrVariable variable = clause.getDeclaredVariable();
if (variable == null) return;
if (ApplicationManager.getApplication().isUnitTestMode()) return;
final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
final Document doc = documentManager.getDocument(element.getContainingFile());
if (doc == null) return;
documentManager.doPostponedOperationsAndUnblockDocument(doc);
editor.getCaretModel().moveToOffset(variable.getTextOffset());
new VariableInplaceRenamer(variable, editor).performInplaceRename();
}
示例10: createRenamer
import com.intellij.refactoring.rename.inplace.VariableInplaceRenamer; //导入依赖的package包/类
@Nullable
@Override
protected VariableInplaceRenamer createRenamer(@NotNull PsiElement elementToRename, Editor editor)
{
return new CSharpVariableInplaceRenamer((PsiNamedElement) elementToRename, editor);
}
示例11: createRenamer
import com.intellij.refactoring.rename.inplace.VariableInplaceRenamer; //导入依赖的package包/类
protected VariableInplaceRenamer createRenamer(@NotNull PsiElement elementToRename, Editor editor) {
return new VariableInplaceRenamer((PsiNameIdentifierOwner) elementToRename, editor);
}