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

项目:nullability-annotations-inspection    文件:AddPackageInfoWithNullabilityDefaultsFix.java   
@Nullable
private PsiJavaFile getOrCreatePackageInfoFile(PsiFile file) {
    if (!(file instanceof PsiJavaFile)) {
        return null;
    }

    PsiPackageStatement packageStatement = ((PsiJavaFile) file).getPackageStatement();
    if (packageStatement == null) {
        return null;
    }

    PsiJavaCodeReferenceElement packageReference = packageStatement.getPackageReference();
    PsiElement target = packageReference.resolve();
    if (!(target instanceof PsiPackage)) {
        return null;
    }

    PsiJavaFile packageInfoFile = packageInfoFile((PsiPackage) target, file.getContainingDirectory());
    if (packageInfoFile == null) {
        packageInfoFile = createPackageInfoFile(file, (PsiPackage) target);
    }

    return packageInfoFile;
}
项目:nullability-annotations-inspection    文件:AddPackageInfoWithNullabilityDefaultsFix.java   
@Nullable
private static Set<PsiAnnotation.TargetType> targetTypesForDefault(PsiAnnotation annotation) {
    PsiJavaCodeReferenceElement element = annotation.getNameReferenceElement();
    PsiElement declaration = element == null ? null : element.resolve();

    if (!(declaration instanceof PsiClass)) {
        return Collections.emptySet();
    }

    PsiClass classDeclaration = (PsiClass) declaration;
    PsiAnnotation tqDefault = AnnotationUtil.findAnnotation(classDeclaration, true, TYPE_QUALIFIER_DEFAULT);

    if (tqDefault == null) {
        return Collections.emptySet();
    }

    return extractRequiredAnnotationTargets(tqDefault.findAttributeValue(null));
}
项目:nullability-annotations-inspection    文件:NullabilityAnnotationsWithTypeQualifierDefault.java   
private static boolean isNullabilityAnnotationForTypeQualifierDefault(PsiAnnotation annotation,
                                                                      boolean nullable,
                                                                      PsiAnnotation.TargetType[] targetTypes) {
    PsiJavaCodeReferenceElement element = annotation.getNameReferenceElement();
    PsiElement declaration = element == null ? null : element.resolve();
    if (!(declaration instanceof PsiClass)) {
        return false;
    }

    String fqn = nullable ? JAVAX_ANNOTATION_NULLABLE : JAVAX_ANNOTATION_NONNULL;
    PsiClass classDeclaration = (PsiClass) declaration;
    if (!AnnotationUtil.isAnnotated(classDeclaration, fqn, false, true)) {
        return false;
    }

    PsiAnnotation tqDefault = AnnotationUtil.findAnnotation(classDeclaration, true, TYPE_QUALIFIER_DEFAULT);
    if (tqDefault == null) {
        return false;
    }

    Set<PsiAnnotation.TargetType> required = extractRequiredAnnotationTargets(tqDefault.findAttributeValue(null));
    return required != null
            && (required.isEmpty() || ContainerUtil.intersects(required, Arrays.asList(targetTypes)));
}
项目:manifold-ij    文件:StubBuilder.java   
public static String makeTypeVar( PsiTypeParameter typeVar )
{
  StringBuilder sb = new StringBuilder();
  sb.append( typeVar.getName() );

  PsiJavaCodeReferenceElement[] bounds = typeVar.getExtendsList().getReferenceElements();
  if( bounds.length > 0 )
  {
    sb.append( " extends " );
    for( int i = 0; i < bounds.length; i++ )
    {
      if( i > 0 )
      {
        sb.append( " & " );
      }
      sb.append( bounds[i].getCanonicalText() );
    }
  }
  return sb.toString();
}
项目:intellij-ce-playground    文件:InlineStaticImportHandler.java   
@Override
public void inlineElement(Project project, Editor editor, PsiElement element) {
  final PsiImportStaticStatement staticStatement = PsiTreeUtil.getParentOfType(element, PsiImportStaticStatement.class);
  final List<PsiJavaCodeReferenceElement> referenceElements =
    collectReferencesThrough(element.getContainingFile(), null, staticStatement);

  RefactoringEventData data = new RefactoringEventData();
  data.addElement(element);
  project.getMessageBus().syncPublisher(RefactoringEventListener.REFACTORING_EVENT_TOPIC).refactoringStarted(REFACTORING_ID, data);


  new WriteCommandAction(project, REFACTORING_NAME){
    @Override
    protected void run(@NotNull Result result) throws Throwable {
      replaceAllAndDeleteImport(referenceElements, null, staticStatement);
    }
  }.execute();
  project.getMessageBus().syncPublisher(RefactoringEventListener.REFACTORING_EVENT_TOPIC).refactoringDone(REFACTORING_ID, null);
}
项目:intellij-ce-playground    文件:StaticInheritanceInspection.java   
@Override
public void visitClass(@NotNull PsiClass aClass) {
  // no call to super, so it doesn't drill down
  final PsiReferenceList implementsList = aClass.getImplementsList();
  if (implementsList == null) {
    return;
  }
  final PsiJavaCodeReferenceElement[] references =
    implementsList.getReferenceElements();
  for (final PsiJavaCodeReferenceElement reference : references) {
    final PsiElement target = reference.resolve();
    if (!(target instanceof PsiClass)) {
      return;
    }
    final PsiClass targetClass = (PsiClass)target;
    if (targetClass.isInterface() && interfaceContainsOnlyConstants(targetClass, new HashSet<PsiClass>())) {
      registerError(reference);
    }
  }
}
项目:intellij-ce-playground    文件:GrThrowsClauseImpl.java   
@Override
@NotNull
public PsiJavaCodeReferenceElement[] getReferenceElements() {
  PsiClassType[] types = getReferencedTypes();
  if (types.length == 0) return PsiJavaCodeReferenceElement.EMPTY_ARRAY;

  PsiManagerEx manager = getManager();

  List<PsiJavaCodeReferenceElement> result = ContainerUtil.newArrayList();
  for (PsiClassType type : types) {
    PsiClassType.ClassResolveResult resolveResult = type.resolveGenerics();
    PsiClass resolved = resolveResult.getElement();
    if (resolved != null) {
      result.add(new LightClassReference(manager, type.getCanonicalText(), resolved, resolveResult.getSubstitutor()));
    }
  }
  return result.toArray(new PsiJavaCodeReferenceElement[result.size()]);
}
项目:intellij-ce-playground    文件:GrThrowsClauseImpl.java   
@Override
public PsiElement add(@NotNull PsiElement element) throws IncorrectOperationException {
  if (element instanceof GrCodeReferenceElement || element instanceof PsiJavaCodeReferenceElement) {
    if (findChildByClass(GrCodeReferenceElement.class) == null) {
      getNode().addLeaf(GroovyTokenTypes.kTHROWS, "throws", null);
    }
    else {
      PsiElement lastChild = getLastChild();
      lastChild = PsiUtil.skipWhitespacesAndComments(lastChild, false);
      if (!lastChild.getNode().getElementType().equals(GroovyTokenTypes.mCOMMA)) {
        getNode().addLeaf(GroovyTokenTypes.mCOMMA, ",", null);
      }
    }

    if (element instanceof PsiJavaCodeReferenceElement) {
      element = GroovyPsiElementFactory.getInstance(getProject()).createCodeReferenceElementFromText(element.getText());
    }
  }
  return super.add(element);
}
项目:tools-idea    文件:StaticInheritanceInspection.java   
@Override
public void visitClass(@NotNull PsiClass aClass) {
  // no call to super, so it doesn't drill down
  final PsiReferenceList implementsList = aClass.getImplementsList();
  if (implementsList == null) {
    return;
  }
  final PsiJavaCodeReferenceElement[] references =
    implementsList.getReferenceElements();
  for (final PsiJavaCodeReferenceElement reference : references) {
    final PsiClass iface = (PsiClass)reference.resolve();
    if (iface != null) {
      if (interfaceContainsOnlyConstants(iface, new HashSet<PsiClass>())) {
        registerError(reference);
      }
    }
  }
}
项目:tools-idea    文件:ExtendsAnnotationInspection.java   
private void checkReferenceList(PsiReferenceList referenceList,
                                PsiClass containingClass) {
  if (referenceList == null) {
    return;
  }
  final PsiJavaCodeReferenceElement[] elements =
    referenceList.getReferenceElements();
  for (final PsiJavaCodeReferenceElement element : elements) {
    final PsiElement referent = element.resolve();
    if (!(referent instanceof PsiClass)) {
      continue;
    }
    final PsiClass psiClass = (PsiClass)referent;
    psiClass.isAnnotationType();
    if (psiClass.isAnnotationType()) {
      registerError(element, containingClass);
    }
  }
}
项目:ParcelablePlease    文件:CodeGenerator.java   
/**
 * Make the class implementing Parcelable
 */
