private boolean isOnClassPath(IJavaScriptUnit element) throws JavaScriptModelException { IJavaScriptProject project = element.getJavaScriptProject(); if (project == null || !project.exists()) return false; return project.isOnIncludepath(element); }
/* (non-Javadoc) * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object) */ public boolean test(Object receiver, String method, Object[] args, Object expectedValue) { if (!(receiver instanceof IJavaScriptElement)) { return false; } IJavaScriptElement res = (IJavaScriptElement) receiver; if (method.equals(NAME)) { return Pattern.matches(toString(expectedValue), res.getElementName()); } else if (method.equals(IS_IN_JAVA_PROJECT)) { IJavaScriptProject javaProject = res.getJavaScriptProject(); return javaProject != null && javaProject.exists() && javaProject.getProject().isOpen(); } else if (method.equals(IS_IN_JAVA_PROJECT_WITH_NATURE)) { IJavaScriptProject javaProject = res.getJavaScriptProject(); if (javaProject != null && javaProject.exists() && javaProject.getProject().isOpen()) { if (expectedValue != null) { try { return javaProject.getProject().hasNature(toString(expectedValue)); } catch (CoreException e) { return false; } } } return false; } else if (method.equals(IS_ON_CLASSPATH)) { IJavaScriptProject javaProject = res.getJavaScriptProject(); if (javaProject != null && javaProject.exists()) { return javaProject.isOnIncludepath(res); } return false; } else if (method.equals(IN_SOURCE_FOLDER)) { IJavaScriptElement root = res.getAncestor(IJavaScriptElement.PACKAGE_FRAGMENT_ROOT); if (root != null) { try { return ((IPackageFragmentRoot) root).getKind() == IPackageFragmentRoot.K_SOURCE; } catch (JavaScriptModelException e) { // ignore } } return false; } else if (method.equals(IN_ARCHIVE)) { IJavaScriptElement root = res.getAncestor(IJavaScriptElement.PACKAGE_FRAGMENT_ROOT); if (root != null) { return ((IPackageFragmentRoot) root).isArchive(); } return false; } else if (method.equals(IN_EXTERNAL_ARCHIVE)) { IJavaScriptElement root = res.getAncestor(IJavaScriptElement.PACKAGE_FRAGMENT_ROOT); if (root != null) { return ((IPackageFragmentRoot) root).isExternal(); } return false; } else if (method.equals(PROJECT_OPTION)) { IJavaScriptProject project = res.getJavaScriptProject(); if (project != null) { if (args.length == 2) { String current = project.getOption(toString(args[0]), true); return current != null && current.equals(args[1]); } else if (args.length == 1) { return project.getOption(toString(args[0]), false) != null; } } return false; } else if (method.equals(HAS_TYPE_ON_CLASSPATH)) { IJavaScriptProject javaProject = res.getJavaScriptProject(); if (javaProject != null && javaProject.exists()) { try { return javaProject.findType(toString(expectedValue)) != null; } catch (JavaScriptModelException e) { return false; } } } return false; }