本文整理汇总了Java中com.intellij.psi.PsiPackageStatement类的典型用法代码示例。如果您正苦于以下问题:Java PsiPackageStatement类的具体用法?Java PsiPackageStatement怎么用?Java PsiPackageStatement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PsiPackageStatement类属于com.intellij.psi包,在下文中一共展示了PsiPackageStatement类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getOrCreatePackageInfoFile
import com.intellij.psi.PsiPackageStatement; //导入依赖的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.PsiPackageStatement; //导入依赖的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: registerTopLevelSem
import com.intellij.psi.PsiPackageStatement; //导入依赖的package包/类
public <T extends PsiModifierListOwner> void registerTopLevelSem(SemRegistrar registrar, final ElementPattern<? extends T> parentPattern, final JamMemberMeta<T,?> parentMeta) {
final boolean isPackage = parentMeta instanceof JamPackageMeta;
final PsiAnnotationPattern annoPattern = myAnnoNamePattern.withSuperParent(
2, isPackage ? PACKAGE_STATEMENT.with(new PatternCondition<PsiPackageStatement>("package") {
@Override
public boolean accepts(@NotNull PsiPackageStatement psiPackageStatement, ProcessingContext context) {
return parentPattern.accepts(psiPackageStatement.getPackageReference().resolve(), context);
}
}) : parentPattern);
registrar.registerSemElementProvider(myMetaKey, annoPattern, annotation -> {
final PsiElement parent = annotation.getParent().getParent();
final T element = (isPackage && parent instanceof PsiPackageStatement? (T)((PsiPackageStatement)parent).getPackageReference().resolve() : (T)parent);
if (element != null && SemService.getSemService(annotation.getProject()).getSemElement(parentMeta.getMetaKey(), element) == parentMeta) {
return this;
}
return null;
});
registerChildren(registrar, annoPattern);
}
开发者ID:consulo,项目名称:consulo-javaee,代码行数:21,代码来源:JamAnnotationMeta.java
示例4: hackAwayEmptyPackage
import com.intellij.psi.PsiPackageStatement; //导入依赖的package包/类
static void hackAwayEmptyPackage(PsiJavaFile file, FileTemplate template, Map<String, Object> props) throws IncorrectOperationException
{
if(!template.isTemplateOfType(JavaFileType.INSTANCE))
{
return;
}
String packageName = (String) props.get(FileTemplate.ATTRIBUTE_PACKAGE_NAME);
if(packageName == null || packageName.length() == 0 || packageName.equals(FileTemplate.ATTRIBUTE_PACKAGE_NAME))
{
PsiPackageStatement packageStatement = file.getPackageStatement();
if(packageStatement != null)
{
packageStatement.delete();
}
}
}
开发者ID:consulo,项目名称:consulo-java,代码行数:18,代码来源:JavaCreateFromTemplateHandler.java
示例5: buildVisitor
import com.intellij.psi.PsiPackageStatement; //导入依赖的package包/类
@Override
public BaseInspectionVisitor buildVisitor() {
return new BaseInspectionVisitor() {
@Override
public void visitPackageStatement(PsiPackageStatement statement) {
final PsiJavaCodeReferenceElement reference = statement.getPackageReference();
if (reference == null) {
return;
}
final String text = reference.getText();
int start = 0;
int index = text.indexOf('.', start);
while (index > 0) {
final String name = text.substring(start, index);
if (!mySettingsDelegate.isValid(name)) {
registerErrorAtOffset(reference, start, index - start, name);
}
start = index + 1;
index = text.indexOf('.', start);
}
final String lastName = text.substring(start);
if (!mySettingsDelegate.isValid(lastName)) {
registerErrorAtOffset(reference, start, lastName.length(), lastName);
}
}
};
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:29,代码来源:PackageNamingConventionInspection.java
示例6: applyFix
import com.intellij.psi.PsiPackageStatement; //导入依赖的package包/类
@Override
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
PsiElement element = descriptor.getPsiElement();
if (element == null) return;
PsiFile myFile = element.getContainingFile();
if (!FileModificationService.getInstance().prepareFileForWrite(myFile)) return;
PsiDirectory directory = myFile.getContainingDirectory();
if (directory == null) return;
PsiJavaPackage myTargetPackage = JavaDirectoryService.getInstance().getPackage(directory);
if (myTargetPackage == null) return;
try {
PsiElementFactory factory = JavaPsiFacade.getInstance(myFile.getProject()).getElementFactory();
PsiPackageStatement myStatement = ((PsiJavaFile)myFile).getPackageStatement();
if (myTargetPackage.getQualifiedName().length() == 0) {
if (myStatement != null) {
myStatement.delete();
}
}
else {
final PsiPackageStatement packageStatement = factory.createPackageStatement(myTargetPackage.getQualifiedName());
if (myStatement != null) {
myStatement.getPackageReference().replace(packageStatement.getPackageReference());
}
else {
myFile.addAfter(packageStatement, null);
}
}
}
catch (IncorrectOperationException e) {
LOG.error(e);
}
}
开发者ID:consulo,项目名称:consulo-java,代码行数:36,代码来源:AdjustPackageNameFix.java
示例7: visitPackageStatement
import com.intellij.psi.PsiPackageStatement; //导入依赖的package包/类
@Override
public void visitPackageStatement(PsiPackageStatement statement) {
mVisitor.report("PsiPackageStatement", statement.getText(), statement);
super.visitElement(statement);
}
开发者ID:cch-robo,项目名称:Android_Lint_SRP_Practice_Example,代码行数:6,代码来源:PsiClassStructureDetector.java
注:本文中的com.intellij.psi.PsiPackageStatement类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论