本文整理汇总了Java中org.jetbrains.java.generate.psi.PsiAdapter.addImportStatement方法的典型用法代码示例。如果您正苦于以下问题:Java PsiAdapter.addImportStatement方法的具体用法?Java PsiAdapter.addImportStatement怎么用?Java PsiAdapter.addImportStatement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jetbrains.java.generate.psi.PsiAdapter
的用法示例。
在下文中一共展示了PsiAdapter.addImportStatement方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: autoImportPackages
import org.jetbrains.java.generate.psi.PsiAdapter; //导入方法依赖的package包/类
/**
* Automatic import the packages.
*
* @param packageNames names of packages (must end with .* and be separated by ; or ,)
* @throws IncorrectOperationException error adding imported package
*/
private static void autoImportPackages(PsiJavaFile psiJavaFile, String packageNames) throws IncorrectOperationException {
StringTokenizer tok = new StringTokenizer(packageNames, ",");
while (tok.hasMoreTokens()) {
String packageName = tok.nextToken().trim(); // trim in case of space
if (logger.isDebugEnabled()) logger.debug("Auto importing package: " + packageName);
PsiAdapter.addImportStatement(psiJavaFile, packageName);
}
}
示例2: autoImportPackages
import org.jetbrains.java.generate.psi.PsiAdapter; //导入方法依赖的package包/类
/**
* Automatic import the packages.
*
* @param packageNames names of packages (must end with .* and be separated by ; or ,)
* @throws IncorrectOperationException error adding imported package
*/
private static void autoImportPackages(PsiJavaFile psiJavaFile, String packageNames) throws IncorrectOperationException
{
StringTokenizer tok = new StringTokenizer(packageNames, ",");
while(tok.hasMoreTokens())
{
String packageName = tok.nextToken().trim(); // trim in case of space
if(logger.isDebugEnabled())
{
logger.debug("Auto importing package: " + packageName);
}
PsiAdapter.addImportStatement(psiJavaFile, packageName);
}
}
示例3: applyFix
import org.jetbrains.java.generate.psi.PsiAdapter; //导入方法依赖的package包/类
/**
* Add the {@link GctConstants.APP_ENGINE_ANNOTATION_NAMED} annotation to the {@link
* PsiParameter} in <code>descriptor</code>. The query name in {@link
* GctConstants.APP_ENGINE_ANNOTATION_NAMED} will be the name of the {@link PsiParameter} in
* <code>descriptor</code>. If the {@link PsiElement} in <code>descriptor</code> is not of
* {@link PsiParameter} type or if the {@link PsiParameter} in <code>descriptor</code> already
* has {@link GctConstants.APP_ENGINE_ANNOTATION_NAMED} or javax.inject.Named, no annotation
* will be added.
*/
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
PsiElement element = descriptor.getPsiElement();
if (element == null) {
return;
}
if (!(element instanceof PsiParameter)) {
return;
}
PsiParameter parameter = (PsiParameter) element;
PsiModifierList modifierList = parameter.getModifierList();
if (modifierList == null) {
return;
}
if (modifierList.findAnnotation(GctConstants.APP_ENGINE_ANNOTATION_NAMED) != null) {
return;
}
if (modifierList.findAnnotation("") != null) {
return;
}
String annotationString = "@Named(\"" + parameter.getName() + "\")";
PsiAnnotation annotation =
JavaPsiFacade.getElementFactory(project)
.createAnnotationFromText(annotationString, element);
modifierList.add(annotation);
PsiFile file = parameter.getContainingFile();
if (file == null) {
return;
}
if (!(file instanceof PsiJavaFile)) {
return;
}
PsiAdapter.addImportStatement((PsiJavaFile) file, GctConstants.APP_ENGINE_ANNOTATION_NAMED);
}