Example usage for org.eclipse.jdt.internal.compiler.problem AbortCompilationUnit AbortCompilationUnit

List of usage examples for org.eclipse.jdt.internal.compiler.problem AbortCompilationUnit AbortCompilationUnit

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.problem AbortCompilationUnit AbortCompilationUnit.

Prototype

public AbortCompilationUnit(CompilationResult compilationResult, IOException exception, String encoding) 

Source Link

Document

Used to surface encoding issues when reading sources

Usage

From source file:com.codenvy.ide.ext.java.server.internal.core.CompilationUnit.java

License:Open Source License

/**
 * @see org.eclipse.jdt.internal.compiler.env.ICompilationUnit#getContents()
 */// w w w .  j  a v a  2  s .  com
public char[] getContents() {
    IBuffer buffer = getBufferManager().getBuffer(this);
    if (buffer == null) {
        // no need to force opening of CU to get the content
        // also this cannot be a working copy, as its buffer is never closed while the working copy is alive
        File file = resource();
        // Get encoding from file
        String encoding;
        encoding = "UTF-8"; //file.getCharset();
        try {
            return Util.getResourceContentsAsCharArray(file, encoding);
        } catch (JavaModelException e) {
            if (manager.abortOnMissingSource.get() == Boolean.TRUE) {
                IOException ioException = e.getJavaModelStatus()
                        .getCode() == IJavaModelStatusConstants.IO_EXCEPTION ? (IOException) e.getException()
                                : new IOException(e.getMessage());
                throw new AbortCompilationUnit(null, ioException, encoding);
            } else {
                Util.log(e, Messages.bind(Messages.file_notFound, file.getAbsolutePath()));
            }
            return CharOperation.NO_CHAR;
        }
    }
    char[] contents = buffer.getCharacters();
    if (contents == null) { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=129814
        if (manager.abortOnMissingSource.get() == Boolean.TRUE) {
            IOException ioException = new IOException(Messages.buffer_closed);
            IFile file = (IFile) getResource();
            // Get encoding from file
            String encoding;
            try {
                encoding = file.getCharset();
            } catch (CoreException ce) {
                // do not use any encoding
                encoding = null;
            }
            throw new AbortCompilationUnit(null, ioException, encoding);
        }
        return CharOperation.NO_CHAR;
    }
    return contents;
}

From source file:io.gige.compiler.internal.CompilationTaskImpl.java

License:Apache License

protected void setTargets(Iterable<? extends JavaFileObject> compilationUnits) {
    this.targets = stream(compilationUnits.spliterator(), false)
            .filter(file -> file.getKind() == JavaFileObject.Kind.SOURCE)
            .map(file -> new CompilationUnit(null, file.getName(), null) {
                @Override/* w ww  .java  2  s . co m*/
                public char[] getContents() {
                    try {
                        return file.getCharContent(true).toString().toCharArray();
                    } catch (IOException e) {
                        throw new AbortCompilationUnit(null, e, null);
                    }
                }
            }).toArray(ICompilationUnit[]::new);
}

From source file:org.eclipse.jdt.internal.core.CompilationUnit.java

License:Open Source License

/**
 * @see org.eclipse.jdt.internal.compiler.env.ICompilationUnit#getContents()
 *///  w  w w . j a va2s.co m
public char[] getContents() {
    IBuffer buffer = getBufferManager().getBuffer(this);
    if (buffer == null) {
        // no need to force opening of CU to get the content
        // also this cannot be a working copy, as its buffer is never closed while the working copy is alive
        IFile file = (IFile) getResource();
        // Get encoding from file
        String encoding;
        try {
            encoding = file.getCharset();
        } catch (CoreException ce) {
            // do not use any encoding
            encoding = null;
        }
        try {
            return Util.getResourceContentsAsCharArray(file, encoding);
        } catch (JavaModelException e) {
            if (JavaModelManager.getJavaModelManager().abortOnMissingSource.get() == Boolean.TRUE) {
                IOException ioException = e.getJavaModelStatus()
                        .getCode() == IJavaModelStatusConstants.IO_EXCEPTION ? (IOException) e.getException()
                                : new IOException(e.getMessage());
                throw new AbortCompilationUnit(null, ioException, encoding);
            } else {
                Util.log(e, Messages.bind(Messages.file_notFound, file.getFullPath().toString()));
            }
            return CharOperation.NO_CHAR;
        }
    }
    char[] contents = buffer.getCharacters();
    if (contents == null) { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=129814
        if (JavaModelManager.getJavaModelManager().abortOnMissingSource.get() == Boolean.TRUE) {
            IOException ioException = new IOException(Messages.buffer_closed);
            IFile file = (IFile) getResource();
            // Get encoding from file
            String encoding;
            try {
                encoding = file.getCharset();
            } catch (CoreException ce) {
                // do not use any encoding
                encoding = null;
            }
            throw new AbortCompilationUnit(null, ioException, encoding);
        }
        return CharOperation.NO_CHAR;
    }
    return contents;
}