Java 类com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl 实例源码

项目:manifold-ij    文件:ExtensionClassAnnotator.java   
private void verifyExtensionInterfaces( PsiElement element, AnnotationHolder holder )
{
  if( element instanceof PsiJavaCodeReferenceElementImpl &&
      ((PsiJavaCodeReferenceElementImpl)element).getTreeParent() instanceof ReferenceListElement &&
      ((PsiJavaCodeReferenceElementImpl)element).getTreeParent().getText().startsWith( PsiKeyword.IMPLEMENTS ) )
  {
    final PsiElement resolve = element.getReference().resolve();
    if( resolve instanceof PsiExtensibleClass )
    {
      PsiExtensibleClass iface = (PsiExtensibleClass)resolve;
      if( !isStructuralInterface( iface ) )
      {
        TextRange range = new TextRange( element.getTextRange().getStartOffset(),
                                         element.getTextRange().getEndOffset() );
        holder.createErrorAnnotation( range, ExtIssueMsg.MSG_ONLY_STRUCTURAL_INTERFACE_ALLOWED_HERE.get( iface.getName() ) );
      }
    }
  }
}
项目: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    文件:JavaCompletionContributor.java   
static boolean isClassNamePossible(CompletionParameters parameters) {
  boolean isSecondCompletion = parameters.getInvocationCount() >= 2;

  PsiElement position = parameters.getPosition();
  if (JavaKeywordCompletion.isInstanceofPlace(position)) return false;

  final PsiElement parent = position.getParent();
  if (!(parent instanceof PsiJavaCodeReferenceElement)) return isSecondCompletion;
  if (((PsiJavaCodeReferenceElement)parent).getQualifier() != null) return isSecondCompletion;

  if (parent instanceof PsiJavaCodeReferenceElementImpl &&
      ((PsiJavaCodeReferenceElementImpl)parent).getKind(parent.getContainingFile()) == PsiJavaCodeReferenceElementImpl.PACKAGE_NAME_KIND) {
    return false;
  }

  PsiElement grand = parent.getParent();
  if (grand instanceof PsiSwitchLabelStatement) {
    return false;
  }

  if (psiElement().inside(PsiImportStatement.class).accepts(parent)) {
    return isSecondCompletion;
  }

  if (grand instanceof PsiAnonymousClass) {
    grand = grand.getParent();
  }
  if (grand instanceof PsiNewExpression && ((PsiNewExpression)grand).getQualifier() != null) {
    return false;
  }

  if (JavaKeywordCompletion.isAfterPrimitiveOrArrayType(position)) {
    return false;
  }

  return true;
}
项目:tools-idea    文件: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;
}
项目:tools-idea    文件: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;
}
项目:tools-idea    文件:JavaCompletionContributor.java   
static boolean isClassNamePossible(CompletionParameters parameters) {
  boolean isSecondCompletion = parameters.getInvocationCount() >= 2;

  PsiElement position = parameters.getPosition();
  if (JavaCompletionData.isInstanceofPlace(position)) return false;

  final PsiElement parent = position.getParent();
  if (!(parent instanceof PsiJavaCodeReferenceElement)) return isSecondCompletion;
  if (((PsiJavaCodeReferenceElement)parent).getQualifier() != null) return isSecondCompletion;

  if (parent instanceof PsiJavaCodeReferenceElementImpl &&
      ((PsiJavaCodeReferenceElementImpl)parent).getKind() == PsiJavaCodeReferenceElementImpl.PACKAGE_NAME_KIND) {
    return false;
  }

  PsiElement grand = parent.getParent();
  if (grand instanceof PsiSwitchLabelStatement) {
    return false;
  }

  if (psiElement().inside(PsiImportStatement.class).accepts(parent)) {
    return isSecondCompletion;
  }

  if (grand instanceof PsiAnonymousClass) {
    grand = grand.getParent();
  }
  if (grand instanceof PsiNewExpression && ((PsiNewExpression)grand).getQualifier() != null) {
    return false;
  }

  if (JavaCompletionData.isAfterPrimitiveOrArrayType(position)) {
    return false;
  }

  return true;
}
项目:consulo-java    文件: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;
}
项目:consulo-java    文件: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    文件:PsiClassReferenceListStubImpl.java   
@Override
public PsiClassType[] getReferencedTypes() {
  if (myTypes != null) return myTypes;
  if (myNames.length == 0) {
    myTypes = PsiClassType.EMPTY_ARRAY;
    return myTypes;
  }

  PsiClassType[] types = new PsiClassType[myNames.length];

  final boolean compiled = ((JavaClassReferenceListElementType)getStubType()).isCompiled(this);
  if (compiled) {
    for (int i = 0; i < types.length; i++) {
      types[i] = new PsiClassReferenceType(new ClsJavaCodeReferenceElementImpl(getPsi(), StringRef.toString(myNames[i])), null);
    }
  }
  else {
    final PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();

    int nullCount = 0;
    final PsiReferenceList psi = getPsi();
    for (int i = 0; i < types.length; i++) {
      PsiElement context = psi;
      if (getParentStub() instanceof PsiClassStub) {
        context = ((PsiClassImpl)getParentStub().getPsi()).calcBasesResolveContext(PsiNameHelper.getShortClassName(StringRef.toString(myNames[i])), psi);
      }

      try {
        final PsiJavaCodeReferenceElement ref = factory.createReferenceFromText(StringRef.toString(myNames[i]), context);
        ((PsiJavaCodeReferenceElementImpl)ref).setKindWhenDummy(PsiJavaCodeReferenceElementImpl.CLASS_NAME_KIND);
        types[i] = factory.createType(ref);
      }
      catch (IncorrectOperationException e) {
        types[i] = null;
        nullCount++;
      }
    }

    if (nullCount > 0) {
      PsiClassType[] newTypes = new PsiClassType[types.length - nullCount];
      int cnt = 0;
      for (PsiClassType type : types) {
        if (type != null) newTypes[cnt++] = type;
      }
      types = newTypes;
    }
  }

  myTypes = types;
  return types;
}
项目:intellij-ce-playground    文件:ResolveClassUtil.java   
@Nullable
public static PsiClass resolveClass(@NotNull PsiJavaCodeReferenceElement ref, @NotNull PsiFile containingFile) {
  if (ref instanceof PsiJavaCodeReferenceElementImpl &&
      ((PsiJavaCodeReferenceElementImpl)ref).getKind(containingFile) == PsiJavaCodeReferenceElementImpl.CLASS_IN_QUALIFIED_NEW_KIND) {
    PsiElement parent = ref.getParent();
    if (parent instanceof PsiAnonymousClass){
      parent = parent.getParent();
    }
    PsiExpression qualifier;
    if (parent instanceof PsiNewExpression){
      qualifier = ((PsiNewExpression)parent).getQualifier();
      LOG.assertTrue(qualifier != null);
    }
    else if (parent instanceof PsiJavaCodeReferenceElement){
      return null;
    }
    else{
      LOG.assertTrue(false);
      return null;
    }

    PsiType qualifierType = qualifier.getType();
    if (qualifierType == null) return null;
    if (!(qualifierType instanceof PsiClassType)) return null;
    PsiClass qualifierClass = PsiUtil.resolveClassInType(qualifierType);
    if (qualifierClass == null) return null;
    String name = ref.getText();
    return qualifierClass.findInnerClassByName(name, true);
  }

  final PsiElement classNameElement = ref.getReferenceNameElement();
  if (!(classNameElement instanceof PsiIdentifier)) return null;
  String className = classNameElement.getText();

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

  ClassResolverProcessor processor = new ClassResolverProcessor(className, ref, containingFile);
  PsiScopesUtil.resolveAndWalk(processor, ref, null);


  /*
  long time2 = System.currentTimeMillis();
  Statistics.resolveClassTime += (time2 - time1);
  Statistics.resolveClassCount++;
  */

  return processor.getResult().length == 1 ? (PsiClass)processor.getResult()[0].getElement() : null;
}
项目:tools-idea    文件:PsiClassReferenceListStubImpl.java   
@Override
public PsiClassType[] getReferencedTypes() {
  if (myTypes != null) return myTypes;
  if (myNames.length == 0) {
    myTypes = PsiClassType.EMPTY_ARRAY;
    return myTypes;
  }

  PsiClassType[] types = new PsiClassType[myNames.length];

  final boolean compiled = ((JavaClassReferenceListElementType)getStubType()).isCompiled(this);
  if (compiled) {
    for (int i = 0; i < types.length; i++) {
      types[i] = new PsiClassReferenceType(new ClsJavaCodeReferenceElementImpl(getPsi(), StringRef.toString(myNames[i])), null);
    }
  }
  else {
    final PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();

    int nullCount = 0;
    final PsiReferenceList psi = getPsi();
    for (int i = 0; i < types.length; i++) {
      PsiElement context = psi;
      if (getParentStub() instanceof PsiClassStub) {
        context = ((PsiClassImpl)getParentStub().getPsi()).calcBasesResolveContext(PsiNameHelper.getShortClassName(StringRef.toString(myNames[i])), psi);
      }

      try {
        final PsiJavaCodeReferenceElement ref = factory.createReferenceFromText(StringRef.toString(myNames[i]), context);
        ((PsiJavaCodeReferenceElementImpl)ref).setKindWhenDummy(PsiJavaCodeReferenceElementImpl.CLASS_NAME_KIND);
        types[i] = factory.createType(ref);
      }
      catch (IncorrectOperationException e) {
        types[i] = null;
        nullCount++;
      }
    }

    if (nullCount > 0) {
      PsiClassType[] newTypes = new PsiClassType[types.length - nullCount];
      int cnt = 0;
      for (PsiClassType type : types) {
        if (type != null) newTypes[cnt++] = type;
      }
      types = newTypes;
    }
  }

  myTypes = types;
  return types;
}
项目:tools-idea    文件:ResolveClassUtil.java   
@Nullable
public static PsiClass resolveClass(PsiJavaCodeReferenceElement ref) {
  if (ref instanceof PsiJavaCodeReferenceElementImpl &&
      ((PsiJavaCodeReferenceElementImpl)ref).getKind() == PsiJavaCodeReferenceElementImpl.CLASS_IN_QUALIFIED_NEW_KIND) {
    PsiElement parent = ref.getParent();
    if (parent instanceof PsiAnonymousClass){
      parent = parent.getParent();
    }
    PsiExpression qualifier;
    if (parent instanceof PsiNewExpression){
      qualifier = ((PsiNewExpression)parent).getQualifier();
      LOG.assertTrue(qualifier != null);
    }
    else if (parent instanceof PsiJavaCodeReferenceElement){
      return null;
    }
    else{
      LOG.assertTrue(false);
      return null;
    }

    PsiType qualifierType = qualifier.getType();
    if (qualifierType == null) return null;
    if (!(qualifierType instanceof PsiClassType)) return null;
    PsiClass qualifierClass = PsiUtil.resolveClassInType(qualifierType);
    if (qualifierClass == null) return null;
    String name = ref.getText();
    return qualifierClass.findInnerClassByName(name, true);
  }

  final PsiElement classNameElement = ref.getReferenceNameElement();
  if (!(classNameElement instanceof PsiIdentifier)) return null;
  String className = classNameElement.getText();

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

  ClassResolverProcessor processor = new ClassResolverProcessor(className, ref, ref.getContainingFile());
  PsiScopesUtil.resolveAndWalk(processor, ref, null);


  /*
  long time2 = System.currentTimeMillis();
  Statistics.resolveClassTime += (time2 - time1);
  Statistics.resolveClassCount++;
  */

  return processor.getResult().length == 1 ? (PsiClass)processor.getResult()[0].getElement() : null;
}
项目:consulo-java    文件:PsiClassReferenceListStubImpl.java   
@NotNull
@Override
public PsiClassType[] getReferencedTypes()
{
    if(myTypes != null)
    {
        return myTypes;
    }

    if(myNames.length == 0)
    {
        myTypes = PsiClassType.EMPTY_ARRAY;
        return myTypes;
    }

    PsiClassType[] types = new PsiClassType[myNames.length];

    final boolean compiled = ((JavaClassReferenceListElementType) getStubType()).isCompiled(this);
    if(compiled)
    {
        for(int i = 0; i < types.length; i++)
        {
            types[i] = new PsiClassReferenceType(new ClsJavaCodeReferenceElementImpl(getPsi(), myNames[i]), null);
        }
    }
    else
    {
        final PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();

        int nullCount = 0;
        final PsiReferenceList psi = getPsi();
        for(int i = 0; i < types.length; i++)
        {
            try
            {
                final PsiJavaCodeReferenceElement ref = factory.createReferenceFromText(myNames[i], psi);
                ((PsiJavaCodeReferenceElementImpl) ref).setKindWhenDummy(PsiJavaCodeReferenceElementImpl.CLASS_NAME_KIND);
                types[i] = factory.createType(ref);
            }
            catch(IncorrectOperationException e)
            {
                types[i] = null;
                nullCount++;
            }
        }

        if(nullCount > 0)
        {
            PsiClassType[] newTypes = new PsiClassType[types.length - nullCount];
            int cnt = 0;
            for(PsiClassType type : types)
            {
                if(type != null)
                {
                    newTypes[cnt++] = type;
                }
            }
            types = newTypes;
        }
    }

    myTypes = types;
    return types.clone();
}
项目:consulo-java    文件:ResolveClassUtil.java   
@Nullable
public static PsiClass resolveClass(@NotNull PsiJavaCodeReferenceElement ref, @NotNull PsiFile containingFile)
{
    if(ref instanceof PsiJavaCodeReferenceElementImpl && ((PsiJavaCodeReferenceElementImpl) ref).getKind(containingFile) == PsiJavaCodeReferenceElementImpl.CLASS_IN_QUALIFIED_NEW_KIND)
    {
        PsiElement parent = ref.getParent();
        if(parent instanceof PsiAnonymousClass)
        {
            parent = parent.getParent();
        }
        PsiExpression qualifier;
        if(parent instanceof PsiNewExpression)
        {
            qualifier = ((PsiNewExpression) parent).getQualifier();
            LOG.assertTrue(qualifier != null);
        }
        else if(parent instanceof PsiJavaCodeReferenceElement)
        {
            return null;
        }
        else
        {
            LOG.assertTrue(false);
            return null;
        }

        PsiType qualifierType = qualifier.getType();
        if(qualifierType == null)
        {
            return null;
        }
        if(!(qualifierType instanceof PsiClassType))
        {
            return null;
        }
        PsiClass qualifierClass = PsiUtil.resolveClassInType(qualifierType);
        if(qualifierClass == null)
        {
            return null;
        }
        String name = ref.getText();
        return qualifierClass.findInnerClassByName(name, true);
    }

    final PsiElement classNameElement = ref.getReferenceNameElement();
    if(!(classNameElement instanceof PsiIdentifier))
    {
        return null;
    }
    String className = classNameElement.getText();

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

    ClassResolverProcessor processor = new ClassResolverProcessor(className, ref, containingFile);
    PsiScopesUtil.resolveAndWalk(processor, ref, null);


   /*
   long time2 = System.currentTimeMillis();
   Statistics.resolveClassTime += (time2 - time1);
   Statistics.resolveClassCount++;
   */

    return processor.getResult().length == 1 ? (PsiClass) processor.getResult()[0].getElement() : null;
}
项目:consulo-java    文件:JavaCompletionContributor.java   
static boolean isClassNamePossible(CompletionParameters parameters)
{
    boolean isSecondCompletion = parameters.getInvocationCount() >= 2;

    PsiElement position = parameters.getPosition();
    if(JavaKeywordCompletion.isInstanceofPlace(position) || JavaMemberNameCompletionContributor.INSIDE_TYPE_PARAMS_PATTERN.accepts(position))
    {
        return false;
    }

    final PsiElement parent = position.getParent();
    if(!(parent instanceof PsiJavaCodeReferenceElement))
    {
        return isSecondCompletion;
    }
    if(((PsiJavaCodeReferenceElement) parent).getQualifier() != null)
    {
        return isSecondCompletion;
    }

    if(parent instanceof PsiJavaCodeReferenceElementImpl && ((PsiJavaCodeReferenceElementImpl) parent).getKind(parent.getContainingFile()) == PsiJavaCodeReferenceElementImpl.PACKAGE_NAME_KIND)
    {
        return false;
    }

    PsiElement grand = parent.getParent();
    if(grand instanceof PsiSwitchLabelStatement)
    {
        return false;
    }

    if(psiElement().inside(PsiImportStatement.class).accepts(parent))
    {
        return isSecondCompletion;
    }

    if(grand instanceof PsiAnonymousClass)
    {
        grand = grand.getParent();
    }
    if(grand instanceof PsiNewExpression && ((PsiNewExpression) grand).getQualifier() != null)
    {
        return false;
    }

    if(JavaKeywordCompletion.isAfterPrimitiveOrArrayType(position))
    {
        return false;
    }

    return true;
}