Java 类com.intellij.psi.JavaRecursiveElementVisitor 实例源码

项目:tools-idea    文件:CodeFragmentFactoryContextWrapper.java   
private PsiElement wrapContext(Project project, final PsiElement originalContext) {
  if (project.isDefault()) return originalContext;
  PsiElement context = originalContext;
  final DebugProcessImpl process = DebuggerManagerEx.getInstanceEx(project).getContext().getDebugProcess();
  if (process != null) {
    final Map<ObjectReference, ValueMarkup> markupMap = ValueDescriptorImpl.getMarkupMap(process);
    if (markupMap != null && markupMap.size() > 0) {
      final Pair<String, Map<String, ObjectReference>> markupVariables = createMarkupVariablesText(markupMap);
      int offset = markupVariables.getFirst().length() - 1;
      final TextWithImportsImpl textWithImports = new TextWithImportsImpl(CodeFragmentKind.CODE_BLOCK, markupVariables.getFirst(), "", myDelegate.getFileType());
      final JavaCodeFragment codeFragment = myDelegate.createCodeFragment(textWithImports, context, project);
      codeFragment.accept(new JavaRecursiveElementVisitor() {
        public void visitLocalVariable(PsiLocalVariable variable) {
          final String name = variable.getName();
          variable.putUserData(LABEL_VARIABLE_VALUE_KEY, markupVariables.getSecond().get(name));
        }
      });
      final PsiElement newContext = codeFragment.findElementAt(offset);
      if (newContext != null) {
        context = newContext;
      }
    }
  }
  return context;
}
项目:consulo-java    文件:JavaSoftKeywordHighlightingPass.java   
@RequiredReadAction
@Override
public void doCollectInformation(@NotNull ProgressIndicator progressIndicator)
{
    LanguageLevel languageLevel = myFile.getLanguageLevel();

    myFile.accept(new JavaRecursiveElementVisitor()
    {
        @Override
        public void visitKeyword(PsiKeyword keyword)
        {
            if(JavaLexer.isSoftKeyword(keyword.getNode().getChars(), languageLevel))
            {
                ContainerUtil.addIfNotNull(myResults, HighlightInfo.newHighlightInfo(JavaHighlightInfoTypes.JAVA_KEYWORD).range(keyword).create());
            }
        }
    });
}
项目:intellij-ce-playground    文件:CodeFragmentFactoryContextWrapper.java   
private PsiElement wrapContext(Project project, final PsiElement originalContext) {
  if (project.isDefault()) return originalContext;
  //TODO [egor] : does not work for anything other than java anyway, see IDEA-132677
  if (!(myDelegate instanceof DefaultCodeFragmentFactory)) {
    return originalContext;
  }
  PsiElement context = originalContext;
  XDebugSession session = XDebuggerManager.getInstance(project).getCurrentSession();
  if (session != null) {
    XValueMarkers<?, ?> markers = ((XDebugSessionImpl)session).getValueMarkers();
    Map<?, ValueMarkup> markupMap = markers != null ? markers.getAllMarkers() : null;
    //final Map<ObjectReference, ValueMarkup> markupMap = ValueDescriptorImpl.getMarkupMap(process);
    if (markupMap != null && markupMap.size() > 0) {
      final Pair<String, Map<String, ObjectReference>> markupVariables = createMarkupVariablesText(markupMap);
      int offset = markupVariables.getFirst().length() - 1;
      final TextWithImportsImpl textWithImports = new TextWithImportsImpl(CodeFragmentKind.CODE_BLOCK, markupVariables.getFirst(), "", myDelegate.getFileType());
      final JavaCodeFragment codeFragment = myDelegate.createCodeFragment(textWithImports, context, project);
      codeFragment.accept(new JavaRecursiveElementVisitor() {
        public void visitLocalVariable(PsiLocalVariable variable) {
          final String name = variable.getName();
          variable.putUserData(LABEL_VARIABLE_VALUE_KEY, markupVariables.getSecond().get(name));
        }
      });
      final PsiElement newContext = codeFragment.findElementAt(offset);
      if (newContext != null) {
        context = newContext;
      }
    }
  }
  return context;
}
项目:CopyConstructorPlugin    文件:IncompleteCopyConstructorInspection.java   
private boolean constructorAssignsAllFields(final PsiMethod constructor, List<PsiField> allFields) {
    final Set<PsiField> unassignedFields = new HashSet<PsiField>(allFields);
    final PsiParameter copyParameter = constructor.getParameterList().getParameters()[0];
    constructor.accept(new JavaRecursiveElementVisitor() {
        @Override
        public void visitAssignmentExpression(PsiAssignmentExpression expression) {
            PsiExpression left = expression.getLExpression();
            PsiExpression right = expression.getRExpression();
            PsiReference assignee = left.getReference();
            if (assignee != null) {
                PsiElement leftReference = assignee.resolve();
                if (leftReference != null && leftReference instanceof PsiField) {
                    PsiField referencedField = (PsiField) leftReference;
                    if (isReferenceToFieldInInstance(left, referencedField, null)) {
                        if (isReferenceToFieldInInstance(right, referencedField, copyParameter)) {
                            unassignedFields.remove(referencedField);
                        } else if (right != null) {
                            // report problem: suspicious assignment copies value from wrong field: "this.x = copy.y"
                            holder.registerProblem(expression,
                                    String.format("Suspicious assignment in copy constructor of '%s' to field %s", right.getText(),
                                            referencedField.getName()), ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
                        }
                    }
                }
            }
        }
    });
    return unassignedFields.isEmpty();
}
项目:consulo-java    文件:VcsContentAnnotationExceptionFilter.java   
@Nullable
private static List<PsiMethod> selectMethod(final PsiMethod[] methods, final Trinity<PsiClass, PsiFile, String> previousLineResult)
{
    if(previousLineResult == null || previousLineResult.getThird() == null)
    {
        return null;
    }

    final List<PsiMethod> result = new SmartList<PsiMethod>();
    for(final PsiMethod method : methods)
    {
        method.accept(new JavaRecursiveElementVisitor()
        {
            @Override
            public void visitCallExpression(PsiCallExpression callExpression)
            {
                final PsiMethod resolved = callExpression.resolveMethod();
                if(resolved != null)
                {
                    if(resolved.getName().equals(previousLineResult.getThird()))
                    {
                        result.add(method);
                    }
                }
            }
        });
    }

    return result;
}
项目:consulo-java    文件:JavaLambdaNodeProvider.java   
@NotNull
@Override
public List<JavaLambdaTreeElement> provideNodes(@NotNull TreeElement node)
{
    if(node instanceof PsiMethodTreeElement ||
            node instanceof PsiFieldTreeElement ||
            node instanceof ClassInitializerTreeElement ||
            node instanceof JavaLambdaTreeElement)
    {
        final PsiElement el = ((PsiTreeElementBase) node).getElement();
        if(el != null)
        {
            final List<JavaLambdaTreeElement> result = new ArrayList<>();
            el.accept(new JavaRecursiveElementVisitor()
            {
                @Override
                public void visitLambdaExpression(PsiLambdaExpression expression)
                {
                    super.visitLambdaExpression(expression);
                    result.add(new JavaLambdaTreeElement(expression));
                }

                @Override
                public void visitClass(PsiClass aClass)
                {
                    //stop at class level
                }
            });
            return result;
        }
    }
    return Collections.emptyList();
}
项目:consulo-java    文件:CodeFragmentFactoryContextWrapper.java   
private PsiElement wrapContext(Project project, final PsiElement originalContext)
{
    if(project.isDefault())
    {
        return originalContext;
    }
    PsiElement context = originalContext;
    final DebugProcessImpl process = DebuggerManagerEx.getInstanceEx(project).getContext().getDebugProcess();
    if(process != null)
    {
        final Map<ObjectReference, ValueMarkup> markupMap = ValueDescriptorImpl.getMarkupMap(process);
        if(markupMap != null && markupMap.size() > 0)
        {
            final Pair<String, Map<String, ObjectReference>> markupVariables = createMarkupVariablesText(markupMap);
            int offset = markupVariables.getFirst().length() - 1;
            final TextWithImportsImpl textWithImports = new TextWithImportsImpl(CodeFragmentKind.CODE_BLOCK, markupVariables.getFirst(), "", myDelegate.getFileType());
            final JavaCodeFragment codeFragment = myDelegate.createCodeFragment(textWithImports, context, project);
            codeFragment.accept(new JavaRecursiveElementVisitor()
            {
                @Override
                public void visitLocalVariable(PsiLocalVariable variable)
                {
                    final String name = variable.getName();
                    variable.putUserData(LABEL_VARIABLE_VALUE_KEY, markupVariables.getSecond().get(name));
                }
            });
            final PsiElement newContext = codeFragment.findElementAt(offset);
            if(newContext != null)
            {
                context = newContext;
            }
        }
    }
    return context;
}