use of com.intellij.psi.PsiJavaFile in project intellij-community by JetBrains.
the class ChainCompletionMethodCallLookupElement method handleInsert.
@Override
public void handleInsert(final InsertionContext context) {
super.handleInsert(context);
if (!myMergedOverloads || isUniqueMethod(myMethod)) {
context.commitDocument();
context.getDocument().insertString(context.getTailOffset() - 1, ChainCompletionLookupElementUtil.fillMethodParameters(myMethod, myReplaceElements));
final PsiFile file = context.getFile();
assert file instanceof PsiJavaFile;
final PsiJavaFile javaFile = (PsiJavaFile) file;
if (myReplaceElements != null) {
myReplaceElements.forEachValue(new TObjectProcedure<SubLookupElement>() {
@Override
public boolean execute(final SubLookupElement subLookupElement) {
subLookupElement.doImport(javaFile);
return true;
}
});
}
context.commitDocument();
context.getEditor().getCaretModel().moveToOffset(context.getTailOffset());
context.commitDocument();
}
}
use of com.intellij.psi.PsiJavaFile in project intellij-community by JetBrains.
the class SaveJavaAsTemplateHandler method getTemplateText.
@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;
}
use of com.intellij.psi.PsiJavaFile in project intellij-community by JetBrains.
the class AnalysisScopeRule method getData.
@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;
}
use of com.intellij.psi.PsiJavaFile in project intellij-community by JetBrains.
the class CurrentPackageMacro method calculateResult.
@Override
public Result calculateResult(@NotNull Expression[] params, ExpressionContext context) {
Project project = context.getProject();
PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(context.getEditor().getDocument());
if (!(file instanceof PsiJavaFile))
return new TextResult("");
return new TextResult(((PsiJavaFile) file).getPackageName());
}
use of com.intellij.psi.PsiJavaFile in project intellij-community by JetBrains.
the class PackageNode method canSelectInLeftTree.
@Override
public boolean canSelectInLeftTree(final Map<PsiFile, Set<PsiFile>> deps) {
Set<PsiFile> files = deps.keySet();
String packageName = myPackageQName;
for (PsiFile file : files) {
if (file instanceof PsiJavaFile && Comparing.equal(packageName, ((PsiJavaFile) file).getPackageName())) {
return true;
}
}
return false;
}
Aggregations