Example usage for org.eclipse.jdt.internal.compiler.impl CompilerOptions getMap

List of usage examples for org.eclipse.jdt.internal.compiler.impl CompilerOptions getMap

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.impl CompilerOptions getMap.

Prototype

public Map<String, String> getMap() 

Source Link

Usage

From source file:com.github.parzonka.ccms.engine.SortElementsOperation.java

License:Open Source License

/**
 * Method processElement.//from   w w w.  j  a v a  2s. co m
 *
 * @param unit
 * @param source
 */
private String processElement(ICompilationUnit unit, char[] source) {
    final Document document = new Document(new String(source));
    final CompilerOptions options = new CompilerOptions(unit.getJavaProject().getOptions(true));
    final ASTParser parser = ASTParser.newParser(this.apiLevel);
    parser.setCompilerOptions(options.getMap());
    parser.setSource(source);
    parser.setKind(ASTParser.K_COMPILATION_UNIT);
    parser.setResolveBindings(false);
    final org.eclipse.jdt.core.dom.CompilationUnit ast = (org.eclipse.jdt.core.dom.CompilationUnit) parser
            .createAST(null);

    final ASTRewrite rewriter = sortCompilationUnit(ast, null);
    if (rewriter == null)
        return document.get();

    final TextEdit edits = rewriter.rewriteAST(document, unit.getJavaProject().getOptions(true));

    RangeMarker[] markers = null;
    if (this.positions != null) {
        markers = new RangeMarker[this.positions.length];
        for (int i = 0, max = this.positions.length; i < max; i++) {
            markers[i] = new RangeMarker(this.positions[i], 0);
            insert(edits, markers[i]);
        }
    }
    try {
        edits.apply(document, TextEdit.UPDATE_REGIONS);
        if (this.positions != null) {
            for (int i = 0, max = markers.length; i < max; i++) {
                this.positions[i] = markers[i].getOffset();
            }
        }
    } catch (final BadLocationException e) {
        // ignore
    }
    return document.get();
}

From source file:com.google.gwt.dev.javac.JavaSourceParser.java

License:Open Source License

/**
 * Parse Java source./*  www  .j a v  a 2 s .  co  m*/
 * 
 * @param javaSource String containing Java source to parse
 * @return a CompilationUnitDeclaration or null if parsing failed
 */
private static CompilationUnitDeclaration parseJava(String javaSource) {
    CodeSnippetParsingUtil parsingUtil = new CodeSnippetParsingUtil();
    CompilerOptions options = new CompilerOptions();
    options.complianceLevel = ClassFileConstants.JDK1_5;
    options.sourceLevel = ClassFileConstants.JDK1_5;
    CompilationUnitDeclaration unit = parsingUtil.parseCompilationUnit(javaSource.toString().toCharArray(),
            options.getMap(), true);
    if (unit.compilationResult().hasProblems()) {
        return null;
    }
    return unit;
}

From source file:org.ant4eclipse.ant.jdt.ecj.CompilerOptionsProvider.java

License:Open Source License

/**
 * <p>/*from  w  ww  .  j a  va 2s . c  o m*/
 * Creates the compiler options for the JDT compiler.
 * </p>
 * <p>
 * The compiler options are defined here:
 * <ul>
 * <li><a href="http://help.eclipse.org/galileo/topic/org.eclipse.jdt.doc.isv/guide/jdt_api_options.htm">JDT Core
 * options</a></li>
 * <li><a href=
 * "http://help.eclipse.org/galileo/topic/org.eclipse.jdt.doc.user/reference/preferences/java/ref-preferences-compiler.htm"
 * >Java Compiler Preferences </a></li>
 * <li><a href="http://help.eclipse.org/galileo/topic/org.eclipse.jdt.doc.user/reference/preferences/java/compiler/ref-preferences-errors-warnings.htm"
 * >Java Compiler Errors/Warnings Preferences</a></li>
 * </ul>
 * </p>
 * 
 * @param javac
 *          the javac task
 * @param projectCompilerOptionsFile
 *          the project specific compiler options file.
 * @param globalCompilerOptionsFile
 *          the global compiler options file.
 * 
 * @return the map with the merged compiler options.
 */
