List of usage examples for org.eclipse.jdt.core IJavaProject getOption
String getOption(String optionName, boolean inheritJavaCoreOptions);
From source file:org.eclipse.jdt.internal.core.SourceMapper.java
License:Open Source License
private synchronized void computeAllRootPaths(IType type) { if (this.areRootPathsComputed) { return;/*ww w .j a v a 2s .co m*/ } IPackageFragmentRoot root = (IPackageFragmentRoot) type.getPackageFragment().getParent(); IPath pkgFragmentRootPath = root.getPath(); final HashSet tempRoots = new HashSet(); long time = 0; if (VERBOSE) { System.out.println("compute all root paths for " + root.getElementName()); //$NON-NLS-1$ time = System.currentTimeMillis(); } final HashSet firstLevelPackageNames = new HashSet(); boolean containsADefaultPackage = false; boolean containsJavaSource = !pkgFragmentRootPath.equals(this.sourcePath); // used to optimize zip file reading only if source path and root path are equals, otherwise assume that attachment contains Java source String sourceLevel = null; String complianceLevel = null; if (root.isArchive()) { JavaModelManager manager = JavaModelManager.getJavaModelManager(); ZipFile zip = null; try { zip = manager.getZipFile(pkgFragmentRootPath); for (Enumeration entries = zip.entries(); entries.hasMoreElements();) { ZipEntry entry = (ZipEntry) entries.nextElement(); String entryName = entry.getName(); if (!entry.isDirectory()) { if (Util.isClassFileName(entryName)) { int index = entryName.indexOf('/'); if (index != -1) { String firstLevelPackageName = entryName.substring(0, index); if (!firstLevelPackageNames.contains(firstLevelPackageName)) { if (sourceLevel == null) { IJavaProject project = root.getJavaProject(); sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true); complianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, true); } IStatus status = JavaConventions.validatePackageName(firstLevelPackageName, sourceLevel, complianceLevel); if (status.isOK() || status.getSeverity() == IStatus.WARNING) { firstLevelPackageNames.add(firstLevelPackageName); } } } else { containsADefaultPackage = true; } } else if (!containsJavaSource && org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(entryName)) { containsJavaSource = true; } } } } catch (CoreException e) { // ignore } finally { manager.closeZipFile(zip); // handle null case } } else { Object target = JavaModel.getTarget(root.getPath(), true); if (target instanceof IResource) { IResource resource = (IResource) target; if (resource instanceof IContainer) { try { IResource[] members = ((IContainer) resource).members(); for (int i = 0, max = members.length; i < max; i++) { IResource member = members[i]; String resourceName = member.getName(); if (member.getType() == IResource.FOLDER) { if (sourceLevel == null) { IJavaProject project = root.getJavaProject(); sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true); complianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, true); } IStatus status = JavaConventions.validatePackageName(resourceName, sourceLevel, complianceLevel); if (status.isOK() || status.getSeverity() == IStatus.WARNING) { firstLevelPackageNames.add(resourceName); } } else if (Util.isClassFileName(resourceName)) { containsADefaultPackage = true; } else if (!containsJavaSource && org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(resourceName)) { containsJavaSource = true; } } } catch (CoreException e) { // ignore } } } } if (containsJavaSource) { // no need to read source attachment if it contains no Java source (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=190840 ) Object target = JavaModel.getTarget(this.sourcePath, true); if (target instanceof IContainer) { IContainer folder = (IContainer) target; computeRootPath(folder, firstLevelPackageNames, containsADefaultPackage, tempRoots, folder.getFullPath().segmentCount()/*if external folder, this is the linked folder path*/); } else { JavaModelManager manager = JavaModelManager.getJavaModelManager(); ZipFile zip = null; try { zip = manager.getZipFile(this.sourcePath); for (Enumeration entries = zip.entries(); entries.hasMoreElements();) { ZipEntry entry = (ZipEntry) entries.nextElement(); String entryName; if (!entry.isDirectory() && org.eclipse.jdt.internal.core.util.Util .isJavaLikeFileName(entryName = entry.getName())) { IPath path = new Path(entryName); int segmentCount = path.segmentCount(); if (segmentCount > 1) { for (int i = 0, max = path.segmentCount() - 1; i < max; i++) { if (firstLevelPackageNames.contains(path.segment(i))) { tempRoots.add(path.uptoSegment(i)); // don't break here as this path could contain other first level package names (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=74014) } if (i == max - 1 && containsADefaultPackage) { tempRoots.add(path.uptoSegment(max)); } } } else if (containsADefaultPackage) { tempRoots.add(new Path("")); //$NON-NLS-1$ } } } } catch (CoreException e) { // ignore } finally { manager.closeZipFile(zip); // handle null case } } } int size = tempRoots.size(); if (this.rootPaths != null) { for (Iterator iterator = this.rootPaths.iterator(); iterator.hasNext();) { tempRoots.add(new Path((String) iterator.next())); } this.rootPaths.clear(); } else { this.rootPaths = new ArrayList(size); } size = tempRoots.size(); if (size > 0) { ArrayList sortedRoots = new ArrayList(tempRoots); if (size > 1) { Collections.sort(sortedRoots, new Comparator() { public int compare(Object o1, Object o2) { IPath path1 = (IPath) o1; IPath path2 = (IPath) o2; return path1.segmentCount() - path2.segmentCount(); } }); } for (Iterator iter = sortedRoots.iterator(); iter.hasNext();) { IPath path = (IPath) iter.next(); this.rootPaths.add(path.toString()); } } this.areRootPathsComputed = true; if (VERBOSE) { System.out.println("Spent " + (System.currentTimeMillis() - time) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ System.out.println("Found " + size + " root paths"); //$NON-NLS-1$ //$NON-NLS-2$ int i = 0; for (Iterator iterator = this.rootPaths.iterator(); iterator.hasNext();) { System.out.println("root[" + i + "]=" + ((String) iterator.next()));//$NON-NLS-1$ //$NON-NLS-2$ i++; } } }
From source file:org.eclipse.jst.common.internal.annotations.ui.AbstractAnnotationTagProposal.java
License:Open Source License
/** * Returns true if camel case matching is enabled. * //from w w w .j av a 2s.c om * @since 3.2 */ protected boolean isCamelCaseMatching() { IJavaProject project = getProject(); String value; if (project == null) value = JavaCore.getOption(JavaCore.CODEASSIST_CAMEL_CASE_MATCH); else value = project.getOption(JavaCore.CODEASSIST_CAMEL_CASE_MATCH, true); return JavaCore.ENABLED.equals(value); }
From source file:org.eclipse.jst.common.project.facet.core.internal.JavaFacetUtil.java
License:Open Source License
public static String getCompilerLevel(final IProject project) { final IJavaProject jproj = JavaCore.create(project); String level = jproj.getOption(JavaCore.COMPILER_COMPLIANCE, false); if (level == null) { level = getCompilerLevel();//w w w . j a va 2s. c o m } return level; }
From source file:org.eclipse.jst.j2ee.internal.common.operations.JavaModelUtil.java
License:Open Source License
public static boolean is50OrHigher(IJavaProject project) { return is50OrHigher(project.getOption(JavaCore.COMPILER_COMPLIANCE, true)); }
From source file:org.eclipse.jst.j2ee.project.facet.JavaProjectMigrationOperation.java
License:Open Source License
private IProjectFacetVersion getJavaFacetVersion() { IProject project = J2EEProjectUtilities.getProject(model.getStringProperty(PROJECT_NAME)); IJavaProject jProj = JemProjectUtilities.getJavaProject(project); String jdtVersion = jProj.getOption(JavaCore.COMPILER_COMPLIANCE, true); if (jdtVersion.startsWith("1.3")) { //$NON-NLS-1$ return JavaFacetUtils.JAVA_13; } else if (jdtVersion.startsWith("1.4")) { //$NON-NLS-1$ return JavaFacetUtils.JAVA_14; } else if (jdtVersion.startsWith("1.5")) { //$NON-NLS-1$ return JavaFacetUtils.JAVA_50; }/*from ww w. j a va2s.c o m*/ return JavaFacetUtils.JAVA_60; }
From source file:org.eclipse.jst.jsp.core.internal.java.jspel.ELGeneratorVisitor.java
License:Open Source License
private boolean compilerSupportsParameterizedTypes() { if (fDocument != null) { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IPath location = TaglibController.getLocation(fDocument); if (location != null && location.segmentCount() > 0) { IJavaProject project = JavaCore.create(root.getProject(location.segment(0))); String compliance = project.getOption(JavaCore.COMPILER_SOURCE, true); try { return Float.parseFloat(compliance) >= 1.5; } catch (NumberFormatException e) { return false; }//from w w w .j av a 2 s. c om } } return false; }
From source file:org.eclipse.jst.ws.internal.axis.creation.ui.command.AxisCheckCompilerLevelCommand.java
License:Open Source License
public IStatus execute(IProgressMonitor monitor, IAdaptable adaptable) { IStatus status = Status.OK_STATUS;/*from w ww .j a va 2 s . c o m*/ String javaSpecVersion = System.getProperty("java.specification.version"); if (javaSpecVersion != null) { IProject project = ProjectUtilities.getProject(serverProject_); IJavaProject javaProject = JavaCore.create(project); if (javaProject != null) { String projectCompilerLevel = javaProject.getOption("org.eclipse.jdt.core.compiler.compliance", false); if (projectCompilerLevel == null) { projectCompilerLevel = (String) JavaCore.getDefaultOptions() .get("org.eclipse.jdt.core.compiler.compliance"); } if (projectCompilerLevel != null) { if (!compilerLevelsCompatible(javaSpecVersion, projectCompilerLevel)) { status = StatusUtils.errorStatus( NLS.bind(AxisCreationUIMessages.MSG_ERROR_COMPILER_LEVEL_NOT_COMPATIBLE, new String[] { javaSpecVersion, serverProject_, projectCompilerLevel })); getEnvironment().getStatusHandler().reportError(status); } } } } return status; }
From source file:org.eclipse.jst.ws.internal.consumption.common.FacetUtils.java
License:Open Source License
/** * Returns the set of facet versions which can be inferred from the provided Java project * //from ww w . j ava2 s. co m * @param javaProject a Java project that exists in the workspace. Must not be null. * @return Set containing elements of type {@link IProjectFacetVersion} */ public static Set getFacetsForJavaProject(IJavaProject javaProject) { Set facets = new HashSet(); String jdkComplianceLevel = null; if (javaProject != null) { jdkComplianceLevel = javaProject.getOption("org.eclipse.jdt.core.compiler.compliance", false); if (jdkComplianceLevel == null) { jdkComplianceLevel = JavaCore.getOption(JavaCore.COMPILER_COMPLIANCE); if (jdkComplianceLevel == null) { jdkComplianceLevel = "1.4"; } } } IProjectFacet javaFacet = ProjectFacetsManager.getProjectFacet(JavaFacet.ID); IProjectFacetVersion javaFacetVersion = null; if (jdkComplianceLevel.equals("1.3")) { javaFacetVersion = javaFacet.getVersion("1.3"); } else if (jdkComplianceLevel.equals("1.4")) { javaFacetVersion = javaFacet.getVersion("1.4"); } else if (jdkComplianceLevel.equals("1.5")) { javaFacetVersion = JavaFacet.JAVA_50; } else if (jdkComplianceLevel.equals("1.6")) { javaFacetVersion = JavaFacet.JAVA_60; } else if (jdkComplianceLevel.equals("1.7")) { javaFacetVersion = JavaFacet.VERSION_1_7; } else { javaFacetVersion = javaFacet.getVersion("1.4"); } facets.add(javaFacetVersion); IProjectFacet utilityFacet = ProjectFacetsManager.getProjectFacet(IModuleConstants.JST_UTILITY_MODULE); IProjectFacetVersion utilityFacetVersion = null; try { utilityFacetVersion = utilityFacet.getLatestVersion(); } catch (CoreException ce) { } if (utilityFacetVersion != null) { facets.add(utilityFacetVersion); } return facets; }
From source file:org.eclipse.m2e.jdt.internal.AbstractJavaProjectConfigurator.java
License:Open Source License
protected void addJavaProjectOptions(Map<String, String> options, ProjectConfigurationRequest request, IProgressMonitor monitor) throws CoreException { String source = null, target = null; for (MojoExecution execution : getCompilerMojoExecutions(request, monitor)) { source = getCompilerLevel(request.getMavenProject(), execution, "source", source, SOURCES, monitor); //$NON-NLS-1$ target = getCompilerLevel(request.getMavenProject(), execution, "target", target, TARGETS, monitor); //$NON-NLS-1$ }//from w w w.ja v a 2 s. co m if (source == null) { source = DEFAULT_COMPILER_LEVEL; log.warn("Could not determine source level, using default " + source); } if (target == null) { target = DEFAULT_COMPILER_LEVEL; log.warn("Could not determine target level, using default " + target); } // While "5" and "6" are valid synonyms for Java 5 and Java 6 source, // Eclipse expects the values 1.5 and 1.6. if (source.equals("5")) { source = "1.5"; } else if (source.equals("6")) { source = "1.6"; } else if (source.equals("7")) { source = "1.7"; } // While "5" and "6" are valid synonyms for Java 5 and Java 6 target, // Eclipse expects the values 1.5 and 1.6. if (target.equals("5")) { target = "1.5"; } else if (target.equals("6")) { target = "1.6"; } else if (target.equals("7")) { target = "1.7"; } options.put(JavaCore.COMPILER_SOURCE, source); options.put(JavaCore.COMPILER_COMPLIANCE, source); options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, target); // 360962 keep forbidden_reference severity set by the user IJavaProject jp = JavaCore.create(request.getProject()); if (jp != null && jp.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, false) == null) { options.put(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, "warning"); //$NON-NLS-1$ } }
From source file:org.eclipse.m2e.jdt.internal.JavaProjectConversionParticipant.java
License:Open Source License
public void convert(IProject project, Model model, IProgressMonitor monitor) throws CoreException { if (!accept(project)) { return;//from ww w .ja v a 2 s . com } IJavaProject javaProject = JavaCore.create(project); if (javaProject == null) { return; } log.debug("Applying Java conversion to " + project.getName()); //$NON-NLS-1$ configureBuildSourceDirectories(model, javaProject); //Read existing Eclipse compiler settings String source = javaProject.getOption(JavaCore.COMPILER_SOURCE, false); String target = javaProject.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, false); //We want to keep pom.xml configuration to a minimum so we rely on convention. If the java version == 1.5, //we shouldn't need to add anything as recent maven-compiler-plugin versions target Java 1.5 by default if (DEFAULT_JAVA_VERSION.equals(source) && DEFAULT_JAVA_VERSION.equals(target)) { return; } //Configure Java version boolean useProperties = false;//TODO Use preferences if (useProperties) { configureProperties(model, source, target); } else { configureCompilerPlugin(model, source, target); } }