本文整理汇总了Java中com.intellij.psi.PsiJavaFile类的典型用法代码示例。如果您正苦于以下问题:Java PsiJavaFile类的具体用法?Java PsiJavaFile怎么用?Java PsiJavaFile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PsiJavaFile类属于com.intellij.psi包,在下文中一共展示了PsiJavaFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getOrCreatePackageInfoFile
import com.intellij.psi.PsiJavaFile; //导入依赖的package包/类
@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;
}
开发者ID:stylismo,项目名称:nullability-annotations-inspection,代码行数:25,代码来源:AddPackageInfoWithNullabilityDefaultsFix.java
示例2: addAnnotationToPackageInfo
import com.intellij.psi.PsiJavaFile; //导入依赖的package包/类
private void addAnnotationToPackageInfo(Project project, PsiJavaFile packageInfoFile) {
if (!FileModificationService.getInstance().preparePsiElementForWrite(packageInfoFile)) {
return;
}
PsiPackageStatement packageStatement = packageInfoFile.getPackageStatement();
if (packageStatement == null) {
return;
}
PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
PsiAnnotation annotation = factory.createAnnotationFromText("@" + annotationForTypeQualifierFqn,
packageInfoFile.getContext());
PsiElement addedAnnotation = packageInfoFile.addBefore(annotation, packageStatement);
JavaCodeStyleManager.getInstance(project).shortenClassReferences(addedAnnotation);
removeRedundantAnnotationsInPackage(project, packageInfoFile.getContainingDirectory().getFiles(), annotation);
}
开发者ID:stylismo,项目名称:nullability-annotations-inspection,代码行数:19,代码来源:AddPackageInfoWithNullabilityDefaultsFix.java
示例3: buildFoldRegions
import com.intellij.psi.PsiJavaFile; //导入依赖的package包/类
@NotNull
@Override
public FoldingDescriptor[] buildFoldRegions(@NotNull PsiElement psiElement, @NotNull Document document, boolean quick) {
if (!(psiElement instanceof PsiJavaFile) || quick || !LoggerFoldingApplicationSettings.getInstance().getState()
.getCollapseByDefault()) {
return new FoldingDescriptor[0];
}
List<FoldingDescriptor> foldingDescriptors = new LinkedList<>();
Project project = psiElement.getProject();
LoggerFoldingProjectSettings.State state = LoggerFoldingProjectSettings.getInstance(project).getState();
buildFoldRegions(psiElement, foldingDescriptors, state);
return foldingDescriptors.toArray(new FoldingDescriptor[foldingDescriptors.size()]);
}
示例4: createStubForFile
import com.intellij.psi.PsiJavaFile; //导入依赖的package包/类
@NotNull
@Override
protected StubElement createStubForFile(@NotNull PsiFile file, @NotNull LighterAST tree) {
if (!(file instanceof PsiJavaFile)) {
return super.createStubForFile(file, tree);
}
String refText = "";
LighterASTNode pkg = LightTreeUtil.firstChildOfType(tree, tree.getRoot(), JavaElementType.PACKAGE_STATEMENT);
if (pkg != null) {
LighterASTNode ref = LightTreeUtil.firstChildOfType(tree, pkg, JavaElementType.JAVA_CODE_REFERENCE);
if (ref != null) {
refText = JavaSourceUtil.getReferenceText(tree, ref);
}
}
return new PsiJavaFileStubImpl((PsiJavaFile)file, StringRef.fromString(refText), false);
}
示例5: getStructureViewBuilder
import com.intellij.psi.PsiJavaFile; //导入依赖的package包/类
@Override
@Nullable
public StructureViewBuilder getStructureViewBuilder(final PsiFile psiFile) {
if (!(psiFile instanceof PsiJavaFile)) return null;
return new TreeBasedStructureViewBuilder() {
@Override
@NotNull
public StructureViewModel createStructureViewModel(@Nullable Editor editor) {
return new JavaFileTreeModel((PsiJavaFile)psiFile, editor);
}
@Override
public boolean isRootNodeShown() {
return false;
}
};
}
示例6: getData
import com.intellij.psi.PsiJavaFile; //导入依赖的package包/类
@Override
public Object getData(final DataProvider dataProvider) {
final Object psiFile = dataProvider.getData(CommonDataKeys.PSI_FILE.getName());
if (psiFile instanceof PsiJavaFile) {
return new JavaAnalysisScope((PsiJavaFile)psiFile);
}
Object psiTarget = dataProvider.getData(CommonDataKeys.PSI_ELEMENT.getName());
if (psiTarget instanceof PsiPackage) {
PsiPackage pack = (PsiPackage)psiTarget;
PsiManager manager = pack.getManager();
if (!manager.isInProject(pack)) return null;
PsiDirectory[] dirs = pack.getDirectories(GlobalSearchScope.projectScope(manager.getProject()));
if (dirs.length == 0) return null;
return new JavaAnalysisScope(pack, (Module)dataProvider.getData(LangDataKeys.MODULE.getName()));
}
return null;
}
示例7: getTemplateText
import com.intellij.psi.PsiJavaFile; //导入依赖的package包/类
@Nullable
public String getTemplateText(final PsiFile psiFile, String fileText, String nameWithoutExtension) {
if(psiFile instanceof PsiJavaFile){
PsiJavaFile javaFile = (PsiJavaFile)psiFile;
String packageName = javaFile.getPackageName();
if (packageName.length() > 0){
fileText = StringUtil.replace(fileText, packageName, "${PACKAGE_NAME}");
}
PsiClass[] classes = javaFile.getClasses();
PsiClass psiClass = null;
if((classes.length > 0)){
for (PsiClass aClass : classes) {
if (nameWithoutExtension.equals(aClass.getName())) {
psiClass = aClass;
break;
}
}
}
if(psiClass != null){
//todo[myakovlev] ? PsiIdentifier nameIdentifier = psiClass.getNameIdentifier();
return StringUtil.replace(fileText, nameWithoutExtension,"${NAME}");
}
}
return null;
}
示例8: testFoldingIsNotBlinkingOnNavigationToSingleLineMethod
import com.intellij.psi.PsiJavaFile; //导入依赖的package包/类
public void testFoldingIsNotBlinkingOnNavigationToSingleLineMethod() {
VirtualFile file = getFile("/src/Bar.java");
PsiJavaFile psiFile = (PsiJavaFile)getPsiManager().findFile(file);
assertNotNull(psiFile);
PsiMethod method = psiFile.getClasses()[0].getMethods()[0];
method.navigate(true);
FileEditor[] editors = myManager.getEditors(file);
assertEquals(1, editors.length);
Editor editor = ((TextEditor)editors[0]).getEditor();
FoldRegion[] regions = editor.getFoldingModel().getAllFoldRegions();
assertEquals(2, regions.length);
assertTrue(regions[0].isExpanded());
assertTrue(regions[1].isExpanded());
CodeInsightTestFixtureImpl.instantiateAndRun(psiFile, editor, new int[]{Pass.UPDATE_ALL, Pass.LOCAL_INSPECTIONS}, false);
regions = editor.getFoldingModel().getAllFoldRegions();
assertEquals(2, regions.length);
assertTrue(regions[0].isExpanded());
assertTrue(regions[1].isExpanded());
}
示例9: doImport
import com.intellij.psi.PsiJavaFile; //导入依赖的package包/类
@Override
public void doImport(final PsiJavaFile javaFile) {
final PsiClass containingClass = myMethod.getContainingClass();
if (containingClass != null) {
if (javaFile.findImportReferenceTo(containingClass) == null) {
javaFile.importClass(containingClass);
}
}
if (myReplaceElements != null) {
myReplaceElements.forEachValue(new TObjectProcedure<SubLookupElement>() {
@Override
public boolean execute(final SubLookupElement subLookupElement) {
subLookupElement.doImport(javaFile);
return false;
}
});
}
}
示例10: testStandardProviders
import com.intellij.psi.PsiJavaFile; //导入依赖的package包/类
public void testStandardProviders() {
final AbstractProjectViewPSIPane pane = myStructure.createPane();
getProjectTreeStructure().setProviders(new ClassesTreeStructureProvider(myProject),
new FormMergerTreeStructureProvider(myProject));
assertStructureEqual(getPackageDirectory(), "PsiDirectory: package1\n" +
" PsiClass:Class1\n" +
" PsiJavaFile:Class2.java\n" +
" PsiClass:Class2\n" +
" PsiClass:Class3\n" +
" PsiJavaFile:Class4.java\n" +
" PsiFile(plain text):Form2.form\n" +
" Form:Form1\n" +
" PsiClass:Form1\n" +
" PsiFile(plain text):Form1.form\n");
PsiClass psiClass = ((PsiJavaFile)getPackageDirectory().findFile("Form1.java")).getClasses()[0];
myStructure.checkNavigateFromSourceBehaviour(psiClass, psiClass.getContainingFile().getVirtualFile(), pane);
PsiFile psiFile = getPackageDirectory().findFile("Form1.form");
VirtualFile virtualFile = psiFile.getContainingFile().getVirtualFile();
myStructure.checkNavigateFromSourceBehaviour(psiFile, virtualFile, pane);
}
示例11: buildFix
import com.intellij.psi.PsiJavaFile; //导入依赖的package包/类
@Override
@Nullable
protected InspectionGadgetsFix buildFix(Object... infos) {
final PsiJavaFile file = (PsiJavaFile)infos[0];
final String fileName = file.getName();
final int prefixIndex = fileName.indexOf((int)'.');
final String filenameWithoutPrefix = fileName.substring(0, prefixIndex);
final PsiClass[] classes = file.getClasses();
for (PsiClass psiClass : classes) {
final String className = psiClass.getName();
if (filenameWithoutPrefix.equals(className)) {
return null;
}
}
return new RenameFix(filenameWithoutPrefix);
}
示例12: visitClass
import com.intellij.psi.PsiJavaFile; //导入依赖的package包/类
@Override
public void visitClass(@NotNull PsiClass aClass) {
// no call to super, so that it doesn't drill down to inner classes
final PsiElement parent = aClass.getParent();
if (!(parent instanceof PsiJavaFile)) {
return;
}
final PsiJavaFile file = (PsiJavaFile)parent;
final String className = aClass.getName();
if (className == null) {
return;
}
final String fileName = file.getName();
final int prefixIndex = fileName.indexOf((int)'.');
if (prefixIndex < 0) {
return;
}
final String filenameWithoutPrefix =
fileName.substring(0, prefixIndex);
if (className.equals(filenameWithoutPrefix)) {
return;
}
registerClassError(aClass, file);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:ClassNameDiffersFromFileNameInspectionBase.java
示例13: visitClass
import com.intellij.psi.PsiJavaFile; //导入依赖的package包/类
@Override
public void visitClass(@NotNull PsiClass aClass) {
// no call to super, so that it doesn't drill down to inner classes
if (!(aClass.getParent() instanceof PsiJavaFile)) {
return;
}
final PsiJavaFile file = (PsiJavaFile)aClass.getParent();
if (file == null) {
return;
}
int numClasses = 0;
final PsiElement[] children = file.getChildren();
for (final PsiElement child : children) {
if (child instanceof PsiClass) {
numClasses++;
}
}
if (numClasses <= 1) {
return;
}
registerClassError(aClass);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:MultipleTopLevelClassesInFileInspectionBase.java
示例14: collectVariables
import com.intellij.psi.PsiJavaFile; //导入依赖的package包/类
@Override
public void collectVariables(@NotNull Map<String, Object> context, Project project, Module module, @NotNull final PsiFile file) {
if (file instanceof PsiClassOwner) {
final FileInfo info = new FileInfo(file) {
@Override
public String getClassName() {
if (file instanceof PsiJavaFile) {
return ((PsiJavaFile)file).getClasses()[0].getName();
}
else {
return super.getClassName();
}
}
@Override
public String getQualifiedClassName() {
if (file instanceof PsiJavaFile) {
return ((PsiJavaFile)file).getClasses()[0].getQualifiedName();
} else {
return super.getQualifiedClassName();
}
}
};
context.put("file", info);
}
}
示例15: getSourceJarRoot
import com.intellij.psi.PsiJavaFile; //导入依赖的package包/类
@Nullable
private VirtualFile getSourceJarRoot(
Project project, BlazeProjectData blazeProjectData, PsiJavaFile clsFile) {
Library library = findLibrary(project, clsFile);
if (library == null || library.getFiles(OrderRootType.SOURCES).length != 0) {
// If the library already has sources attached, no need to hunt for them.
return null;
}
BlazeJarLibrary blazeLibrary =
LibraryActionHelper.findLibraryFromIntellijLibrary(project, blazeProjectData, library);
if (blazeLibrary == null) {
return null;
}
// TODO: If there are multiple source jars, search for one containing this PsiJavaFile.
for (ArtifactLocation jar : blazeLibrary.libraryArtifact.sourceJars) {
VirtualFile root = getSourceJarRoot(project, blazeProjectData.artifactLocationDecoder, jar);
if (root != null) {
return root;
}
}
return null;
}