@SuppressWarnings("unchecked")
public static final StringMap getCompilerOptions(Javac javac, String projectCompilerOptionsFile,
        String globalCompilerOptionsFile) {
    Assure.notNull("javac", javac);

    // get the project options
    StringMap projectOptions = getFileCompilerOptions(projectCompilerOptionsFile);
    if (A4ELogging.isTraceingEnabled()) {
        A4ELogging.trace("Read projectOptions from '%s': '%s'.", projectCompilerOptionsFile, projectOptions);
    }
    // get the default options
    StringMap defaultOptions = getFileCompilerOptions(globalCompilerOptionsFile);
    if (A4ELogging.isTraceingEnabled()) {
        A4ELogging.trace("Read defaultOptions from '%s': '%s'.", globalCompilerOptionsFile, defaultOptions);
    }
    // get the javac options
    StringMap javacOptions = getJavacCompilerOptions(javac);
    if (A4ELogging.isTraceingEnabled()) {
        A4ELogging.trace("javacOptions: '%s'.", javacOptions);
    }
    // merge the map
    StringMap mergedMap = mergeCompilerOptions(projectOptions, defaultOptions, javacOptions);
    if (A4ELogging.isTraceingEnabled()) {
        A4ELogging.trace("mergedMap: '%s'.", mergedMap);
    }

    // [AE-201] If not enabled/disabled explicitly, enable ECJ javadoc parsing support
    // to find references inside javadoc
    if (!mergedMap.containsKey(ENABLE_JAVADOC_SUPPORT)) {
        mergedMap.put(ENABLE_JAVADOC_SUPPORT, "enabled");
    }

    // If not enabled/disabled explicitly, set ECJ forbidden reference to 'error
    if (!mergedMap.containsKey(FORBIDDEN_REFERENCE)) {
        mergedMap.put(FORBIDDEN_REFERENCE, "error");
    }

    // create result
    CompilerOptions compilerOptions = new CompilerOptions(mergedMap);

    // verbose option
    compilerOptions.verbose = javac.getVerbose();

    // debug the compiler options
    if (A4ELogging.isDebuggingEnabled()) {
        A4ELogging.debug("Using the following compile options:\n %s", compilerOptions.toString());
    }

    // return the compiler options
    StringMap result = new StringMap();
    result.putAll(compilerOptions.getMap());
    return result;
}

From source file:org.eclipse.che.jdt.rest.CompilerSetupService.java

License:Open Source License

@GET
@Path("/all")
@Consumes(APPLICATION_JSON)/*from w w  w .j  ava  2  s. co m*/
@Produces(APPLICATION_JSON)
public Map<String, String> getAllParameters(@QueryParam("projectpath") String projectPath) {
    IJavaProject project = JAVA_MODEL.getJavaProject(projectPath);

    //noinspection unchecked
    Map<String, String> map = project.getOptions(true);

    CompilerOptions options = new CompilerOptions(map);

    //noinspection unchecked
    return options.getMap();
}

From source file:org.eclipse.che.plugin.java.server.rest.CompilerSetupService.java

License:Open Source License

/**
 * Return java compiler preferences for current project by not empty path {@code projectpath}. If {@code projectpath} if empty then
 * return java compile preferences for current workspace.
 *
 * @param projectPath project path//  w  ww  . j a v  a  2s .c om
 * @return java compiler preferences
 */
@GET
@Path("/all")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
public Map<String, String> getAllParameters(@QueryParam("projectpath") String projectPath) {
    if (projectPath == null || projectPath.isEmpty()) {
        //noinspection unchecked
        CompilerOptions options = new CompilerOptions(new HashMap<>(JavaCore.getOptions()));
        //noinspection unchecked
        return options.getMap();
    }

    IJavaProject project = JAVA_MODEL.getJavaProject(projectPath);

    //noinspection unchecked
    Map<String, String> map = project.getOptions(true);
    CompilerOptions options = new CompilerOptions(map);

    //noinspection unchecked
    return options.getMap();
}

