List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot getKind
int getKind() throws JavaModelException;
From source file:org.eclipse.contribution.visualiser.jdtImpl.JDTContentProvider.java
License:Open Source License
/** * Returns true if this package fragment has Java classes in it. * @param fragment// w ww .j av a 2s. c o m * @return true if the package fragment contains Java classes */ protected boolean containsUsefulStuff(IPackageFragment fragment) { try { if (fragment.getKind() == IPackageFragment.PACKAGE_FRAGMENT_ROOT) { IPackageFragmentRoot ipfr = (IPackageFragmentRoot) fragment; if (ipfr.getKind() == IPackageFragmentRoot.K_BINARY) { return false; } } } catch (JavaModelException e) { e.printStackTrace(); } return true; }
From source file:org.eclipse.e4.tools.ui.designer.utils.ClassLoaderHelper.java
License:Open Source License
private static URL findResourceURL(IJavaProject javaProject, Set<IJavaProject> visited, boolean isFirstProject, String name) {/* w ww . j av a2 s. c o m*/ if (visited.contains(javaProject)) return null; visited.add(javaProject); try { IPath outPath = javaProject.getProject().getLocation().removeLastSegments(1) .append(javaProject.getOutputLocation()); outPath = outPath.addTrailingSeparator(); { URL url = toURL(outPath.append(name)); if (url != null) { return url; } } for (IPackageFragmentRoot fragment : javaProject.getPackageFragmentRoots()) { if (fragment.getKind() == IPackageFragmentRoot.K_SOURCE) { URL url = toURL(fragment.getResource().getLocation().append(name)); if (url != null) { return url; } } } // urls.add(out); IClasspathEntry[] entries = javaProject.getResolvedClasspath(true); for (IClasspathEntry entry : entries) { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: { // TODO IClasspathEntry resolveEntry = JavaCore.getResolvedClasspathEntry(entry); File file = resolveEntry.getPath().toFile(); IPath path = resolveEntry.getPath(); if (!file.exists()) { String projectName = path.segment(0); IProject project = javaProject.getProject().getWorkspace().getRoot() .getProject(projectName); path = project.getLocation().append(path.removeFirstSegments(1)); } String spec = "jar:file:" + path.toString() + "!/" + name; try { URL url2 = new URL(spec); url2.getContent(); return url2; } catch (Exception e) { } } break; case IClasspathEntry.CPE_CONTAINER: break; case IClasspathEntry.CPE_VARIABLE: { { // TODO URL url = toURL(outPath.append(name)); if (url != null) { return url; } } } break; case IClasspathEntry.CPE_PROJECT: { if (isFirstProject || entry.isExported()) { URL url = findResourceURL(getJavaProject(entry), visited, false, name); if (url != null) { return url; } } break; } } } } catch (JavaModelException e) { e.printStackTrace(); } return null; }
From source file:org.eclipse.e4.xwt.tools.ui.designer.loader.XWTVisualLoader.java
License:Open Source License
public synchronized Control loadWithOptions(URL url, Map<String, Object> options) throws Exception { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRoot root = workspace.getRoot(); String fileStr = url.getFile(); if (fileStr.indexOf(PathHelper.WHITE_SPACE_ASCII) != -1) { fileStr = fileStr.replace(PathHelper.WHITE_SPACE_ASCII, " "); }//from w w w . j a v a 2 s . c om IFile file = root.getFileForLocation(new Path(fileStr)); if (file != null) { try { // the url given an binary file of project, we need find the source file of it and the load and open. IProject project = file.getProject(); String fullPath = file.getFullPath().toString(); IJavaProject javaProject = JavaCore.create(project); String outputPath = javaProject.getOutputLocation().toString(); if (fullPath != null && outputPath != null && fullPath.startsWith(outputPath)) { String fileSourcePath = fullPath.substring(outputPath.length()); IPackageFragmentRoot[] allPackageFragmentRoots = javaProject.getAllPackageFragmentRoots(); for (IPackageFragmentRoot pRoot : allPackageFragmentRoots) { if (pRoot.getKind() == IPackageFragmentRoot.K_SOURCE) { IFolder resource = (IFolder) pRoot.getResource(); IFile sourceFile = resource.getFile(new Path(fileSourcePath)); if (sourceFile != null && sourceFile.exists()) { file = sourceFile; break; } } } } } catch (Exception e) { } } if (file != null) { IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IEditorPart activeEditor = activePage.getActiveEditor(); try { XWTDesigner designer = (XWTDesigner) activePage.openEditor(new FileEditorInput(file), XWTDesigner.EDITOR_ID, false); XamlDocument xamlDocument = (XamlDocument) designer.getDocumentRoot(); XWTModelBuilder builder = null; if (xamlDocument == null) { builder = new XWTModelBuilder(); builder.doLoad(designer, null); xamlDocument = builder.getDiagram(); } Control control = (Control) new XWTProxy(file).load(xamlDocument.getRootElement(), options); if (builder != null) { builder.dispose(); } return control; } finally { activePage.activate(activeEditor); } } return null; }
From source file:org.eclipse.fx.ide.css.validation.CssDslJavaValidator.java
License:Open Source License
@SuppressWarnings("restriction") @Check/* w ww.ja v a 2s.com*/ public void checkDeclaration(css_declaration dec) { // System.err.println("CHECK DECL " + dec); css_property property = dec.getProperty(); // Only validate files who are: // * in a plug-in project // - when css is part of build.properties bin.includes // - when css is part of the source-folder IFile file = Utils.getFile(dec.eResource()); //TODO We should add a service possibility to contribute these lookups boolean validate = false; try { if (file.getProject().hasNature("org.eclipse.pde.PluginNature")) { //$NON-NLS-1$ // validate = true; IFile properties = PDEProject.getBuildProperties(file.getProject()); Properties p = new Properties(); try (InputStream in = properties.getContents()) { p.load(in); String includes = p.getProperty("bin.includes"); //$NON-NLS-1$ if (includes != null) { IPath path = file.getProjectRelativePath(); for (String s : includes.split(",")) { //$NON-NLS-1$ if (path.toString().startsWith(s.trim())) { validate = true; break; } } } } catch (IOException e) { e.printStackTrace(); } } if (!validate && file.getProject().hasNature("org.eclipse.jdt.core.javanature")) { //$NON-NLS-1$ IJavaProject jp = JavaCore.create(file.getProject()); for (IPackageFragmentRoot r : jp.getPackageFragmentRoots()) { if (r.getKind() == IPackageFragmentRoot.K_SOURCE) { if (file.getProjectRelativePath().toString() .startsWith(r.getPath().removeFirstSegments(1).toString())) { validate = true; break; } } } } } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (!validate) { return; } if (dec.eContainer() instanceof font_face) { if ("font-family".equals(property.getName())) { if (dec.getValueTokens().stream().filter(this::filterWS).count() != 1) { error("Font family has to define a name", dec, CssDslPackage.Literals.CSS_DECLARATION__VALUE_TOKENS); } else { if (!(dec.getValueTokens().stream().filter(this::filterWS).findFirst() .get() instanceof IdentifierTok)) { CssTok tok = dec.getValueTokens().stream().filter(this::filterWS).findFirst().get(); error("Invalid font family name", dec, CssDslPackage.Literals.CSS_DECLARATION__VALUE_TOKENS, dec.getValueTokens().indexOf(tok)); } } } else if ("src".equals(property.getName())) { if (dec.getValueTokens().stream().filter(this::filterWS).count() == 0) { error("At least one URL is required", dec, CssDslPackage.Literals.CSS_DECLARATION__VALUE_TOKENS); } else { dec.getValueTokens().stream().filter(this::filterWS).filter(this::filterSymbol) .filter((t) -> !(t instanceof UrlTok)).forEach((t) -> { error("Only url-values are allowed", dec, CssDslPackage.Literals.CSS_DECLARATION__VALUE_TOKENS, dec.getValueTokens().indexOf(t)); }); } } else if ("font-stretch".equals(property.getName())) { } else if ("font-style".equals(property.getName())) { } else if ("font-weight".equals(property.getName())) { } else if ("unicode-range".equals(property.getName())) { } else { warning("Unknown property: \"" + property.getName() + "\"", property, CssDslPackage.Literals.CSS_PROPERTY__NAME); } return; } List<Proposal> properties = ext.getPropertyProposalsForSelector(file, dec, null); //extension.getAllProperties(uri); boolean known = false; for (Proposal p : properties) { if (p.getProposal().equals(property.getName())) { known = true; break; } } if (!known) { ICompositeNode node = NodeModelUtils.getNode(dec.getProperty()); boolean suppress = node.getText().contains("@SuppressWarning"); if (!suppress && !PREDEFINED_VAR_PROPS.contains(property.getName()) && !property.getName().startsWith("-var")) { //$NON-NLS-1$ warning("Unknown property: \"" + property.getName() + "\"", property, CssDslPackage.Literals.CSS_PROPERTY__NAME); } } else { ruleset rs = (ruleset) dec.eContainer(); List<selector> selectors = rs.getSelectors(); // Set<CssProperty> selectorProps = new HashSet<>(); // for (selector selector : selectors) { // selectorProps.addAll(extension.getPropertiesForSelector(uri, selector)); // } List<Proposal> selectorProps = ext.getPropertyProposalsForSelector(Utils.getFile(dec.eResource()), dec, selectors); if (selectorProps.size() > 0) { boolean supported = false; for (Proposal p : selectorProps) { if (p.getProposal().equals(property.getName())) { supported = true; break; } } if (!supported) { ICompositeNode node = NodeModelUtils.getNode(dec.getProperty()); boolean suppress = node.getText().contains("@SuppressWarning"); //$NON-NLS-1$ if (!PREDEFINED_VAR_PROPS.contains(property.getName()) && !property.getName().startsWith("-var")) { warning("\"" + property.getName() + "\" is not supported by the given selectors", CssDslPackage.Literals.CSS_DECLARATION__PROPERTY); } } } // List<ValidationResult> result = extension.validateProperty(uri, null, property.getName(), tokens); // System.err.println(result); // // System.err.println("validation of " + property.getName()); // if (!result.isEmpty()) { // for (ValidationResult r : result) { // if (r.status == ValidationStatus.ERROR) { // if (r.object != null) { // if (r.object instanceof FuncTok) { // FuncTok f = (FuncTok) r.object; // error(r.message, f, CssDslPackage.Literals.FUNC_TOK__NAME, -1); // } // else { // error(r.message, r.object, null, 0); // } // } // else { // error(r.message, dec, CssDslPackage.Literals.CSS_DECLARATION__VALUE_TOKENS, r.index); // } // } // } // } } }
From source file:org.eclipse.jdt.internal.core.CompilationUnit.java
License:Open Source License
protected IStatus validateCompilationUnit(IResource resource) { IPackageFragmentRoot root = getPackageFragmentRoot(); // root never null as validation is not done for working copies try {/*from w w w .j a v a 2 s . c om*/ if (root.getKind() != IPackageFragmentRoot.K_SOURCE) return new JavaModelStatus(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, root); } catch (JavaModelException e) { return e.getJavaModelStatus(); } if (resource != null) { char[][] inclusionPatterns = ((PackageFragmentRoot) root).fullInclusionPatternChars(); char[][] exclusionPatterns = ((PackageFragmentRoot) root).fullExclusionPatternChars(); if (Util.isExcluded(resource, inclusionPatterns, exclusionPatterns)) return new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_NOT_ON_CLASSPATH, this); if (!resource.isAccessible()) return new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, this); } IJavaProject project = getJavaProject(); return JavaConventions.validateCompilationUnitName(getElementName(), project.getOption(JavaCore.COMPILER_SOURCE, true), project.getOption(JavaCore.COMPILER_COMPLIANCE, true)); }
From source file:org.eclipse.jem.workbench.utility.JemProjectUtilities.java
License:Open Source License
/** * Get all source package fragment roots. * /* w ww . j av a 2s. c om*/ * @param javaProj * @return source package fragment roots * @throws JavaModelException * * @since 1.0.0 */ public static List getSourcePackageFragmentRoots(IJavaProject javaProj) throws JavaModelException { List result = new ArrayList(); IPackageFragmentRoot[] roots = javaProj.getPackageFragmentRoots(); for (int i = 0; i < roots.length; i++) { IPackageFragmentRoot root = roots[i]; if (root.getKind() == IPackageFragmentRoot.K_SOURCE) result.add(root); } return result; }
From source file:org.eclipse.jpt.common.core.internal.utility.PackageFragmentRootTools.java
License:Open Source License
private static boolean isSourceFolder_(IPackageFragmentRoot pfr) throws JavaModelException { return pfr.exists() && (pfr.getKind() == IPackageFragmentRoot.K_SOURCE); }
From source file:org.eclipse.jpt.jpa.eclipselink.ui.internal.entity.data.model.EclipseLinkDynamicEntityDataModelProvider.java
License:Open Source License
/** * Returns all the the existing source path roots cross the selected project * @return a set of IPackageFragmentRoot with the kind of source path *//* w w w. j a va 2s . com*/ protected IPackageFragmentRoot[] getJavaPackageFragmentRoots() { JpaProject jpaProject = getJpaProject(); IPackageFragmentRoot[] packRoots = new IPackageFragmentRoot[0]; List<IPackageFragmentRoot> rootList = new ArrayList<IPackageFragmentRoot>(); if (jpaProject != null) { IJavaProject javaProject = jpaProject.getJavaProject(); if (javaProject != null) { try { packRoots = javaProject.getAllPackageFragmentRoots(); for (IPackageFragmentRoot root : packRoots) { if (root.getKind() == IPackageFragmentRoot.K_SOURCE) { rootList.add(root); } } packRoots = new IPackageFragmentRoot[rootList.size()]; rootList.toArray(packRoots); } catch (JavaModelException e) { // fall through JptJpaEclipseLinkUiPlugin.instance().logError(e); } } } return packRoots; }
From source file:org.eclipse.jpt.jpa.ui.internal.wizards.entity.data.model.EntityDataModelProvider.java
License:Open Source License
protected IContainer getDefaultJavaSourceContainer() { JpaProject jpaProject = getTargetJpaProject(); if (jpaProject == null) { return null; }//w w w . j a v a2 s.co m IJavaProject javaProject = jpaProject.getJavaProject(); try { for (IPackageFragmentRoot pfr : javaProject.getPackageFragmentRoots()) { if (pfr.getKind() == IPackageFragmentRoot.K_SOURCE) { return (IContainer) pfr.getUnderlyingResource(); } } } catch (JavaModelException jme) { // fall through JptJpaUiPlugin.instance().logError(jme); } return null; }
From source file:org.eclipse.jpt.jpa.ui.internal.wizards.entity.data.model.EntityDataModelProvider.java
License:Open Source License
protected IContainer getJavaSourceContainer() { String containerFullPath = getStringProperty(SOURCE_FOLDER); JpaProject jpaProject = getTargetJpaProject(); if (jpaProject == null) { return null; }//ww w . j a v a 2 s . c o m IJavaProject javaProject = jpaProject.getJavaProject(); try { for (IPackageFragmentRoot pfr : javaProject.getPackageFragmentRoots()) { if (pfr.getKind() == IPackageFragmentRoot.K_SOURCE) { IContainer container = (IContainer) pfr.getUnderlyingResource(); if (container.getFullPath().equals(new Path(containerFullPath))) { return container; } } } } catch (JavaModelException jme) { // fall through JptJpaUiPlugin.instance().logError(jme); } return null; }