下面列出了怎么用com.intellij.psi.impl.compiled.ClsClassImpl的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* 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);
}
@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;
}
@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();
}
}