List of usage examples for org.eclipse.jdt.core IJavaProject getOptions
Map<String, String> getOptions(boolean inheritJavaCoreOptions);
From source file:net.atos.optimus.common.tools.jdt.XACodeFormatter.java
License:Open Source License
/** * Format a String . Use the default code formatter * * @param sourceToFormat/*from ww w . java2 s .com*/ * String to format * */ public static String format(String inputSource, IJavaProject project) { Map<?, ?> options = project != null ? project.getOptions(true) : JavaCore.getOptions(); String sourceToFormat = preformat(inputSource); CodeFormatter formatter = ToolFactory.createCodeFormatter(options, ToolFactory.M_FORMAT_EXISTING); IDocument document = new Document(sourceToFormat); TextEdit textEdit = formatter.format(CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS, sourceToFormat, 0, sourceToFormat.length(), 0, null); if (textEdit != null) { try { textEdit.apply(document); String destination = document.get(); return destination; } catch (Exception e) { Activator.getDefault() .logError("The compilation unit could not be" + " read because of thrown Exception.", e); // In this case, return initial content return sourceToFormat; } } else { // In this case, return initial content return sourceToFormat; } }
From source file:net.rim.ejde.internal.ui.wizards.BasicBlackBerryProjectWizardPageTwo.java
License:Open Source License
/** * Initialize java compiler./*from w w w . j a v a 2 s . c o m*/ */ private void initializeJavaCompiler(IJavaProject eclipseProject) { final Map<String, String> map = eclipseProject.getOptions(false); if (map.size() > 0) { map.remove(JavaCore.COMPILER_COMPLIANCE); map.remove(JavaCore.COMPILER_SOURCE); map.remove(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM); } map.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3); map.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4); map.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_2); eclipseProject.setOptions(map); }
From source file:net.rim.ejde.internal.util.ImportUtils.java
License:Open Source License
/** * Sets a whole bunch of project specific settings. * <p>//from ww w. ja v a 2 s. c o m * http://help.eclipse.org/help31/topic/org.eclipse.jdt.doc.isv/reference/ * api/org/eclipse/jdt/core/JavaCore.html#getDefaultOptions() * * @param project */ @SuppressWarnings("unchecked") static public void initializeProjectOptions(IJavaProject javaProject) { if (null == javaProject) throw new IllegalArgumentException(); final Map map = javaProject.getOptions(false); if (map.size() > 0) { map.remove(JavaCore.COMPILER_COMPLIANCE); map.remove(JavaCore.COMPILER_SOURCE); map.remove(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM); } map.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3); // DPI 221069 --> Bugzilla id=250185 map.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4); map.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_2); javaProject.setOptions(map); }
From source file:net.rim.ejde.internal.util.ProjectUtils.java
License:Open Source License
/** * Checks if the given <code>javaProject</code> has compatibility problem. * * @param javaProject/*from w ww .j ava 2 s.c om*/ * @return */ public static boolean hasJDKCompatibilityProblem(IJavaProject javaProject) { final Map map = javaProject.getOptions(true); if (map.size() > 0) { String value = (String) map.get(JavaCore.COMPILER_COMPLIANCE); if (!value.equalsIgnoreCase(JavaCore.VERSION_1_4)) { return true; } value = (String) map.get(JavaCore.COMPILER_SOURCE); if (!value.equalsIgnoreCase(JavaCore.VERSION_1_3)) { return true; } value = (String) map.get(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM); if (!value.equalsIgnoreCase(JavaCore.VERSION_1_2)) { return true; } } return false; }
From source file:net.sf.spindle.core.builder.EclipseBuildInfrastructure.java
License:Mozilla Public License
private boolean doesProjectSupportJavaAnnotations(IProject project) { if (true)//from www.j a va2 s . co m return false; // FIXME get rid of this when we figure out how to handle annotations! IJavaProject jproject = JavaCore.create(project); if (jproject == null || !jproject.exists() || !project.isAccessible()) return false; Map options = jproject.getOptions(true); String target = (String) options.get(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM); if (target == null) return false; float version = Float.parseFloat(target); if (version < 1.5) return false; System.out.println("target: " + target); String sourceCompatibility = (String) options.get(JavaCore.COMPILER_SOURCE); if (sourceCompatibility == null) return false; float compat = Float.parseFloat(sourceCompatibility); if (compat < 1.5) return false; System.out.println("sourceCompatibility: " + sourceCompatibility); return true; }
From source file:nz.ac.auckland.ptjava.builder.PTJavaFileBuilderNature.java
License:Open Source License
/** * Add the nature to the specified project if it does not already have it. * /*from w ww . j a v a 2s. c o m*/ * @param project the project to be modified */ public static void addNature(IProject project) { // Cannot modify closed projects. if (!project.isOpen()) return; // Get the description. IProjectDescription description; try { description = project.getDescription(); } catch (CoreException e) { PTJavaLog.logError(e); return; } // Determine if the project already has the nature. List<String> newIds = new ArrayList<String>(); newIds.addAll(Arrays.asList(description.getNatureIds())); int index = newIds.indexOf(NATURE_ID); if (index != -1) return; // Add the nature newIds.add(NATURE_ID); description.setNatureIds(newIds.toArray(new String[newIds.size()])); try { // Save the description. project.setDescription(description, null); if (project.hasNature(JavaCore.NATURE_ID)) { IJavaProject javaProject = JavaCore.create(project); // set up compiler to not copy .ptjava files to output Map options = javaProject.getOptions(false); options.put(JavaCore.CORE_JAVA_BUILD_RESOURCE_COPY_FILTER, "*.ptjava"); javaProject.setOptions(options); } else { PTJavaLog.logInfo("The project to add ParaTask nature does not have Java nature!"); } } catch (CoreException e) { PTJavaLog.logError(e); } }
From source file:org.autorefactor.refactoring.PrepareApplyRefactoringsJob.java
License:Open Source License
private JavaProjectOptions getJavaProjectOptions(IJavaElement javaElement) { final IJavaProject javaProject = getIJavaProject(javaElement); JavaProjectOptions options = javaProjects.get(javaProject); if (options == null) { options = new JavaProjectOptionsImpl(javaProject.getOptions(true)); javaProjects.put(javaProject, options); }/* w w w .j a v a 2 s . c om*/ return options; }
From source file:org.autorefactor.ui.PrepareApplyRefactoringsJob.java
License:Open Source License
@SuppressWarnings("unchecked") private JavaProjectOptions getJavaProjectOptions(IJavaElement javaElement) { final IJavaProject javaProject = getIJavaProject(javaElement); JavaProjectOptions options = javaProjects.get(javaProject); if (options == null) { options = new JavaProjectOptionsImpl(javaProject.getOptions(true)); javaProjects.put(javaProject, options); }//from w w w .ja va2s . c om return options; }
From source file:org.bundlemaker.core.jdt.internal.parser.JdtParser.java
License:Open Source License
/** * {@inheritDoc}//w ww . j a v a2 s . c om */ @Override protected synchronized void doParseResource(IProjectContentEntry projectContent, IParsableResource resource, boolean parseReferences, boolean isBatchParse) { // if (!canParse(resource)) { return; } try { _parser.setSource(new String(resource.getContent()).toCharArray()); _parser.setResolveBindings(true); if (isBatchParse) { // the associated java project IJavaProject javaProject = JdtProjectHelper .getAssociatedJavaProject(projectContent.getProvider().getBundleMakerProject()); _parser.setProject(javaProject); // Override (default) Compiler Options from Java Project with 'our' options _parser.setCompilerOptions( CoreParserJdt.getCompilerOptionsWithComplianceLevel(javaProject.getOptions(true))); _parser.setUnitName("/" + javaProject.getProject().getName() + "/" + resource.getPath()); } else { if (projectContent.getProvider() instanceof JdtProjectContentProvider) { // reset model extension resource.addResourceModelExtension(null); String root = resource.getRoot(); IJavaProject javaProject = ((JdtProjectContentProvider) projectContent.getProvider()) .getSourceJavaProject(projectContent, root); _parser.setProject(javaProject); _parser.setUnitName("/" + javaProject.getProject().getName() + "/" + resource.getPath()); } } // // step 1: set the directly referenced types JdtAstVisitor visitor = new JdtAstVisitor(resource); ((CompilationUnit) _parser.createAST(null)).accept(visitor); // step 4: add the errors to the error list for (IProblem problem : visitor.getProblems()) { // add errors if (problem.isError()) { getProblems().add(problem); } } // set the primary type String primaryTypeName = JavaTypeUtils.convertToFullyQualifiedName(resource.getPath(), ".java"); IType primaryType = resource.adaptAs(IParsableTypeResource.class).getType(primaryTypeName); resource.adaptAs(IParsableTypeResource.class).setPrimaryType(primaryType); } catch (Exception e) { getProblems().add(new IProblem.DefaultProblem(resource, "Error while parsing: " + e)); e.printStackTrace(); } }
From source file:org.codehaus.groovy.eclipse.refactoring.actions.CleanUpPostSaveListener.java
License:Open Source License
private boolean compatibleOptions(IJavaProject project, Map cleanUpOptions) { if (cleanUpOptions.size() == 0) return true; Map projectOptions = project.getOptions(true); for (Iterator iterator = cleanUpOptions.keySet().iterator(); iterator.hasNext();) { String key = (String) iterator.next(); String projectOption = (String) projectOptions.get(key); String cleanUpOption = (String) cleanUpOptions.get(key); if (!strongerEquals(projectOption, cleanUpOption)) return false; }//from w ww. j a v a 2 s . co m return true; }