com.intellij.refactoring.util.RefactoringUtil Java Examples
The following examples show how to use
com.intellij.refactoring.util.RefactoringUtil.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExtractSuperBaseProcessor.java From intellij-haxe with Apache License 2.0 | 6 votes |
@NotNull protected UsageInfo[] findUsages() { PsiReference[] refs = ReferencesSearch.search(myClass, GlobalSearchScope.projectScope(myProject), false).toArray(new PsiReference[0]); final ArrayList<UsageInfo> result = new ArrayList<UsageInfo>(); detectTurnToSuperRefs(refs, result); final PsiPackage originalPackage = JavaDirectoryService.getInstance().getPackage(myClass.getContainingFile().getContainingDirectory()); if (Comparing.equal(JavaDirectoryService.getInstance().getPackage(myTargetDirectory), originalPackage)) { result.clear(); } for (final PsiReference ref : refs) { final PsiElement element = ref.getElement(); if (!canTurnToSuper(element) && !RefactoringUtil.inImportStatement(ref, element)) { result.add(new BindToOldUsageInfo(element, ref, myClass)); } } UsageInfo[] usageInfos = result.toArray(new UsageInfo[result.size()]); return UsageViewUtil.removeDuplicatedUsages(usageInfos); }
Example #2
Source File: PushDownProcessor.java From intellij-haxe with Apache License 2.0 | 5 votes |
private void removeFromTargetClass() throws IncorrectOperationException { for (MemberInfo memberInfo : myMemberInfos) { final PsiElement member = memberInfo.getMember(); if (member instanceof PsiField) { member.delete(); } else if (member instanceof PsiMethod) { if (memberInfo.isToAbstract()) { final PsiMethod method = (PsiMethod)member; if (method.hasModifierProperty(PsiModifier.PRIVATE)) { PsiUtil.setModifierProperty(method, PsiModifier.PROTECTED, true); } RefactoringUtil.makeMethodAbstract(myClass, method); myJavaDocPolicy.processOldJavaDoc(method.getDocComment()); } else { member.delete(); } } else if (member instanceof PsiClass) { //if (Boolean.FALSE.equals(memberInfo.getOverrides())) { //RefactoringUtil.removeFromReferenceList(myClass.getImplementsList(), (PsiClass)member); //} //else { //} member.delete(); } } }
Example #3
Source File: HaxePullUpHelper.java From intellij-haxe with Apache License 2.0 | 5 votes |
private void doMoveField(PsiSubstitutor substitutor, MemberInfo info) { PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(myProject); PsiField field = (PsiField)info.getMember(); field.normalizeDeclaration(); RefactoringUtil.replaceMovedMemberTypeParameters(field, PsiUtil.typeParametersIterable(mySourceClass), substitutor, elementFactory); fixReferencesToStatic(field); if (myIsTargetInterface) { PsiUtil.setModifierProperty(field, PsiModifier.PUBLIC, true); } final PsiMember movedElement = (PsiMember)myTargetSuperClass.addBefore(convertFieldToLanguage(field, myTargetSuperClass.getLanguage()), myTargetSuperClass.getRBrace()); myMembersAfterMove.add(movedElement); field.delete(); }
Example #4
Source File: HaxePullUpHelper.java From intellij-haxe with Apache License 2.0 | 4 votes |
@Nullable private PsiStatement hasCommonInitializer(PsiStatement commonInitializer, PsiMethod subConstructor, PsiField field, ArrayList<PsiElement> statementsToRemove) { final PsiCodeBlock body = subConstructor.getBody(); if (body == null) return null; final PsiStatement[] statements = body.getStatements(); // Algorithm: there should be only one write usage of field in a subConstructor, // and in that usage field must be a target of top-level assignment, and RHS of assignment // should be the same as commonInitializer if latter is non-null. // // There should be no usages before that initializer, and there should be // no write usages afterwards. PsiStatement commonInitializerCandidate = null; for (PsiStatement statement : statements) { final HashSet<PsiStatement> collectedStatements = new HashSet<PsiStatement>(); collectPsiStatements(statement, collectedStatements); boolean doLookup = true; for (PsiStatement collectedStatement : collectedStatements) { if (collectedStatement instanceof PsiExpressionStatement) { final PsiExpression expression = ((PsiExpressionStatement)collectedStatement).getExpression(); if (expression instanceof PsiAssignmentExpression) { final PsiAssignmentExpression assignmentExpression = (PsiAssignmentExpression)expression; final PsiExpression lExpression = assignmentExpression.getLExpression(); if (lExpression instanceof PsiReferenceExpression) { final PsiReferenceExpression lRef = (PsiReferenceExpression)lExpression; if (lRef.getQualifierExpression() == null || lRef.getQualifierExpression() instanceof PsiThisExpression) { final PsiElement resolved = lRef.resolve(); if (resolved == field) { doLookup = false; if (commonInitializerCandidate == null) { final PsiExpression initializer = assignmentExpression.getRExpression(); if (initializer == null) return null; if (commonInitializer == null) { final IsMovableInitializerVisitor visitor = new IsMovableInitializerVisitor(); statement.accept(visitor); if (visitor.isMovable()) { ChangeContextUtil.encodeContextInfo(statement, true); PsiStatement statementCopy = (PsiStatement)statement.copy(); ChangeContextUtil.clearContextInfo(statement); statementsToRemove.add(statement); commonInitializerCandidate = statementCopy; } else { return null; } } else { if (PsiEquivalenceUtil.areElementsEquivalent(commonInitializer, statement)) { statementsToRemove.add(statement); commonInitializerCandidate = commonInitializer; } else { return null; } } } else if (!PsiEquivalenceUtil.areElementsEquivalent(commonInitializerCandidate, statement)){ return null; } } } } } } } if (doLookup) { final PsiReference[] references = ReferencesSearch.search(field, new LocalSearchScope(statement), false).toArray(new PsiReference[0]); if (commonInitializerCandidate == null && references.length > 0) { return null; } for (PsiReference reference : references) { if (RefactoringUtil.isAssignmentLHS(reference.getElement())) return null; } } } return commonInitializerCandidate; }