当前位置: 首页>>代码示例>>Java>>正文


Java PsiJavaFile.getPackageName方法代码示例

本文整理汇总了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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:SaveJavaAsTemplateHandler.java

示例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;
}
 
开发者ID:cumtping,项目名称:Androud-Studio-Plugin---CodeGenerator,代码行数:11,代码来源:ActionUtils.java

示例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();
}
 
开发者ID:getgauge,项目名称:Intellij-Plugin,代码行数:8,代码来源:FileManager.java

示例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);
    }
}
 
开发者ID:resios,项目名称:jacoco-coverage,代码行数:30,代码来源:AnnotateFileWithCoverageAction.java

示例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;
}
 
开发者ID:krasa,项目名称:MavenHelper,代码行数:12,代码来源:RunTestFileAction.java

示例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;
}
 
开发者ID:krasa,项目名称:MavenHelper,代码行数:15,代码来源:RunTestFileAction.java

示例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);
		}
	}
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:32,代码来源:JavadocGeneratorRunProfile.java

示例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();
}
 
开发者ID:mcxtzhang,项目名称:mvp-code-creator,代码行数:12,代码来源:Utils.java


注:本文中的com.intellij.psi.PsiJavaFile.getPackageName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。