List of usage examples for org.eclipse.jdt.core ITypeHierarchy getSubclasses
IType[] getSubclasses(IType type);
From source file:org.eclipse.jst.jsf.taglibprocessing.attributevalues.JavaClassType.java
License:Open Source License
private void addValidSubClasses(IType res, Set vals, Set checkedTypes) { try {/*from w ww . j a va2 s . c o m*/ //check to see if we have already checked the hiearchy if (checkedTypes.contains(res)) return; //should we add itself? if (isInnerOrAnonymousClass(res)) return; if (!isAbstractClass(res)) vals.add(res); //since it is a set, dupes will not be added ITypeHierarchy hierarchy = res.newTypeHierarchy(getJavaProject(), null); IType[] subclasses = hierarchy.getSubclasses(res); checkedTypes.add(res); for (int i = 0; i < subclasses.length; i++) { addValidSubClasses(subclasses[i], vals, checkedTypes); } } catch (JavaModelException e) { //ignore } }
From source file:org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.ResourceChangedProcessor.java
License:Open Source License
private List<JaxrsElementDelta> preprocessApplicationChangesOnWebxmlAdditionOrChange(IResource resource, JaxrsMetamodel metamodel, IProgressMonitor progressMonitor) throws CoreException { final IType applicationType = JdtUtils.resolveType(APPLICATION.qualifiedName, metamodel.getJavaProject(), progressMonitor);//from w w w .j a v a2 s . co m // occurs when the project has the jax-rs nature (the builder is called), but no jaxrs library is in the classpath if (applicationType == null) { return Collections.emptyList(); } final List<JaxrsElementDelta> results = new ArrayList<JaxrsElementDelta>(); final ITypeHierarchy applicationTypeHierarchy = JdtUtils.resolveTypeHierarchy(applicationType, applicationType.getJavaProject(), false, progressMonitor); final IType[] applicationSubclasses = applicationTypeHierarchy.getSubclasses(applicationType); // add the standard Application type in last position in the hierarchy final IType[] applicationClasses = CollectionUtils.append(applicationSubclasses, applicationType, new IType[applicationSubclasses.length + 1]); // existing web.xml-based JAX-RS applications in the metamodel final List<JaxrsWebxmlApplication> existingApplications = metamodel.getWebxmlApplications(); // web.xml-based JAX-RS applications declared in the web deployment descriptor final List<JaxrsWebxmlApplication> declaredApplications = new ArrayList<JaxrsWebxmlApplication>(); for (IType applicationClass : applicationClasses) { final String applicationClassName = applicationClass.getFullyQualifiedName(); final String applicationPath = WtpUtils.getApplicationPath(resource, applicationClassName); if (applicationPath != null) { declaredApplications .add(factory.createApplication(applicationClassName, applicationPath, resource, metamodel)); } } // now compare the 'existing' vs 'declared' lists to update the metamodel (adding/updating/removing items) final Collection<JaxrsWebxmlApplication> addedApplications = CollectionUtils .difference(declaredApplications, existingApplications); for (JaxrsWebxmlApplication application : addedApplications) { results.add(new JaxrsElementDelta(application, ADDED)); } final Collection<JaxrsWebxmlApplication> changedApplications = CollectionUtils .intersection(declaredApplications, existingApplications); for (JaxrsWebxmlApplication application : changedApplications) { results.add(new JaxrsElementDelta(application, CHANGED, F_FINE_GRAINED)); } final Collection<JaxrsWebxmlApplication> removedApplications = CollectionUtils .difference(existingApplications, declaredApplications); for (JaxrsWebxmlApplication application : removedApplications) { results.add(new JaxrsElementDelta(application, REMOVED)); } /*final IJaxrsApplication application = metamodel.getApplication(); if (resolvedApplicationPath != null) { if (application == null || application.getElementKind() == EnumElementKind.APPLICATION_JAVA) { metamodel.add(webxmlApplication); results.add(new JaxrsElementDelta(webxmlApplication, ADDED)); } else if (application != null && application.getElementKind() == EnumElementKind.APPLICATION_WEBXML) { int flags = webxmlApplication.update(webxmlApplication); results.add(new JaxrsElementDelta(webxmlApplication, CHANGED, flags)); } } else if(application != null && application.getElementKind() == EnumElementKind.APPLICATION_WEBXML){ final JaxrsWebxmlApplication webxmlApplication = (JaxrsWebxmlApplication) application; metamodel.remove(webxmlApplication); results.add(new JaxrsElementDelta(webxmlApplication, REMOVED)); }*/ // otherwise, do nothing (application path not declared in web.xml, or not valid but can't be discovered) return results; }