List of usage examples for org.eclipse.jdt.core IJavaProject getOption
String getOption(String optionName, boolean inheritJavaCoreOptions);
From source file:org.hibernate.eclipse.console.workbench.ProjectCompilerVersionChecker.java
License:Open Source License
/** * // w w w . ja va2 s. c om * @param ccfg * @return false if Projects jdk version is bigger than Eclipse jdk version */ public static boolean validateProjectComplianceLevel(final ConsoleConfiguration ccfg) { IJavaProject[] javaProjects = ProjectUtils.findJavaProjects(ccfg); if (javaProjects.length > 0) { for (final IJavaProject iJavaProject : javaProjects) { if (iJavaProject.exists()) { String projectTarget = iJavaProject.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, true); String eclipseCompilerVersion = System.getProperty("java.specification.version"); //$NON-NLS-1$ long projectJdkLevel = versionToJdkLevel(projectTarget); long eclipseJdkLevel = versionToJdkLevel(eclipseCompilerVersion); if (eclipseJdkLevel < projectJdkLevel) { Display.getDefault().syncExec(new Runnable() { @Override public void run() { MessageDialog.openWarning(null, Messages.ProjectCompilerVersionChecker_title, NLS.bind(Messages.ProjectCompilerVersionChecker_message, iJavaProject.getElementName())); } }); return false; } } } } return true; }
From source file:org.hyperic.hypclipse.internal.util.HQDEJavaHelper.java
License:Open Source License
/** * Precedence order from high to low: (1) Project specific option; * (2) General preference option; (3) Default option; (4) Java 1.3 * @param project/*w w w .j a v a 2 s . co m*/ * @param optionName * @return */ public static String getJavaLevel(IProject project, String optionName) { // Returns the corresponding java project // No need to check for null, will return null IJavaProject javaProject = JavaCore.create(project); String value = null; // Preferred to use the project if ((javaProject != null) && javaProject.exists()) { // Get the project specific option if one exists. Rolls up to the // general preference option if no project specific option exists. value = javaProject.getOption(optionName, true); if (value != null) { return value; } } // Get the general preference option value = JavaCore.getJavaCore().getPluginPreferences().getString(optionName); if (value != null) { return value; } // Get the default option value = JavaCore.getOption(optionName); if (value != null) { return value; } // Return the default return JavaCore.VERSION_1_3; }
From source file:org.jboss.mapper.eclipse.internal.util.JavaUtil.java
License:Open Source License
/** * @param context/*ww w . j av a 2s .com*/ * @return the Java source and runtime compliance levels for the project * containing the supplied Java element */ public static String[] getSourceComplianceLevels(IJavaElement context) { if (context != null) { IJavaProject javaProject = context.getJavaProject(); if (javaProject != null) { return new String[] { javaProject.getOption(JavaCore.COMPILER_SOURCE, true), javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true) }; } } return new String[] { JavaCore.getOption(JavaCore.COMPILER_SOURCE), JavaCore.getOption(JavaCore.COMPILER_COMPLIANCE) }; }
From source file:org.jboss.tools.arquillian.core.internal.compiler.ArquillianCompilationParticipant.java
License:Open Source License
protected void addAllSourceFiles(final List<SourceFile> sourceFiles, final IJavaProject project) throws CoreException { for (int i = 0, l = this.sourceLocations.length; i < l; i++) { final ClasspathMultiDirectory sourceLocation = this.sourceLocations[i]; final char[][] exclusionPatterns = sourceLocation.exclusionPatterns; final char[][] inclusionPatterns = sourceLocation.inclusionPatterns; final boolean isAlsoProject = sourceLocation.sourceFolder.equals(project.getProject()); final int segmentCount = sourceLocation.sourceFolder.getFullPath().segmentCount(); final IContainer outputFolder = sourceLocation.binaryFolder; final boolean isOutputFolder = sourceLocation.sourceFolder.equals(outputFolder); sourceLocation.sourceFolder.accept(new IResourceProxyVisitor() { public boolean visit(IResourceProxy proxy) throws CoreException { switch (proxy.getType()) { case IResource.FILE: if (org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(proxy.getName())) { IResource resource = proxy.requestResource(); if (exclusionPatterns != null || inclusionPatterns != null) if (Util.isExcluded(resource.getFullPath(), inclusionPatterns, exclusionPatterns, false)) return false; if (!ArquillianSearchEngine.isArquillianJUnitTest(proxy, project)) { return false; }// www.j av a 2s. co m sourceFiles.add(new SourceFile((IFile) resource, sourceLocation)); } return false; case IResource.FOLDER: IPath folderPath = null; if (isAlsoProject) if (isExcludedFromProject(folderPath = proxy.requestFullPath(), project)) return false; if (exclusionPatterns != null) { if (folderPath == null) folderPath = proxy.requestFullPath(); if (Util.isExcluded(folderPath, inclusionPatterns, exclusionPatterns, true)) { // must walk children if inclusionPatterns != null, can skip them if == null // but folder is excluded so do not create it in the output folder return inclusionPatterns != null; } } if (!isOutputFolder) { if (folderPath == null) folderPath = proxy.requestFullPath(); String packageName = folderPath.lastSegment(); if (packageName.length() > 0) { String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true); String complianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, true); if (JavaConventions.validatePackageName(packageName, sourceLevel, complianceLevel) .getSeverity() != IStatus.ERROR) createFolder(folderPath.removeFirstSegments(segmentCount), outputFolder); } } } return true; } }, IResource.NONE); this.notifier.checkCancel(); } }
From source file:org.jboss.tools.arquillian.core.internal.util.ArquillianSearchEngine.java
License:Open Source License
private static void createProblem(String message, IType type, IMethodBinding deploymentMethod, Integer severity, int line) throws CoreException { if (severity == null || type == null || type.getJavaProject() == null) { return;/* ww w . j ava2 s . co m*/ } boolean enable = ArquillianUtility.isValidatorEnabled(type.getJavaProject().getProject()); if (!enable) { return; } ICompilationUnit cu = type.getCompilationUnit(); if (cu == null) { return; } IResource resource = cu.getResource(); if (resource == null) { return; } IMarker marker = resource.createMarker(ArquillianConstants.MARKER_RESOURCE_ID); String[] allNames = { IMarker.MESSAGE, IMarker.SEVERITY, IJavaModelMarker.ID, IMarker.CHAR_START, IMarker.CHAR_END, IMarker.LINE_NUMBER, IMarker.SOURCE_ID, }; Object[] allValues = new Object[allNames.length]; int index = 0; allValues[index++] = message; allValues[index++] = severity; allValues[index++] = ArquillianConstants.ARQUILLIAN_PROBLEM_ID; int start = -1; int end = -1; if (line != -1) { IJavaProject project = cu.getJavaProject(); String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true); String complianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, true); IScanner scanner = ToolFactory.createScanner(false, false, true, sourceLevel, complianceLevel); scanner.setSource(cu.getBuffer().getCharacters()); if (scan(scanner)) { start = scanner.getLineStart(line); end = scanner.getLineEnd(line); } } if (start == -1 || end == -1) { IJavaElement javaElement = deploymentMethod.getJavaElement(); ISourceRange range = null; if (javaElement instanceof IMember) { IMember member = (IMember) javaElement; if (javaElement != null) { try { range = member.getNameRange(); } catch (JavaModelException e) { if (e.getJavaModelStatus().getCode() != IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST) { throw e; } if (!CharOperation.equals(javaElement.getElementName().toCharArray(), TypeConstants.PACKAGE_INFO_NAME)) { throw e; } } } } start = range == null ? 0 : range.getOffset(); end = range == null ? 1 : start + range.getLength(); } allValues[index++] = new Integer(start); // start allValues[index++] = new Integer(end > 0 ? end + 1 : end); // end allValues[index++] = new Integer(line); // line number allValues[index++] = ArquillianConstants.SOURCE_ID; marker.setAttributes(allNames, allValues); }
From source file:org.jboss.tools.arquillian.ui.internal.wizards.NewArquillianJUnitTestCaseDeploymentPage.java
License:Open Source License
private static String[] getSourceComplianceLevels(IJavaElement context) { if (context != null) { IJavaProject javaProject = context.getJavaProject(); if (javaProject != null) { return new String[] { javaProject.getOption(JavaCore.COMPILER_SOURCE, true), javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true) }; }/*from ww w.ja va 2 s . co m*/ } return new String[] { JavaCore.getOption(JavaCore.COMPILER_SOURCE), JavaCore.getOption(JavaCore.COMPILER_COMPLIANCE) }; }
From source file:org.jboss.tools.common.ui.ValidatorFactory.java
License:Open Source License
/** * //from w w w . j av a 2s .c om * @param jProject * @return java project's CompilerSourceLevel or default one. */ public static String getCompilerSourceLevel(IJavaProject jProject) { if (jProject == null) { return DEFAULT_SOURCE_LEVEL; } String sourceLevel = jProject.getOption(JavaCore.COMPILER_SOURCE, true); return sourceLevel != null ? sourceLevel : DEFAULT_SOURCE_LEVEL; }
From source file:org.jboss.tools.common.ui.ValidatorFactory.java
License:Open Source License
/** * //from w w w .j a v a 2s . c om * @param jProject * @return java project's CompilerComplianceLevel or default one. */ public static String getCompilerComplianceLevel(IJavaProject jProject) { if (jProject == null) { return DEFAULT_COMPLIANCE_LEVEL; } String compliance = jProject.getOption(JavaCore.COMPILER_COMPLIANCE, true); return compliance != null ? compliance : DEFAULT_SOURCE_LEVEL; }
From source file:org.jboss.tools.ws.jaxws.ui.utils.JBossWSUIUtils.java
License:Open Source License
public static String[] getSourceComplianceLevels(IJavaElement context) { if (context != null) { IJavaProject javaProject = context.getJavaProject(); if (javaProject != null) { return new String[] { javaProject.getOption(JavaCore.COMPILER_SOURCE, true), javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true) }; }// w ww . j av a2s .co m } return new String[] { JavaCore.getOption(JavaCore.COMPILER_SOURCE), JavaCore.getOption(JavaCore.COMPILER_COMPLIANCE) }; }
From source file:org.limy.eclipse.qalab.common.LimyQalabUtils.java
License:Open Source License
/** * Javav?WFNgJDKo?[W?B/* w w w. ja va 2 s . com*/ * @param project Javav?WFNg * @return JDKo?[W */ public static String getJdkVersion(IJavaProject project) { return project.getOption(JavaCore.COMPILER_SOURCE, true); }