Java 类com.intellij.psi.impl.compiled.ClsClassImpl 实例源码

项目:hybris-integration-intellij-idea-plugin    文件:HybrisEnumLiteralItemReference.java   
@NotNull
@Override
public ResolveResult[] multiResolve(final boolean incompleteCode) {
    Project project = myElement.getProject();
    final String enumLiteralJavaModelName = myElement.getText().replaceAll("\"", "").toUpperCase();

    final PsiShortNamesCache psiShortNamesCache = PsiShortNamesCache.getInstance(project);
    final PsiField[] javaEnumLiteralFields = psiShortNamesCache.getFieldsByName(
        enumLiteralJavaModelName, GlobalSearchScope.allScope(project)
    );

    final Set<PsiField> enumFields = stream(javaEnumLiteralFields)
        .filter(literal -> literal.getParent() != null)
        .filter(literal -> literal.getParent() instanceof ClsClassImpl)
        .filter(literal -> ((ClsClassImpl) literal.getParent()).isEnum())
        .collect(Collectors.toSet());

    return PsiElementResolveResult.createResults(enumFields);
}
项目:intellij-ce-playground    文件:JavaPsiImplementationHelperImpl.java   
@NotNull
@Override
public PsiElement getClsFileNavigationElement(PsiJavaFile clsFile) {
  PsiClass[] classes = clsFile.getClasses();
  if (classes.length == 0) return clsFile;

  String sourceFileName = ((ClsClassImpl)classes[0]).getSourceFileName();
  String packageName = clsFile.getPackageName();
  String relativePath = packageName.isEmpty() ? sourceFileName : packageName.replace('.', '/') + '/' + sourceFileName;

  ProjectFileIndex index = ProjectFileIndex.SERVICE.getInstance(clsFile.getProject());
  for (OrderEntry orderEntry : index.getOrderEntriesForFile(clsFile.getContainingFile().getVirtualFile())) {
    if (!(orderEntry instanceof LibraryOrSdkOrderEntry)) continue;
    for (VirtualFile root : orderEntry.getFiles(OrderRootType.SOURCES)) {
      VirtualFile source = root.findFileByRelativePath(relativePath);
      if (source != null && source.isValid()) {
        PsiFile psiSource = clsFile.getManager().findFile(source);
        if (psiSource instanceof PsiClassOwner) {
          return psiSource;
        }
      }
    }
  }

  return clsFile;
}
项目:tools-idea    文件:JavaPsiImplementationHelperImpl.java   
@Override
public PsiElement getClsFileNavigationElement(PsiJavaFile clsFile) {
  String packageName = clsFile.getPackageName();
  PsiClass[] classes = clsFile.getClasses();
  if (classes.length == 0) return clsFile;
  String sourceFileName = ((ClsClassImpl)classes[0]).getSourceFileName();
  String relativeFilePath = packageName.isEmpty() ? sourceFileName : packageName.replace('.', '/') + '/' + sourceFileName;

  final VirtualFile vFile = clsFile.getContainingFile().getVirtualFile();
  ProjectFileIndex projectFileIndex = ProjectFileIndex.SERVICE.getInstance(clsFile.getProject());
  final List<OrderEntry> orderEntries = projectFileIndex.getOrderEntriesForFile(vFile);
  for (OrderEntry orderEntry : orderEntries) {
    VirtualFile[] files = orderEntry.getFiles(OrderRootType.SOURCES);
    for (VirtualFile file : files) {
      VirtualFile source = file.findFileByRelativePath(relativeFilePath);
      if (source != null) {
        PsiFile psiSource = clsFile.getManager().findFile(source);
        if (psiSource instanceof PsiClassOwner) {
          return psiSource;
        }
      }
    }
  }
  return clsFile;
}
项目:consulo-java    文件:PositionManagerImpl.java   
private PsiClass findPsiClassByName(String originalQName, @Nullable Consumer<ClsClassImpl> altClsProcessor)
{
    PsiClass psiClass = null;
    // first check alternative jre if any
    Sdk alternativeJre = myDebugProcess.getSession().getAlternativeJre();
    if(alternativeJre != null)
    {
        psiClass = findClass(myDebugProcess.getProject(), originalQName, AlternativeJreClassFinder.getSearchScope(alternativeJre));
        if(psiClass instanceof ClsClassImpl && altClsProcessor != null)
        { //try to find sources
            altClsProcessor.accept((ClsClassImpl) psiClass);
        }
    }

    if(psiClass == null)
    {
        psiClass = findClass(myDebugProcess.getProject(), originalQName, myDebugProcess.getSearchScope());
    }
    return psiClass;
}
项目:consulo-java    文件:PositionManagerImpl.java   
@Nullable
private PsiFile findAlternativeJreSourceFile(ClsClassImpl psiClass)
{
    String sourceFileName = psiClass.getSourceFileName();
    String packageName = ((PsiClassOwner) psiClass.getContainingFile()).getPackageName();
    String relativePath = packageName.isEmpty() ? sourceFileName : packageName.replace('.', '/') + '/' + sourceFileName;
    Sdk alternativeJre = myDebugProcess.getSession().getAlternativeJre();

    if(alternativeJre != null)
    {
        for(VirtualFile file : AlternativeJreClassFinder.getSourceRoots(alternativeJre))
        {
            VirtualFile source = file.findFileByRelativePath(relativePath);
            if(source != null && source.isValid())
            {
                PsiFile psiSource = psiClass.getManager().findFile(source);
                if(psiSource instanceof PsiClassOwner)
                {
                    return psiSource;
                }
            }
        }
    }
    return null;
}
项目:intellij-ce-playground    文件:CollectClassMembersUtil.java   
private static boolean processCyclicDependence(PsiClass aClass, Set<PsiClass> classes) {
  if (!classes.add(aClass)) {
    return aClass.isInterface() || CommonClassNames.JAVA_LANG_OBJECT.equals(aClass.getQualifiedName());
  }

  if (aClass instanceof ClsClassImpl) return true; //optimization

  for (PsiClass psiClass : aClass.getSupers()) {
    if (!processCyclicDependence(psiClass, classes)) {
      return false;
    }
  }
  return true;
}
项目:intellij-ce-playground    文件:GrTraitUtil.java   
@Contract("null -> false")
public static boolean isTrait(@Nullable PsiClass containingClass) {
  return containingClass instanceof GrTypeDefinition && ((GrTypeDefinition)containingClass).isTrait()
         || containingClass instanceof ClsClassImpl
            && containingClass.isInterface()
            && AnnotationUtil.isAnnotated(containingClass, "groovy.transform.Trait", false);
}
项目:intellij-ce-playground    文件:GrTraitUtil.java   
public static PsiMethod createTraitMethodFromCompiledHelperMethod(final PsiMethod compiledMethod, final ClsClassImpl trait) {
  assert compiledMethod.getParameterList().getParametersCount() > 0;

  final GrLightMethodBuilder result = new GrLightMethodBuilder(compiledMethod.getManager(), compiledMethod.getName());
  result.setOriginInfo("via @Trait");
  result.addModifier(PsiModifier.STATIC);
  for (PsiTypeParameter parameter : compiledMethod.getTypeParameters()) {
    result.getTypeParameterList().addParameter(parameter);
  }

  final PsiTypeVisitor<PsiType> corrector = createCorrector(compiledMethod, trait);

  final PsiParameter[] methodParameters = compiledMethod.getParameterList().getParameters();
  for (int i = 1; i < methodParameters.length; i++) {
    final PsiParameter originalParameter = methodParameters[i];
    final PsiType correctedType = originalParameter.getType().accept(corrector);
    result.addParameter(originalParameter.getName(), correctedType, false);
  }

  for (PsiClassType type : compiledMethod.getThrowsList().getReferencedTypes()) {
    final PsiType correctedType = type.accept(corrector);
    result.getThrowsList().addReference(correctedType instanceof PsiClassType ? (PsiClassType)correctedType : type);
  }

  {
    final PsiType originalType = compiledMethod.getReturnType();
    result.setReturnType(originalType == null ? null : originalType.accept(corrector));
  }

  final PsiClass traitSource = trait.getSourceMirrorClass();
  final PsiMethod sourceMethod = traitSource == null ? null : traitSource.findMethodBySignature(result, false);
  result.setNavigationElement(sourceMethod != null ? sourceMethod : compiledMethod);

  return result;
}
项目:intellij-ce-playground    文件:GrTraitUtil.java   
public static Collection<PsiMethod> getCompiledTraitConcreteMethods(@NotNull final ClsClassImpl trait) {
  return CachedValuesManager.getCachedValue(trait, new CachedValueProvider<Collection<PsiMethod>>() {
    @Nullable
    @Override
    public Result<Collection<PsiMethod>> compute() {
      final Collection<PsiMethod> result = ContainerUtil.newArrayList();
      doCollectCompiledTraitMethods(trait, result);
      return Result.create(result, trait);
    }
  });
}
项目:intellij    文件:BlazeSourceJarNavigationPolicy.java   
@Nullable
private Result<PsiFile> getSourceFileResult(ClsFileImpl clsFile, VirtualFile root) {
  // This code is adapted from JavaPsiImplementationHelperImpl#getClsFileNavigationElement
  PsiClass[] classes = clsFile.getClasses();
  if (classes.length == 0) {
    return null;
  }

  String sourceFileName = ((ClsClassImpl) classes[0]).getSourceFileName();
  String packageName = clsFile.getPackageName();
  String relativePath =
      packageName.isEmpty()
          ? sourceFileName
          : packageName.replace('.', '/') + '/' + sourceFileName;

  VirtualFile source = root.findFileByRelativePath(relativePath);
  if (source != null && source.isValid()) {
    // Since we have an actual source jar tracked down, use that source jar as the modification
    // tracker. This means the result will continue to be cached unless that source jar changes.
    // If we didn't find a source jar, we use a modification tracker that invalidates on every
    // Blaze sync, which is less efficient.
    PsiFile psiSource = clsFile.getManager().findFile(source);
    if (psiSource instanceof PsiClassOwner) {
      return Result.create(psiSource, source);
    }
    return Result.create(null, source);
  }

  return null;
}
项目:tools-idea    文件:CollectClassMembersUtil.java   
private static boolean processCyclicDependence(PsiClass aClass, Set<PsiClass> classes) {
  if (!classes.add(aClass)) {
    return aClass.isInterface() || CommonClassNames.JAVA_LANG_OBJECT.equals(aClass.getQualifiedName());
  }

  if (aClass instanceof ClsClassImpl) return true; //optimization

  for (PsiClass psiClass : aClass.getSupers()) {
    if (!processCyclicDependence(psiClass, classes)) {
      return false;
    }
  }
  return true;
}
项目:consulo-java    文件:JavaPsiImplementationHelperImpl.java   
@Override
public PsiElement getClsFileNavigationElement(PsiJavaFile clsFile)
{
    PsiClass[] classes = clsFile.getClasses();
    if(classes.length == 0)
    {
        return clsFile;
    }

    String sourceFileName = ((ClsClassImpl) classes[0]).getSourceFileName();
    String packageName = clsFile.getPackageName();
    String relativePath = packageName.isEmpty() ? sourceFileName : packageName.replace('.', '/') + '/' + sourceFileName;

    ProjectFileIndex index = ProjectFileIndex.SERVICE.getInstance(clsFile.getProject());
    for(OrderEntry orderEntry : index.getOrderEntriesForFile(clsFile.getContainingFile().getVirtualFile()))
    {
        if(!(orderEntry instanceof OrderEntryWithTracking))
        {
            continue;
        }
        for(VirtualFile root : orderEntry.getFiles(SourcesOrderRootType.getInstance()))
        {
            VirtualFile source = root.findFileByRelativePath(relativePath);
            if(source != null && source.isValid())
            {
                PsiFile psiSource = clsFile.getManager().findFile(source);
                if(psiSource instanceof PsiClassOwner)
                {
                    return psiSource;
                }
            }
        }
    }

    return clsFile;
}
项目:codehelper.generator    文件:AutoCodingAction.java   
public void actionPerformed(AnActionEvent event) {
        String projectPath = StringUtils.EMPTY;
        try {
            //todo need check if need module.
            UserConfigService.loadUserConfig(ProjectHelper.getProjectPath(event));
            projectPath = ProjectHelper.getProjectPath(event);
            Project project = event.getProject();
            Editor editor = event.getData(LangDataKeys.EDITOR);
            PsiFile currentFile = event.getData(LangDataKeys.PSI_FILE);
            CaretModel caretModel = editor.getCaretModel();
            LogicalPosition oldLogicPos = caretModel.getLogicalPosition();
            String text = currentFile.getText();
            List<String> lines = Splitter.on("\n").splitToList(text);
            PojoLine pojo = getCursorLine(lines, oldLogicPos);
            PsiDirectory containingDirectory = currentFile.getContainingDirectory();
//            HintManager.getInstance().showInformationHint(editor,"success");
            String dir = containingDirectory.getVirtualFile().getCanonicalPath() + GenCodeResponseHelper.getPathSplitter() + currentFile.getName();
            AutoCodingRequest request = new AutoCodingRequest();
            request.setRequestType("AutoCoding");
            request.setCodingType("Setter");
            ServerRequestHelper.fillCommonField(request);
            if (pojo != null) {
                request.setPojoName(pojo.getClassName());
                LogicalPosition newStatementPos = new LogicalPosition(pojo.getLineNumber() , pojo.getLineStartPos() + 1);
                LogicalPosition insertPos = new LogicalPosition(pojo.getLineNumber() + 1 , 0 );
                caretModel.moveToLogicalPosition(newStatementPos);
                PsiElement currentFileElement = event.getData(LangDataKeys.PSI_ELEMENT);
                if (currentFileElement instanceof PsiClassImpl || currentFileElement instanceof ClsClassImpl) {
                    //                    Integer trueOffSet = getOffset(pojo, dir);
                    //                    if(trueOffSet != 0){
                    //                       offset = trueOffSet;
                    //                    }
                    Document document = PsiDocumentManager.getInstance(event.getProject()).getDocument(currentFile);
                    caretModel.moveToLogicalPosition(insertPos);
                    Integer offset = caretModel.getOffset();
                    String insert = insertSetter(project, pojo, document, currentFileElement, offset);
                    request.setInsert(insert);
//                    SettingService.getSetting().setLastInsertPos(offset);
//                    SettingService.getSetting().setLastInsertLength(setter.length());
                }
            }
//            VirtualFileManager.getInstance().syncRefresh();
//            ApplicationManager.getApplication().saveAll();

            caretModel.moveToLogicalPosition(oldLogicPos);
            SendToServerService.post(project,request);
        } catch (Throwable ignored) {
            LOGGER.error("actionPerformed :{}", ignored);
        }finally {
            LoggerWrapper.saveAllLogs(projectPath);
            SettingService.updateLastRunTime();
        }

    }