Search in sources :

Example 1 with UserTagInfo

use of com.redhat.qute.commons.usertags.UserTagInfo in project quarkus-ls by redhat-developer.

the class QuarkusIntegrationForQute method collectUserTags.

/**
 * Collect user tags for the given package fragment root.
 *
 * @param root the package fragment root.
 * @param tags the user tags list to fill.
 *
 * @throws JavaModelException
 * @throws CoreException
 */
private static void collectUserTags(IPackageFragmentRoot root, List<UserTagInfo> tags) throws JavaModelException, CoreException {
    IJavaElement[] children = root.getChildren();
    for (IJavaElement child : children) {
        if (child instanceof IPackageFragment) {
            IPackageFragment packageRoot = (IPackageFragment) child;
            if (TEMPLATES_TAGS_ENTRY.equals(packageRoot.getElementName())) {
                // 'templates.tags' entry exists, loop for all resources to build user tags
                Object[] resources = packageRoot.getNonJavaResources();
                if (resources != null) {
                    for (Object object : resources) {
                        if (object instanceof IJarEntryResource) {
                            // It's a HTML, etc file, build the user tag
                            IJarEntryResource templateFile = (IJarEntryResource) object;
                            String fileName = templateFile.getName();
                            String uri = toUri(templateFile);
                            String content = convertStreamToString(templateFile.getContents());
                            UserTagInfo tagInfo = new UserTagInfo();
                            tagInfo.setFileName(fileName);
                            tagInfo.setUri(uri);
                            tagInfo.setContent(content);
                            tags.add(tagInfo);
                        }
                    }
                }
            }
        }
    }
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IJarEntryResource(org.eclipse.jdt.core.IJarEntryResource) UserTagInfo(com.redhat.qute.commons.usertags.UserTagInfo)

Example 2 with UserTagInfo

use of com.redhat.qute.commons.usertags.UserTagInfo in project quarkus-ls by redhat-developer.

the class QuarkusIntegrationForQute method getUserTags.

/**
 * Collect user tags from the given Java project.
 *
 * @param javaProject the Java project.
 * @param monitor     the progress monitor
 *
 * @return user tags from the given Java project.
 *
 * @throws CoreException
 */
public static List<UserTagInfo> getUserTags(IJavaProject javaProject, IProgressMonitor monitor) throws CoreException {
    List<UserTagInfo> tags = new ArrayList<UserTagInfo>();
    // Loop for each JAR of the classpath and try to collect files from the
    // 'templates.tags' entry
    IClasspathEntry[] resolvedClasspath = ((JavaProject) javaProject).getResolvedClasspath();
    for (IClasspathEntry entry : resolvedClasspath) {
        if (entry.isTest()) {
            continue;
        }
        switch(entry.getEntryKind()) {
            case IClasspathEntry.CPE_LIBRARY:
                String jarPath = entry.getPath().toOSString();
                IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(jarPath);
                if (root != null) {
                    collectUserTags(root, tags);
                }
        }
    }
    return tags;
}
Also used : JavaProject(org.eclipse.jdt.internal.core.JavaProject) IJavaProject(org.eclipse.jdt.core.IJavaProject) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) ArrayList(java.util.ArrayList) UserTagInfo(com.redhat.qute.commons.usertags.UserTagInfo) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Aggregations

UserTagInfo (com.redhat.qute.commons.usertags.UserTagInfo)2 ArrayList (java.util.ArrayList)1 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)1 IJarEntryResource (org.eclipse.jdt.core.IJarEntryResource)1 IJavaElement (org.eclipse.jdt.core.IJavaElement)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)1 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)1 JavaProject (org.eclipse.jdt.internal.core.JavaProject)1