From source file:org.eclipse.objectteams.otdt.tests.compiler.smap.AbstractSourceMapGeneratorTest.java

License:Open Source License

@SuppressWarnings("unchecked")
protected CompilerOptions getCompilerOptions() {
    CompilerOptions cOptions = new CompilerOptions();
    Map<String, String> options = cOptions.getMap();
    if (COMPLIANCE_1_3.equals(this.complianceLevel)) {
        options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_3);
        options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_3);
        options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_3);
    } else if (COMPLIANCE_1_4.equals(this.complianceLevel)) {
        options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_4);
        options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_4);
        options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4);
    } else if (COMPLIANCE_1_5.equals(this.complianceLevel)) {
        options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5);
        options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5);
        options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5);
    }/*from w w w . ja  v a  2s .c o m*/

    options.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE);
    options.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.WARNING);
    options.put(CompilerOptions.OPTION_ReportLocalVariableHiding, CompilerOptions.WARNING);
    options.put(CompilerOptions.OPTION_ReportFieldHiding, CompilerOptions.WARNING);
    options.put(CompilerOptions.OPTION_ReportPossibleAccidentalBooleanAssignment, CompilerOptions.WARNING);
    options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.WARNING);
    options.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.PRESERVE);
    options.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.PRESERVE);
    options.put(CompilerOptions.OPTION_ReportUnnecessaryElse, CompilerOptions.WARNING);

    return new CompilerOptions(options);
}

From source file:org.eclipse.xtext.xbase.compiler.InMemoryJavaCompiler.java

License:Open Source License

public InMemoryJavaCompiler(final ClassLoader parent, final CompilerOptions compilerOptions) {
    InMemoryJavaCompiler.ClassLoaderBasedNameEnvironment _classLoaderBasedNameEnvironment = new InMemoryJavaCompiler.ClassLoaderBasedNameEnvironment(
            parent);//from  ww w.java2  s  . co  m
    this.nameEnv = _classLoaderBasedNameEnvironment;
    this.parentClassLoader = parent;
    Map<String, String> _map = compilerOptions.getMap();
    CompilerOptions _compilerOptions = new CompilerOptions(_map);
    this.compilerOptions = _compilerOptions;
}

From source file:org.eclipse.xtext.xbase.testing.InMemoryJavaCompiler.java

License:Open Source License

public InMemoryJavaCompiler(final ClassLoader parent, final CompilerOptions compilerOptions) {
    InMemoryJavaCompiler.ClassLoaderBasedNameEnvironment _classLoaderBasedNameEnvironment = new InMemoryJavaCompiler.ClassLoaderBasedNameEnvironment(
            parent);//from  w  w  w.  j a v a 2 s  .  com
    this.nameEnv = _classLoaderBasedNameEnvironment;
    this.parentClassLoader = parent;
    Map _map = compilerOptions.getMap();
    CompilerOptions _compilerOptions = new CompilerOptions(_map);
    this.compilerOptions = _compilerOptions;
}

From source file:ptolemy.backtrack.eclipse.plugin.editor.MultiPageCompilationUnitEditor.java

License:Open Source License

/** Get the compilation unit for the Java code in the "Raw" tab.
 *
 *  @return The compilation unit./*from  w ww  .  j  a v  a2 s.  co  m*/
 *  @exception JavaModelException If the compilation unit cannot be
 *   retrieved from the Eclipse Java editor.
 */
private CompilationUnit _getCompilationUnit() throws JavaModelException {

    IWorkingCopyManager manager = JavaPlugin.getDefault().getWorkingCopyManager();
    ICompilationUnit unit = manager.getWorkingCopy(getEditorInput());

    CompilerOptions options = new CompilerOptions(unit.getJavaProject().getOptions(true));
    ASTParser parser = ASTParser.newParser(AST.JLS3); // FIXME
    parser.setCompilerOptions(options.getMap());
    parser.setSource(unit.getBuffer().getCharacters());
    parser.setKind(ASTParser.K_COMPILATION_UNIT);
    parser.setResolveBindings(false);
    CompilationUnit result = (CompilationUnit) parser.createAST(null);

    return result; //AST.parseCompilationUnit(unit, false);
}