private void makeClassImplementParcelable(PsiElementFactory elementFactory, JavaCodeStyleManager styleManager) {
  final PsiClassType[] implementsListTypes = psiClass.getImplementsListTypes();
  final String implementsType = "android.os.Parcelable";

  for (PsiClassType implementsListType : implementsListTypes) {
    PsiClass resolved = implementsListType.resolve();

    // Already implements Parcelable, no need to add it
    if (resolved != null && implementsType.equals(resolved.getQualifiedName())) {
      return;
    }
  }

  PsiJavaCodeReferenceElement implementsReference =
      elementFactory.createReferenceFromText(implementsType, psiClass);
  PsiReferenceList implementsList = psiClass.getImplementsList();

  if (implementsList != null) {
    styleManager.shortenClassReferences(implementsList.add(implementsReference));
  }
}
项目:lombok-intellij-plugin    文件:LombokElementFinderTest.java   
@Test
public void findClass() throws Exception {
  final PsiClass psiBaseClass = mock(PsiClass.class);
  when(javaFileManager.findClass(BASE_CLASS, scope)).thenReturn(psiBaseClass);

  final PsiModifierList psiModifierList = mock(PsiModifierList.class);
  when(psiBaseClass.getModifierList()).thenReturn(psiModifierList);

  final PsiAnnotation psiAnnotation = mock(PsiAnnotation.class);
  when(psiModifierList.getAnnotations()).thenReturn(new PsiAnnotation[]{psiAnnotation});

  when(psiAnnotation.getQualifiedName()).thenReturn(Builder.class.getName());

  final PsiJavaCodeReferenceElement referenceElement = mock(PsiJavaCodeReferenceElement.class);
  when(psiAnnotation.getNameReferenceElement()).thenReturn(referenceElement);
  when(referenceElement.getReferenceName()).thenReturn(Builder.class.getSimpleName());

  final PsiClass psiBuilderClass = mock(PsiClass.class);
  when(psiBaseClass.findInnerClassByName(eq(SOME_CLASS_BUILDER.substring(1)), anyBoolean())).thenReturn(psiBuilderClass);
  when(psiBuilderClass.getName()).thenReturn(SOME_CLASS_BUILDER.substring(1));

  final PsiClass psiClass = elementFinder.findClass(BASE_CLASS + SOME_CLASS_BUILDER, scope);
  assertNotNull(psiClass);
  verify(javaFileManager).findClass(BASE_CLASS, scope);
}
项目:consulo-javaee    文件:JspxImportStatementImpl.java   
@Nullable
@Override
public PsiJavaCodeReferenceElement getImportReference()
{
    if(myErrorElement != null)
    {
        return null;
    }

    if(isOnDemand())
    {
        return new LightPackageReference(getManager(), myQName);
    }
    else
    {
        return new LightClassReference(getManager(), myQName, myQName, getResolveScope());
    }
}
项目:consulo-java    文件:ClsPackageAccessibilityStatementImpl.java   
public ClsPackageAccessibilityStatementImpl(PsiPackageAccessibilityStatementStub stub)
{
    super(stub);
    myPackageReference = new AtomicNullableLazyValue<PsiJavaCodeReferenceElement>()
    {
        @Override
        protected PsiJavaCodeReferenceElement compute()
        {
            String packageName = getPackageName();
            return packageName != null ? new ClsJavaCodeReferenceElementImpl(ClsPackageAccessibilityStatementImpl.this, packageName) : null;
        }
    };
    myModuleReferences = new AtomicNotNullLazyValue<Iterable<PsiJavaModuleReferenceElement>>()
    {
        @NotNull
        @Override
        protected Iterable<PsiJavaModuleReferenceElement> compute()
        {
            return ContainerUtil.map(getStub().getTargets(), target -> new ClsJavaModuleReferenceElementImpl(ClsPackageAccessibilityStatementImpl.this, target));
        }
    };
}
项目:consulo-java    文件:PsiReferenceListImpl.java   
@Override
@NotNull
public PsiClassType[] getReferencedTypes()
{
    PsiClassReferenceListStub stub = getGreenStub();
    if(stub != null)
    {
        return stub.getReferencedTypes();
    }

    PsiJavaCodeReferenceElement[] refs = getReferenceElements();
    PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
    PsiClassType[] types = new PsiClassType[refs.length];
    for(int i = 0; i < types.length; i++)
    {
        types[i] = factory.createType(refs[i]);
    }

    return types;
}
项目:consulo-java    文件:ImportsHighlightUtil.java   
static HighlightInfo checkStaticOnDemandImportResolvesToClass(PsiImportStaticStatement statement)
{
    if(statement.isOnDemand() && statement.resolveTargetClass() == null)
    {
        PsiJavaCodeReferenceElement ref = statement.getImportReference();
        if(ref != null)
        {
            PsiElement resolve = ref.resolve();
            if(resolve != null)
            {
                return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(ObjectUtils.notNull(ref.getReferenceNameElement(), ref)).descriptionAndTooltip("Class " + ref
                        .getCanonicalText() + " not found").create();
            }
        }
    }
    return null;
}
项目:consulo-java    文件:MergeProvidesStatementsFix.java   
@NotNull
private static List<String> getImplementationNames(@NotNull List<PsiProvidesStatement> statements)
{
    List<String> list = new ArrayList<>();
    for(PsiProvidesStatement statement : statements)
    {
        PsiReferenceList implementationList = statement.getImplementationList();
        if(implementationList == null)
        {
            continue;
        }
        for(PsiJavaCodeReferenceElement element : implementationList.getReferenceElements())
        {
            ContainerUtil.addIfNotNull(list, element.getQualifiedName());
        }
    }
    return list;
}
项目:consulo-java    文件:MergeProvidesStatementsFix.java   
@Nullable
public static MergeModuleStatementsFix createFix(@Nullable PsiProvidesStatement statement)
{
    if(statement != null)
    {
        final PsiElement parent = statement.getParent();
        if(parent instanceof PsiJavaModule)
        {
            final PsiJavaCodeReferenceElement interfaceReference = statement.getInterfaceReference();
            if(interfaceReference != null)
            {
                final String interfaceName = interfaceReference.getQualifiedName();
                if(interfaceName != null)
                {
                    return new MergeProvidesStatementsFix((PsiJavaModule) parent, interfaceName);
                }
            }
        }
    }
    return null;
}
项目:consulo-java    文件:MakeExternalAnnotationExplicit.java   
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file)
{
    final PsiElement leaf = file.findElementAt(editor.getCaretModel().getOffset());
    final PsiModifierListOwner owner = ExternalAnnotationsLineMarkerProvider.getAnnotationOwner(leaf);
    if(owner != null && owner.getLanguage().isKindOf(JavaLanguage.INSTANCE) && isWritable(owner) && ModuleUtilCore.findModuleForPsiElement(file) != null && PsiUtil.getLanguageLevel(file)
            .isAtLeast(LanguageLevel.JDK_1_5))
    {
        final PsiAnnotation[] annotations = getAnnotations(project, owner);
        if(annotations.length > 0)
        {
            final String annos = StringUtil.join(annotations, annotation ->
            {
                final PsiJavaCodeReferenceElement nameRef = annotation.getNameReferenceElement();
                final String name = nameRef != null ? nameRef.getReferenceName() : annotation.getQualifiedName();
                return "@" + name + annotation.getParameterList().getText();
            }, " ");
            setText("Insert '" + annos + "'");
            return true;
        }
    }

    return false;
}
项目:consulo-java    文件:MakeInferredAnnotationExplicit.java   
@Override
public boolean isAvailable(@NotNull final Project project, Editor editor, PsiFile file)
{
    final PsiElement leaf = file.findElementAt(editor.getCaretModel().getOffset());
    final PsiModifierListOwner owner = ExternalAnnotationsLineMarkerProvider.getAnnotationOwner(leaf);
    if(owner != null && owner.getLanguage().isKindOf(JavaLanguage.INSTANCE) && isWritable(owner) && ModuleUtilCore.findModuleForPsiElement(file) != null && PsiUtil.getLanguageLevel(file)
            .isAtLeast(LanguageLevel.JDK_1_5))
    {
        final PsiAnnotation[] annotations = InferredAnnotationsManager.getInstance(project).findInferredAnnotations(owner);
        if(annotations.length > 0)
        {
            final String annos = StringUtil.join(annotations, annotation ->
            {
                final PsiJavaCodeReferenceElement nameRef = correctAnnotation(annotation).getNameReferenceElement();
                final String name = nameRef != null ? nameRef.getReferenceName() : annotation.getQualifiedName();
                return "@" + name + annotation.getParameterList().getText();
            }, " ");
            setText("Insert '" + annos + "'");
            return true;
        }
    }

    return false;
}
项目:consulo-java    文件:HyperlinksToClassesOption.java   
private static void findClassReferences(PsiElement psiElement, TreeMap<Integer, PsiReference> refMap, Map<PsiFile, PsiFile> filesMap, PsiFile psiFile) {
  PsiReference ref = psiElement.getReference();
  if(ref instanceof PsiJavaCodeReferenceElement) {
    PsiElement refElement = ref.resolve();
    if(refElement instanceof PsiClass) {
      PsiFile containingFile = refElement.getContainingFile();
      if(!containingFile.equals(psiFile) && filesMap.get(containingFile) != null) {
        refMap.put(psiElement.getTextRange().getStartOffset(), ref);
      }
      return;
    }
  }
  PsiElement[] children = psiElement.getChildren();
  for (PsiElement aChildren : children) {
    findClassReferences(aChildren, refMap, filesMap, psiFile);
  }
}
项目:consulo-java    文件:ExtendsAnnotationInspection.java   
private void checkReferenceList(PsiReferenceList referenceList,
                                PsiClass containingClass) {
  if (referenceList == null) {
    return;
  }
  final PsiJavaCodeReferenceElement[] elements =
    referenceList.getReferenceElements();
  for (final PsiJavaCodeReferenceElement element : elements) {
    final PsiElement referent = element.resolve();
    if (!(referent instanceof PsiClass)) {
      continue;
    }
    final PsiClass psiClass = (PsiClass)referent;
    psiClass.isAnnotationType();
    if (psiClass.isAnnotationType()) {
      registerError(element, containingClass);
    }
  }
}
项目:consulo-java    文件:MultipleExceptionsDeclaredOnTestMethodInspection.java   
@Override
public void visitMethod(PsiMethod method) {
  super.visitMethod(method);
  if (!TestUtils.isJUnitTestMethod(method)) {
    return;
  }
  final PsiReferenceList throwsList = method.getThrowsList();
  final PsiJavaCodeReferenceElement[] referenceElements =
    throwsList.getReferenceElements();
  if (referenceElements.length < 2) {
    return;
  }

  final Query<PsiReference> query =
    MethodReferencesSearch.search(method);
  final PsiReference firstReference = query.findFirst();
  if (firstReference != null) {
    return;
  }
  registerError(throwsList);
}
项目:consulo-java    文件:ImportHelperTest.java   
public void testAutoImportSkipsClassReferenceInMethodPosition() throws Throwable
{
    @NonNls String text = "package x; import java.util.HashMap; class S { HashMap<String,String> f(){ return  Hash<caret>Map <String, String >();} }  ";
    configureByText(JavaFileType.INSTANCE, text);

    boolean old = CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY;
    CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY = true;
    DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(true);

    try
    {
        List<HighlightInfo> errs = highlightErrors();
        assertTrue(errs.size() > 1);

        PsiJavaFile javaFile = (PsiJavaFile) getFile();
        assertEquals(1, javaFile.getImportList().getAllImportStatements().length);

        PsiReference ref = javaFile.findReferenceAt(getEditor().getCaretModel().getOffset());
        ImportClassFix fix = new ImportClassFix((PsiJavaCodeReferenceElement) ref);
        assertFalse(fix.isAvailable(getProject(), getEditor(), getFile()));
    }
    finally
    {
        CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY = old;
    }
}
项目:consulo-java    文件:BindToElementTest.java   
public void testSingleClassImport() throws Exception
{
    doTest(new Runnable()
    {
        @Override
        public void run()
        {
            PsiElement element = myFile.findElementAt(myEditor.getCaretModel().getOffset());
            final PsiJavaCodeReferenceElement referenceElement = PsiTreeUtil.getParentOfType(element, PsiJavaCodeReferenceElement.class);
            final PsiClass aClassA = JavaPsiFacade.getInstance(myProject).findClass("p2.A", GlobalSearchScope.moduleScope(myModule));
            assertNotNull(aClassA);
            try
            {
                referenceElement.bindToElement(aClassA);
            }
            catch(IncorrectOperationException e)
            {
                LOGGER.error(e);
            }
        }
    });
}
项目:intellij-ce-playground    文件:PsiImportStatementStubImpl.java   
@Override
@Nullable
public PsiJavaCodeReferenceElement getReference() {
  PsiJavaCodeReferenceElement ref = SoftReference.dereference(myReference);
  if (ref == null) {
    ref = isStatic() ? getStaticReference() : getRegularReference();
    myReference = new SoftReference<PsiJavaCodeReferenceElement>(ref);
  }
  return ref;
}
项目:intellij-ce-playground    文件:PsiImportStatementStubImpl.java   
@Nullable
private PsiJavaCodeReferenceElement getStaticReference() {
  final PsiJavaCodeReferenceElement refElement = createReference();
  if (refElement == null) return null;
  if (isOnDemand() && refElement instanceof PsiJavaCodeReferenceElementImpl) {
    ((PsiJavaCodeReferenceElementImpl)refElement).setKindWhenDummy(PsiJavaCodeReferenceElementImpl.CLASS_FQ_NAME_KIND);
  }
  return refElement;
}
项目:intellij-ce-playground    文件:PsiImportStatementStubImpl.java   
@Nullable
private PsiJavaCodeReferenceElement getRegularReference() {
  final PsiJavaCodeReferenceElement refElement = createReference();
  if (refElement == null) return null;
  ((PsiJavaCodeReferenceElementImpl)refElement).setKindWhenDummy(
    isOnDemand() ? PsiJavaCodeReferenceElementImpl.CLASS_FQ_OR_PACKAGE_NAME_KIND
                 : PsiJavaCodeReferenceElementImpl.CLASS_FQ_NAME_KIND);
  return refElement;
}
项目:intellij-ce-playground    文件:PsiImportStatementStubImpl.java   
@Nullable
private PsiJavaCodeReferenceElement createReference() {
  final String refText = getImportReferenceText();
  if (refText == null) return null;

  final PsiJavaParserFacade parserFacade = JavaPsiFacade.getInstance(getProject()).getParserFacade();
  try {
    return parserFacade.createReferenceFromText(refText, getPsi());
  }
  catch (IncorrectOperationException e) {
    return null;
  }
}
项目:intellij-ce-playground    文件:ResolveVariableUtil.java   
public static PsiVariable resolveVariable(@NotNull PsiJavaCodeReferenceElement ref,
                                          boolean[] problemWithAccess,
                                          boolean[] problemWithStatic
) {

  /*
  long time1 = System.currentTimeMillis();
  */

  final VariableResolverProcessor processor = new VariableResolverProcessor(ref, ref.getContainingFile());
  PsiScopesUtil.resolveAndWalk(processor, ref, null);

  /*
  long time2 = System.currentTimeMillis();
  Statistics.resolveVariableTime += (time2 - time1);
  Statistics.resolveVariableCount++;
  */
  final JavaResolveResult[] result = processor.getResult();
  if (result.length != 1) return null;
  final PsiVariable refVar = (PsiVariable)result[0].getElement();

  if (problemWithAccess != null) {
    problemWithAccess[0] = !result[0].isAccessible();
  }
  if (problemWithStatic != null) {
    problemWithStatic[0] = !result[0].isStaticsScopeCorrect();
  }


  return refVar;
}
项目:intellij-ce-playground    文件:PsiImportStatementBaseImpl.java   
@Override
public PsiJavaCodeReferenceElement getImportReference() {
  PsiUtilCore.ensureValid(this);
  final PsiImportStatementStub stub = getStub();
  if (stub != null) {
    return stub.getReference();
  }
  return (PsiJavaCodeReferenceElement)calcTreeElement().findChildByRoleAsPsiElement(ChildRole.IMPORT_REFERENCE);
}
项目:intellij-ce-playground    文件:JavaDocReferenceInspection.java   
@Override
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
  final PsiElement element = PsiTreeUtil.getParentOfType(descriptor.getPsiElement(), PsiJavaCodeReferenceElement.class);
  if (element instanceof PsiJavaCodeReferenceElement) {
    final PsiJavaCodeReferenceElement referenceElement = (PsiJavaCodeReferenceElement)element;
    Collections.sort(originalClasses, new PsiProximityComparator(referenceElement.getElement()));
    final JList list = new JBList(originalClasses.toArray(new PsiClass[originalClasses.size()]));
    list.setCellRenderer(new FQNameCellRenderer());
    final Runnable runnable = new Runnable() {
      @Override
      public void run() {
        if (!element.isValid()) return;
        final int index = list.getSelectedIndex();
        if (index < 0) return;
        new WriteCommandAction(project, element.getContainingFile()){
          @Override
          protected void run(@NotNull final Result result) throws Throwable {
            final PsiClass psiClass = originalClasses.get(index);
            if (psiClass.isValid()) {
              PsiDocumentManager.getInstance(project).commitAllDocuments();
              referenceElement.bindToElement(psiClass);
            }
          }
        }.execute();
      }
    };
    final AsyncResult<DataContext> asyncResult = DataManager.getInstance().getDataContextFromFocus();
    asyncResult.doWhenDone(new Consumer<DataContext>() {
      @Override
      public void consume(DataContext dataContext) {
        new PopupChooserBuilder(list).
          setTitle(QuickFixBundle.message("add.qualifier.original.class.chooser.title")).
          setItemChoosenCallback(runnable).
          createPopup().
          showInBestPositionFor(dataContext);
      }
    });
  }
}
项目:intellij-ce-playground    文件:RemoveNewQualifierFix.java   
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
  if (!FileModificationService.getInstance().prepareFileForWrite(expression.getContainingFile())) return;
  PsiJavaCodeReferenceElement classReference = expression.getClassReference();
  expression.getQualifier().delete();
  if (aClass != null && classReference != null) {
    classReference.bindToElement(aClass);
  }
}
项目:intellij-ce-playground    文件:InlineMethodDialog.java   
public InlineMethodDialog(Project project, PsiMethod method, PsiJavaCodeReferenceElement ref, Editor editor,
                          final boolean allowInlineThisOnly) {
  super(project, true, method);
  myMethod = method;
  myReferenceElement = ref;
  myEditor = editor;
  myAllowInlineThisOnly = allowInlineThisOnly;
  myInvokedOnReference = ref != null;

  setTitle(REFACTORING_NAME);
  myOccurrencesNumber = initOccurrencesNumber(method);
  init();
}
项目:intellij-ce-playground    文件:InlineLocalDialog.java   
public InlineLocalDialog(Project project, PsiVariable variable, final PsiJavaCodeReferenceElement ref, int occurrencesCount) {
  super(project, variable, ref, occurrencesCount);
  myVariable = variable;
  myInvokedOnReference = ref != null;

  setTitle(REFACTORING_NAME);
  myOccurrencesNumber = occurrencesCount;
  init();
}
项目:intellij-ce-playground    文件:PackageNamingConventionInspection.java   
@Override
public BaseInspectionVisitor buildVisitor() {
  return new BaseInspectionVisitor() {

    @Override
    public void visitPackageStatement(PsiPackageStatement statement) {
      final PsiJavaCodeReferenceElement reference = statement.getPackageReference();
      if (reference == null) {
        return;
      }
      final String text = reference.getText();
      int start = 0;
      int index = text.indexOf('.', start);
      while (index > 0) {
        final String name = text.substring(start, index);
        if (!mySettingsDelegate.isValid(name)) {
          registerErrorAtOffset(reference, start, index - start, name);
        }
        start = index + 1;
        index = text.indexOf('.', start);
      }
      final String lastName = text.substring(start);
      if (!mySettingsDelegate.isValid(lastName)) {
        registerErrorAtOffset(reference, start, lastName.length(), lastName);
      }
    }
  };
}
项目:intellij-ce-playground    文件:ThrownExceptionsPerMethodInspection.java   
@Override
public void visitMethod(@NotNull PsiMethod method) {
  // note: no call to super
  if (method.getNameIdentifier() == null) {
    return;
  }
  final PsiReferenceList throwList = method.getThrowsList();
  final PsiJavaCodeReferenceElement[] thrownExceptions =
    throwList.getReferenceElements();
  final int exceptionCount = thrownExceptions.length;
  if (exceptionCount <= getLimit()) {
    return;
  }
  registerMethodError(method, Integer.valueOf(exceptionCount));
}
项目:polygene-java    文件:SideEffectsAnnotationDeclaredCorrectlyInspection.java   
private RemoveAnnotationValueFix( @NotNull PsiAnnotationMemberValue annotationValueToRemove,
                                  @NotNull PsiJavaCodeReferenceElement sideEffectClassReference )
{
    super( message( "side.effects.annotation.declared.correctly.fix.remove.class.reference",
                    sideEffectClassReference.getQualifiedName() ) );
    this.annotationValueToRemove = annotationValueToRemove;
}
项目:polygene-java    文件:ConcernsAnnotationDeclaredCorrectlyInspection.java   
public RemoveInvalidConcernClassReferenceFix( @NotNull PsiAnnotationMemberValue annotationValueToRemove,
                                              @NotNull PsiJavaCodeReferenceElement concernClassReference )
{
    super( message( "concerns.annotation.declared.correctly.fix.remove.concern.class.reference",
                    concernClassReference.getQualifiedName() ) );
    this.concernClassAnnotationValue = annotationValueToRemove;
}
项目:polygene-java    文件:MixinImplementsMixinType.java   
private ProblemDescriptor createProblemDescriptor( @NotNull InspectionManager manager,
                                                   @NotNull PsiAnnotationMemberValue mixinAnnotationValue,
                                                   @NotNull PsiJavaCodeReferenceElement mixinClassReference,
                                                   @NotNull String message )
{
    RemoveInvalidMixinClassReferenceFix fix = new RemoveInvalidMixinClassReferenceFix(
        mixinAnnotationValue, mixinClassReference
    );
    return manager.createProblemDescriptor( mixinAnnotationValue, message, fix, GENERIC_ERROR_OR_WARNING );
}