本文整理汇总了Java中com.intellij.codeInsight.generation.GenerateMembersUtil.positionCaret方法的典型用法代码示例。如果您正苦于以下问题:Java GenerateMembersUtil.positionCaret方法的具体用法?Java GenerateMembersUtil.positionCaret怎么用?Java GenerateMembersUtil.positionCaret使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.codeInsight.generation.GenerateMembersUtil
的用法示例。
在下文中一共展示了GenerateMembersUtil.positionCaret方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: invoke
import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入方法依赖的package包/类
@Override
public void invoke(@NotNull Project project,
@NotNull PsiFile file,
@Nullable("is null when called from inspection") Editor editor,
@NotNull PsiElement startElement,
@NotNull PsiElement endElement) {
final PsiClass myClass = (PsiClass)startElement;
if (!FileModificationService.getInstance().prepareFileForWrite(myClass.getContainingFile())) return;
PsiCodeBlock body;
if (myClass.isInterface() && (body = myMethodPrototype.getBody()) != null) body.delete();
for (String exception : myExceptions) {
PsiUtil.addException(myMethodPrototype, exception);
}
PsiMethod method = (PsiMethod)myClass.add(myMethodPrototype);
method = (PsiMethod)method.replace(reformat(project, method));
if (editor != null && method.getContainingFile() == file) {
GenerateMembersUtil.positionCaret(editor, method, true);
}
}
示例2: postAddAction
import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入方法依赖的package包/类
protected void postAddAction(@NotNull PsiFile file,
@Nullable("is null when called from inspection") Editor editor,
PsiMethod newMethod) {
if (editor != null && newMethod.getContainingFile() == file) {
GenerateMembersUtil.positionCaret(editor, newMethod, true);
}
}
示例3: processIntention
import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入方法依赖的package包/类
@Override
protected void processIntention(Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
final PsiLambdaExpression lambdaExpression = PsiTreeUtil.getParentOfType(element, PsiLambdaExpression.class);
LOG.assertTrue(lambdaExpression != null);
final PsiParameter[] paramListCopy = ((PsiParameterList)lambdaExpression.getParameterList().copy()).getParameters();
final PsiType functionalInterfaceType = lambdaExpression.getFunctionalInterfaceType();
LOG.assertTrue(functionalInterfaceType != null);
final PsiMethod method = LambdaUtil.getFunctionalInterfaceMethod(functionalInterfaceType);
LOG.assertTrue(method != null);
final String blockText = getBodyText(lambdaExpression);
if (blockText == null) return;
final PsiElementFactory psiElementFactory = JavaPsiFacade.getElementFactory(element.getProject());
PsiCodeBlock blockFromText = psiElementFactory.createCodeBlockFromText(blockText, lambdaExpression);
qualifyThisExpressions(lambdaExpression, psiElementFactory, blockFromText);
blockFromText = psiElementFactory.createCodeBlockFromText(blockFromText.getText(), null);
PsiNewExpression newExpression = (PsiNewExpression)psiElementFactory.createExpressionFromText("new " + functionalInterfaceType.getCanonicalText() + "(){}", lambdaExpression);
newExpression = (PsiNewExpression)JavaCodeStyleManager.getInstance(lambdaExpression.getProject()).shortenClassReferences(lambdaExpression.replace(newExpression));
final PsiAnonymousClass anonymousClass = newExpression.getAnonymousClass();
LOG.assertTrue(anonymousClass != null);
final List<PsiGenerationInfo<PsiMethod>> infos = OverrideImplementUtil.overrideOrImplement(anonymousClass, method);
if (infos != null && infos.size() == 1) {
final PsiMethod member = infos.get(0).getPsiMember();
final PsiParameter[] parameters = member.getParameterList().getParameters();
if (parameters.length == paramListCopy.length) {
for (int i = 0; i < parameters.length; i++) {
final PsiParameter parameter = parameters[i];
final String lambdaParamName = paramListCopy[i].getName();
if (lambdaParamName != null) {
parameter.setName(lambdaParamName);
}
}
}
PsiCodeBlock codeBlock = member.getBody();
LOG.assertTrue(codeBlock != null);
codeBlock = (PsiCodeBlock)codeBlock.replace(blockFromText);
GenerateMembersUtil.positionCaret(editor, member, true);
}
}
示例4: processIntention
import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入方法依赖的package包/类
@Override
protected void processIntention(Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
final PsiLambdaExpression lambdaExpression = PsiTreeUtil.getParentOfType(element, PsiLambdaExpression.class);
LOG.assertTrue(lambdaExpression != null);
final PsiParameter[] paramListCopy = ((PsiParameterList)lambdaExpression.getParameterList().copy()).getParameters();
PsiType functionalInterfaceType = lambdaExpression.getFunctionalInterfaceType();
LOG.assertTrue(functionalInterfaceType != null);
functionalInterfaceType = GenericsUtil.eliminateWildcards(functionalInterfaceType);
final PsiMethod method = LambdaUtil.getFunctionalInterfaceMethod(functionalInterfaceType);
LOG.assertTrue(method != null);
final String blockText = getBodyText(lambdaExpression);
if (blockText == null) return;
final PsiElementFactory psiElementFactory = JavaPsiFacade.getElementFactory(element.getProject());
PsiCodeBlock blockFromText = psiElementFactory.createCodeBlockFromText(blockText, lambdaExpression);
ChangeContextUtil.encodeContextInfo(blockFromText, true);
PsiNewExpression newExpression = (PsiNewExpression)psiElementFactory.createExpressionFromText("new " + functionalInterfaceType.getCanonicalText() + "(){}", lambdaExpression);
final PsiClass thisClass = PsiTreeUtil.getParentOfType(lambdaExpression, PsiClass.class, true);
final String thisClassName = thisClass.getName();
if (thisClassName != null) {
final PsiThisExpression thisAccessExpr = thisClass instanceof PsiAnonymousClass ? null : RefactoringChangeUtil
.createThisExpression(lambdaExpression.getManager(), thisClass);
ChangeContextUtil.decodeContextInfo(blockFromText, thisClass, thisAccessExpr);
final Map<PsiElement, PsiElement> replacements = new HashMap<PsiElement, PsiElement>();
blockFromText.accept(new JavaRecursiveElementWalkingVisitor() {
@Override
public void visitSuperExpression(PsiSuperExpression expression) {
super.visitSuperExpression(expression);
if (expression.getQualifier() == null) {
replacements.put(expression, psiElementFactory.createExpressionFromText(thisClassName + "." + expression.getText(), expression));
}
}
});
for (PsiElement psiElement : replacements.keySet()) {
psiElement.replace(replacements.get(psiElement));
}
}
blockFromText = psiElementFactory.createCodeBlockFromText(blockFromText.getText(), null);
newExpression = (PsiNewExpression)JavaCodeStyleManager.getInstance(lambdaExpression.getProject()).shortenClassReferences(lambdaExpression.replace(newExpression));
final PsiAnonymousClass anonymousClass = newExpression.getAnonymousClass();
LOG.assertTrue(anonymousClass != null);
final List<PsiGenerationInfo<PsiMethod>> infos = OverrideImplementUtil.overrideOrImplement(anonymousClass, method);
if (infos != null && infos.size() == 1) {
final PsiMethod member = infos.get(0).getPsiMember();
final PsiParameter[] parameters = member.getParameterList().getParameters();
for (int i = 0; i < parameters.length; i++) {
final PsiParameter parameter = parameters[i];
final String lambdaParamName = paramListCopy[i].getName();
if (lambdaParamName != null) {
parameter.setName(lambdaParamName);
}
}
PsiCodeBlock codeBlock = member.getBody();
LOG.assertTrue(codeBlock != null);
codeBlock = (PsiCodeBlock)codeBlock.replace(blockFromText);
GenerateMembersUtil.positionCaret(editor, member, true);
}
}