com.intellij.psi.impl.compiled.ClsClassImpl Java Examples

The following examples show how to use com.intellij.psi.impl.compiled.ClsClassImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PsiSearchUtils.java    From litho with Apache License 2.0 5 votes vote down vote up
/**
 * Searches everywhere for a java class with the specified full-qualified name and returns one if
 * it is found (excluding .class). This method might return classes out of project scope.
 *
 * @see #findClass(Project, String)
 */
@Nullable
public static PsiClass findOriginalClass(Project project, String qualifiedName) {
  return Arrays.stream(findClasses(project, qualifiedName))
      .filter(cls -> !(cls instanceof ClsClassImpl))
      .findAny()
      .orElse(null);
}
 
Example #2
Source File: BlazeSourceJarNavigationPolicy.java    From intellij with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #3
Source File: AutoCodingAction.java    From codehelper.generator with Apache License 2.0 4 votes vote down vote up
@Override
    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();
        }

    }