Ejemplo n.º 1
0
 private static boolean mayBeFinal(Set<PsiReference> refsSet, PsiElement firstElement) {
   for (PsiReference ref : refsSet) {
     PsiElement element = ref.getElement();
     if (element == firstElement) continue;
     if (element instanceof PsiExpression
         && PsiUtil.isAccessedForWriting((PsiExpression) element)) return false;
   }
   return true;
 }
 private static boolean notAccessedForWriting(
     @NotNull PsiVariable variable, @NotNull LocalSearchScope searchScope) {
   for (PsiReference reference : ReferencesSearch.search(variable, searchScope)) {
     final PsiElement element = reference.getElement();
     if (element instanceof PsiExpression
         && PsiUtil.isAccessedForWriting((PsiExpression) element)) {
       return false;
     }
   }
   return true;
 }
Ejemplo n.º 3
0
 private static PsiElement getFirstElement(Collection<PsiReference> refs) {
   PsiElement firstElement = null;
   for (PsiReference reference : refs) {
     final PsiElement element = reference.getElement();
     if (firstElement == null
         || firstElement.getTextRange().getStartOffset()
             > element.getTextRange().getStartOffset()) {
       firstElement = element;
     }
   }
   return firstElement;
 }
Ejemplo n.º 4
0
 private static PsiCodeBlock findAnchorBlock(final Collection<PsiReference> refs) {
   PsiCodeBlock result = null;
   for (PsiReference psiReference : refs) {
     final PsiElement element = psiReference.getElement();
     PsiCodeBlock block = PsiTreeUtil.getParentOfType(element, PsiCodeBlock.class);
     if (result == null || block == null) {
       result = block;
     } else {
       final PsiElement commonParent = PsiTreeUtil.findCommonParent(result, block);
       result = PsiTreeUtil.getParentOfType(commonParent, PsiCodeBlock.class, false);
     }
   }
   return result;
 }
 private void removeParametersUsedInExitsOnly(
     PsiElement codeFragment, List<PsiVariable> inputVariables) {
   LocalSearchScope scope = new LocalSearchScope(codeFragment);
   Variables:
   for (Iterator<PsiVariable> iterator = inputVariables.iterator(); iterator.hasNext(); ) {
     PsiVariable variable = iterator.next();
     for (PsiReference ref : ReferencesSearch.search(variable, scope)) {
       PsiElement element = ref.getElement();
       int elementOffset = myControlFlow.getStartOffset(element);
       if (elementOffset == -1) {
         continue Variables;
       }
       if (elementOffset >= myFlowStart && elementOffset <= myFlowEnd) {
         if (!isInExitStatements(element, myExitStatements)) continue Variables;
       }
     }
     iterator.remove();
   }
 }
 @Override
 public boolean process(PsiReference reference) {
   final PsiElement element = reference.getElement();
   if (element instanceof PsiReferenceExpression
       && PsiUtil.isAccessedForWriting((PsiExpression) element)) {
     myIsWriteRefFound = true;
     return false;
   }
   return true;
 }