本文整理汇总了Java中com.intellij.psi.PsiJavaFile.getPackageName方法的典型用法代码示例。如果您正苦于以下问题:Java PsiJavaFile.getPackageName方法的具体用法?Java PsiJavaFile.getPackageName怎么用?Java PsiJavaFile.getPackageName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.PsiJavaFile
的用法示例。
在下文中一共展示了PsiJavaFile.getPackageName方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: getJavaClass
import com.intellij.psi.PsiJavaFile; //导入方法依赖的package包/类
public static String getJavaClass(final PsiClass psiClass) {
if (psiClass == null) {
return null;
}
if (psiClass.getContainingFile() instanceof PsiJavaFile) {
PsiJavaFile javaFile = (PsiJavaFile) psiClass.getContainingFile();
return javaFile.getPackageName() + "." + javaFile.getName().replace(".java", "");
}
return null;
}
示例3: getJavaFileName
import com.intellij.psi.PsiJavaFile; //导入方法依赖的package包/类
public static String getJavaFileName(PsiFile value) {
PsiJavaFile javaFile = (PsiJavaFile) value;
if (!javaFile.getPackageName().equals("")) {
return javaFile.getPackageName() + "." + javaFile.getName();
}
return javaFile.getName();
}
示例4: showCoverageForFile
import com.intellij.psi.PsiJavaFile; //导入方法依赖的package包/类
private void showCoverageForFile(PsiJavaFile javaFile, AnActionEvent e, Project project) {
VirtualFile virtualFile = javaFile.getVirtualFile();
if (virtualFile == null) {
Notifications.Bus.notify(getMissingFileNotification(virtualFile), project);
return;
}
Module module = ModuleUtil.findModuleForFile(virtualFile, project);
if(module == null){
return;
}
File coverageRootPath = CoverageUtils.getCoverageReportRoot(module, project);
if (coverageRootPath.exists()) {
String packageName = javaFile.getPackageName();
File url = new File(coverageRootPath, packageName);
boolean wasFound = false;
url = new File(url, virtualFile.getName() + ".html");
if (url.exists()) {
BrowserUtil.launchBrowser(url.toURI().getPath());
wasFound = true;
}
if (!wasFound) {
Notifications.Bus.notify(getMissingFileNotification(virtualFile), project);
}
} else {
Notifications.Bus.notify(getMissingReportNotification(e), project);
}
}
示例5: getPsiFilePath
import com.intellij.psi.PsiJavaFile; //导入方法依赖的package包/类
@NotNull
private String getPsiFilePath(PsiJavaFile psiFile) {
String packageName = psiFile.getPackageName();
String fullName;
if (packageName.isEmpty()) {
fullName = psiFile.getName();
} else {
fullName = packageName.replace(".", "/") + "/" + psiFile.getVirtualFile().getName();
}
return fullName;
}
示例6: getTestArgument
import com.intellij.psi.PsiJavaFile; //导入方法依赖的package包/类
protected String getTestArgument(AnActionEvent e, PsiJavaFile psiFile) {
final ConfigurationContext context = ConfigurationContext.getFromContext(e.getDataContext());
RunnerAndConfigurationSettings configuration = context.getConfiguration();
String classAndMethod = configuration.getName().replace(".", "#");
String result;
String packageName = psiFile.getPackageName();
if (StringUtils.isNotBlank(packageName)) {
result = packageName + "." + classAndMethod;
} else {
result = classAndMethod;
}
return result;
}
示例7: visitFile
import com.intellij.psi.PsiJavaFile; //导入方法依赖的package包/类
@Override
public void visitFile(PsiFile file)
{
final VirtualFile fileOrDir = file.getVirtualFile();
if(fileOrDir == null)
{
return;
}
if(!fileOrDir.isInLocalFileSystem())
{
return;
}
final Module module = ModuleUtilCore.findModuleForFile(fileOrDir, myPsiManager.getProject());
if(module != null)
{
myModules.add(module);
}
if(file instanceof PsiJavaFile)
{
final PsiJavaFile javaFile = (PsiJavaFile) file;
final String packageName = javaFile.getPackageName();
if(containsPackagePrefix(module, packageName) || (packageName.length() == 0 && !(javaFile instanceof ServerPageFile)) || !myUsePackageNotation)
{
mySourceFiles.add(FileUtil.toSystemIndependentName(fileOrDir.getPath()));
}
else
{
myPackages.add(packageName);
}
}
}
示例8: visitMethod
import com.intellij.psi.PsiJavaFile; //导入方法依赖的package包/类
@Override
public void visitMethod(@NotNull PsiMethod method) {
final PsiClass aClass = method.getContainingClass();
if (aClass == null) {
return;
}
if (method.getNameIdentifier() == null) {
return;
}
PsiClass ancestorClass = aClass.getSuperClass();
final Set<PsiClass> visitedClasses = new HashSet<PsiClass>();
while (ancestorClass != null) {
if (!visitedClasses.add(ancestorClass)) {
return;
}
final PsiMethod overridingMethod =
ancestorClass.findMethodBySignature(method, true);
if (overridingMethod != null) {
if (overridingMethod.hasModifierProperty(
PsiModifier.PACKAGE_LOCAL)) {
final PsiJavaFile file =
PsiTreeUtil.getParentOfType(aClass,
PsiJavaFile.class);
if (file == null) {
return;
}
final PsiJavaFile ancestorFile =
PsiTreeUtil.getParentOfType(ancestorClass,
PsiJavaFile.class);
if (ancestorFile == null) {
return;
}
final String packageName = file.getPackageName();
final String ancestorPackageName =
ancestorFile.getPackageName();
if (!packageName.equals(ancestorPackageName)) {
registerMethodError(method);
return;
}
}
}
ancestorClass = ancestorClass.getSuperClass();
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:45,代码来源:MethodOverridesPackageLocalMethodInspectionBase.java
示例9: getPkgName
import com.intellij.psi.PsiJavaFile; //导入方法依赖的package包/类
/**
* Get package name of current class.
* Like this:"com.example.helloworld"
*
* @param e
* @return
*/
public static String getPkgName(AnActionEvent e) {
PsiJavaFile javaFile = (PsiJavaFile) e.getData(CommonDataKeys.PSI_FILE);
return javaFile.getPackageName();
}