use of com.intellij.psi.PsiPackage in project markdown-doclet by Abnaxos.
the class MarkdownDocumentationProvider method generateDoc.
@Nullable
@Override
public String generateDoc(PsiElement element, @Nullable PsiElement originalElement) {
boolean process = false;
for (Class supported : SUPPORTED_ELEMENT_TYPES) {
if (supported.isInstance(element)) {
process = true;
break;
}
}
if (!process) {
return null;
}
PsiFile file = null;
if (element instanceof PsiDirectory) {
// let's see whether we can map the directory to a package; if so, change the
// element to the package and continue
PsiPackage pkg = JavaDirectoryService.getInstance().getPackage((PsiDirectory) element);
if (pkg != null) {
element = pkg;
} else {
return null;
}
}
if (element instanceof PsiPackage) {
for (PsiDirectory dir : ((PsiPackage) element).getDirectories()) {
PsiFile info = dir.findFile(PsiPackage.PACKAGE_INFO_FILE);
if (info != null) {
ASTNode node = info.getNode();
if (node != null) {
ASTNode docCommentNode = node.findChildByType(JavaDocElementType.DOC_COMMENT);
if (docCommentNode != null) {
// the default implementation will now use this file
// we're going to take over below, if Markdown is enabled in
// the corresponding module
// see JavaDocInfoGenerator.generatePackageJavaDoc()
file = info;
break;
}
}
}
if (dir.findFile("package.html") != null) {
// leave that to the default
return null;
}
}
} else {
if (JavaLanguage.INSTANCE.equals(element.getLanguage())) {
element = element.getNavigationElement();
if (element.getContainingFile() != null) {
file = element.getContainingFile();
}
}
}
if (file != null) {
DocCommentProcessor processor = new DocCommentProcessor(file);
if (processor.isEnabled()) {
String docHtml;
if (element instanceof PsiMethod) {
docHtml = super.generateDoc(PsiProxy.forMethod((PsiMethod) element), originalElement);
} else if (element instanceof PsiParameter) {
docHtml = super.generateDoc(PsiProxy.forParameter((PsiParameter) element), originalElement);
} else {
MarkdownJavaDocInfoGenerator javaDocInfoGenerator = new MarkdownJavaDocInfoGenerator(element.getProject(), element, processor);
List<String> docURLs = getExternalJavaDocUrl(element);
String text = javaDocInfoGenerator.generateDocInfo(docURLs);
Plugin.print("Intermediate HTML output", text);
docHtml = JavaDocExternalFilter.filterInternalDocInfo(text);
}
docHtml = extendCss(docHtml);
Plugin.print("Final HTML output", docHtml);
return docHtml;
} else {
return null;
}
} else {
return null;
}
}
use of com.intellij.psi.PsiPackage in project azure-tools-for-java by Microsoft.
the class CreateFunctionAction method invokeDialog.
@Override
protected PsiElement[] invokeDialog(Project project, PsiDirectory psiDirectory) {
final Operation operation = TelemetryManager.createOperation(TelemetryConstants.FUNCTION, TelemetryConstants.CREATE_FUNCTION_TRIGGER);
try {
operation.start();
PsiPackage pkg = JavaDirectoryService.getInstance().getPackage(psiDirectory);
// get existing package from current directory
String hintPackageName = pkg == null ? "" : pkg.getQualifiedName();
CreateFunctionForm form = new CreateFunctionForm(project, hintPackageName);
List<PsiElement> psiElements = new ArrayList<>();
if (form.showAndGet()) {
final FunctionTemplate bindingTemplate;
try {
Map<String, String> parameters = form.getTemplateParameters();
final String connectionName = parameters.get("connection");
String triggerType = form.getTriggerType();
String packageName = parameters.get("packageName");
String className = parameters.get("className");
PsiDirectory directory = ClassUtil.sourceRoot(psiDirectory);
String newName = packageName.replace('.', '/');
bindingTemplate = AzureFunctionsUtils.getFunctionTemplate(triggerType);
operation.trackProperty(TelemetryConstants.TRIGGER_TYPE, triggerType);
if (StringUtils.equalsIgnoreCase(triggerType, CreateFunctionForm.EVENT_HUB_TRIGGER)) {
if (StringUtils.isBlank(connectionName)) {
throw new AzureExecutionException(message("function.createFunction.error.connectionMissed"));
}
parameters.putIfAbsent("eventHubName", "myeventhub");
parameters.putIfAbsent("consumerGroup", "$Default");
}
final String functionClassContent = AzureFunctionsUtils.substituteParametersInTemplate(bindingTemplate, parameters);
if (StringUtils.isNotEmpty(functionClassContent)) {
AzureTaskManager.getInstance().write(() -> {
CreateFileAction.MkDirs mkDirs = ApplicationManager.getApplication().runWriteAction((Computable<CreateFileAction.MkDirs>) () -> new CreateFileAction.MkDirs(newName + '/' + className, directory));
PsiFileFactory factory = PsiFileFactory.getInstance(project);
try {
mkDirs.directory.checkCreateFile(className + ".java");
} catch (final IncorrectOperationException e) {
final String dir = mkDirs.directory.getName();
final String error = String.format("failed to create function class[%s] in directory[%s]", className, dir);
throw new AzureToolkitRuntimeException(error, e);
}
CommandProcessor.getInstance().executeCommand(project, () -> {
PsiFile psiFile = factory.createFileFromText(className + ".java", JavaFileType.INSTANCE, functionClassContent);
psiElements.add(mkDirs.directory.add(psiFile));
}, null, null);
if (StringUtils.equalsIgnoreCase(triggerType, CreateFunctionForm.EVENT_HUB_TRIGGER)) {
try {
String connectionString = form.getEventHubNamespace() == null ? DEFAULT_EVENT_HUB_CONNECTION_STRING : getEventHubNamespaceConnectionString(form.getEventHubNamespace());
AzureFunctionsUtils.applyKeyValueToLocalSettingFile(new File(project.getBasePath(), "local.settings.json"), parameters.get("connection"), connectionString);
} catch (IOException e) {
EventUtil.logError(operation, ErrorType.systemError, e, null, null);
final String error = "failed to get connection string and save to local settings";
throw new AzureToolkitRuntimeException(error, e);
}
}
});
}
} catch (AzureExecutionException e) {
AzureMessager.getMessager().error(e);
EventUtil.logError(operation, ErrorType.systemError, e, null, null);
}
}
if (!psiElements.isEmpty()) {
FileEditorManager.getInstance(project).openFile(psiElements.get(0).getContainingFile().getVirtualFile(), false);
}
return psiElements.toArray(new PsiElement[0]);
} finally {
operation.complete();
}
}
use of com.intellij.psi.PsiPackage in project azure-tools-for-java by Microsoft.
the class CreateFunctionAction method doCheckPackageExists.
private static boolean doCheckPackageExists(PsiDirectory directory) {
PsiPackage pkg = JavaDirectoryService.getInstance().getPackage(directory);
if (pkg == null) {
return false;
}
String name = pkg.getQualifiedName();
return StringUtil.isEmpty(name) || PsiNameHelper.getInstance(directory.getProject()).isQualifiedName(name);
}
use of com.intellij.psi.PsiPackage in project moe-ide-integration by multi-os-engine.
the class MOEJUnitUtil method getModelPackagesWithName.
public static Vector<PsiPackage> getModelPackagesWithName(Module myModule, final String packageRootName) {
final Vector<PsiPackage> packages = new Vector<PsiPackage>();
final PsiManager psiManager = PsiManager.getInstance(myModule.getProject());
final FileIndex fileIndex = ModuleRootManager.getInstance(myModule).getFileIndex();
fileIndex.iterateContent(new ContentIterator() {
public boolean processFile(VirtualFile fileOrDir) {
if (fileOrDir.isDirectory() && fileIndex.isUnderSourceRootOfType(fileOrDir, JavaModuleSourceRootTypes.SOURCES)) {
final PsiDirectory psiDirectory = psiManager.findDirectory(fileOrDir);
if (psiDirectory != null) {
PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(psiDirectory);
if (aPackage != null) {
String actName = aPackage.getQualifiedName();
if (actName.equals(packageRootName) || actName.startsWith(packageRootName)) {
packages.add(aPackage);
}
}
}
}
return true;
}
});
return packages;
}
use of com.intellij.psi.PsiPackage in project moe-ide-integration by multi-os-engine.
the class MOEJUnitUtil method getTestClasses.
public static Vector<PsiClass> getTestClasses(Module myModule, final String packageRootName) {
Vector<PsiPackage> packages = getModelPackagesWithName(myModule, packageRootName);
Vector<PsiClass> testClasses = new Vector<PsiClass>();
Iterator<PsiPackage> it = packages.iterator();
while (it.hasNext()) {
PsiPackage p = it.next();
PsiClass[] packageClasses = p.getClasses();
if (packageClasses != null && packageClasses.length > 0) {
for (PsiClass c : packageClasses) {
if (JUnitUtil.isTestClass(c)) {
testClasses.add(c);
}
}
}
}
return testClasses;
}
Aggregations