@NonNull private String getContent(final boolean assign) throws IOException { final CharSequence content = createContent(); final String result = toString(content); if (assign) { this.text = result; } return result; }
/** * Returns the content of the file represented by the {@link JavaSource}. * @return String the java source */ public String getText() { if (!hasSource()) { throw new IllegalStateException (); } try { return this.jfo.getCharContent(false).toString(); } catch (IOException ioe) { //Should never happen Exceptions.printStackTrace(ioe); return null; } }
public final void update () throws IOException { if (this.kind != Kind.CLASS) { //Side effect assigns the text getContent(true); } }
/** * Returns the mtime of the file, in the case of opened * modified file, the mtime is not known, this method returns * the current time. */ @Override public long getLastModified() { Long dirty; if (isModifiedByWorkingCopy()) { return System.currentTimeMillis(); } else if ((dirty = isDirty()) != null) { return dirty; } else { return getFileLastModified(); } }
@Override @NonNull public final OutputStream openOutputStream() throws IOException { final FileObject file = handle.resolveFileObject(true); if (file == null) { throw new IOException("Cannot create file: " + toString()); //NOI18N } OutputStream res = createOutputStream(); if (res == null) { res = new LckStream (file); } return res; }
return AbstractSourceFileObject.getFactory().createJavaFileObject(handle, null, null, false);
/** * Returns the {@link TokenHierarchy} for the file represented by the {@link JavaSource}. * @return lexer TokenHierarchy */ public TokenHierarchy<?> getTokenHierarchy() { if (!hasSource()) { throw new IllegalStateException (); } try { return this.jfo.getTokenHierarchy(); } catch (IOException ioe) { //Should never happen Exceptions.printStackTrace(ioe); return null; } }
@Override public boolean isSameFile(javax.tools.FileObject a, javax.tools.FileObject b) { return a instanceof AbstractSourceFileObject && b instanceof AbstractSourceFileObject && ((AbstractSourceFileObject)a).getHandle().file != null && ((AbstractSourceFileObject)a).getHandle().file.equals( ((AbstractSourceFileObject)b).getHandle().file); }
@Override public final boolean isNameCompatible ( @NonNull final String simplename, @NonNull final JavaFileObject.Kind kind) { assert simplename != null; return this.kind == kind && this.getNameWithoutExtension().equals(simplename); }
@Override public final boolean delete() { if (isDirty() != null) { //If the file is modified in editor do not delete it return false; } else { final FileObject file = handle.resolveFileObject(false); if (file == null) { return false; } try { FileLock lock = file.lock(); try { file.delete (lock); return true; } finally { lock.releaseLock(); } } catch (IOException e) { return false; } } }
/** * Creates {@link JavaFileObject} for a NetBeans {@link FileObject} * Any client which needs to create {@link JavaFileObject} for java * source file should use this factory method. * @param {@link FileObject} for which the {@link JavaFileObject} should be created * @param {@link FileObject} root owning the file * @param renderNow if true the snap shot of the file is taken immediately * @return {@link JavaFileObject}, never returns null * @exception {@link IOException} may be thrown */ public static AbstractSourceFileObject sourceFileObject (final FileObject file, final FileObject root, JavaFileFilterImplementation filter, boolean renderNow) throws IOException { assert file != null; if (!file.isValid() || file.isVirtual()) { throw new InvalidFileException (file); } return AbstractSourceFileObject.getFactory().createJavaFileObject( new AbstractSourceFileObject.Handle(file, root), filter, null, renderNow); }
? ((AbstractSourceFileObject) unit.getSourceFile()).getTokenHierarchy() : TokenHierarchy.create(unit.getSourceFile().getCharContent(true), JavaTokenId.language()); TokenSequence<JavaTokenId> seq = tokens.tokenSequence(JavaTokenId.language());
@Override @NonNull public final InputStream openInputStream() throws IOException { String _text = text; if (_text == null) { _text= getContent(false); } return new ByteArrayInputStream (_text.getBytes()); }
/** * Creates {@link JavaFileObject} for a NetBeans {@link FileObject} * Any client which needs to create {@link JavaFileObject} for java * source file should use this factory method. * @param {@link FileObject} for which the {@link JavaFileObject} should be created * @param {@link FileObject} root owning the file * @param renderNow if true the snap shot of the file is taken immediately * @return {@link JavaFileObject}, never returns null * @exception {@link IOException} may be thrown */ public static AbstractSourceFileObject sourceFileObject (final FileObject file, final FileObject root, final JavaFileFilterImplementation filter, final CharSequence content) throws IOException { assert file != null; if (!file.isValid() || file.isVirtual()) { throw new InvalidFileException (file); } return AbstractSourceFileObject.getFactory().createJavaFileObject( new AbstractSourceFileObject.Handle(file, root), filter, content, true); }
@NonNull public final TokenHierarchy<?> getTokenHierarchy() throws IOException { if (this.tokens == null) { final CharBuffer charBuffer = getCharContent(true); this.tokens = TokenHierarchy.create(charBuffer, false, JavaTokenId.language(), null, null); //TODO: .createSnapshot(); } return this.tokens; }
@Override @NonNull public final Reader openReader(final boolean ignoreEncodingErrors) throws IOException { String _text = text; if (_text == null) { _text = getContent(false); } return new StringReader(_text); }
@Override @NonNull public final CharBuffer getCharContent(final boolean ignoreEncodingErrors) throws IOException { String _text = this.text; if (_text == null) { _text = getContent(false); } return CharBuffer.wrap(_text); }