List of usage examples for org.eclipse.jdt.internal.core.util Util getResourceContentsAsCharArray
public static char[] getResourceContentsAsCharArray(IFile file) throws JavaModelException
From source file:net.sf.j2s.core.builder.SourceFile.java
License:Open Source License
public char[] getContents() { try {/*ww w . j ava 2 s . c o m*/ return Util.getResourceContentsAsCharArray(this.resource); } catch (CoreException e) { throw new AbortCompilation(true, new MissingSourceFileException(this.resource.getFullPath().toString())); } }
From source file:org.eclipse.ajdt.core.builder.AJCompilationParticipantResult.java
License:Open Source License
@Override public char[] getContents() { try {//from w ww . ja v a 2s . c om contents = Util.getResourceContentsAsCharArray(this.file); } catch (CoreException e) { return CharOperation.NO_CHAR; } return this.contents; }
From source file:org.eclipse.che.ide.extension.maven.server.core.MavenClasspathUtil.java
License:Open Source License
public static IClasspathContainer readMavenClasspath(IJavaProject javaProject) { IFile file = javaProject.getProject().getFile(".codenvy/classpath.maven"); IClasspathEntry[] entries;/*www.j ava 2 s . c om*/ if (file.exists()) { try { char[] chars = Util.getResourceContentsAsCharArray(file); String content = new String(chars); if (!content.isEmpty()) { String[] pathToJars = content.split(":"); List<IClasspathEntry> classpathEntry = new ArrayList<>(); for (String path : pathToJars) { String srcPath = path.substring(0, path.lastIndexOf('.')) + "-sources.jar"; classpathEntry.add(JavaCore.newLibraryEntry(new org.eclipse.core.runtime.Path(path), new org.eclipse.core.runtime.Path(srcPath), null)); } entries = classpathEntry.toArray(new IClasspathEntry[classpathEntry.size()]); } else { entries = EMPTY; } } catch (JavaModelException e) { LOG.error("Can't read maven classpath.", e); entries = EMPTY; } } else { entries = EMPTY; } return new MavenClasspathContainer(entries); }
From source file:org.eclipse.jdt.internal.core.CompilationUnit.java
License:Open Source License
/** * @see Openable#openBuffer(IProgressMonitor, Object) *///from w w w. java 2 s . c o m protected IBuffer openBuffer(IProgressMonitor pm, Object info) throws JavaModelException { // create buffer BufferManager bufManager = getBufferManager(); boolean isWorkingCopy = isWorkingCopy(); IBuffer buffer = isWorkingCopy ? this.owner.createBuffer(this) : BufferManager.createBuffer(this); if (buffer == null) return null; ICompilationUnit original = null; boolean mustSetToOriginalContent = false; if (isWorkingCopy) { // ensure that isOpen() is called outside the bufManager synchronized block // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=237772 // GROOVY start /* old { mustSetToOriginalContent = !isPrimary() && (original = new CompilationUnit((PackageFragment)getParent(), getElementName(), DefaultWorkingCopyOwner.PRIMARY)).isOpen() ; } new */ mustSetToOriginalContent = !isPrimary() && (original = LanguageSupportFactory.newCompilationUnit((PackageFragment) getParent(), getElementName(), DefaultWorkingCopyOwner.PRIMARY)).isOpen(); // GROOVY end } // synchronize to ensure that 2 threads are not putting 2 different buffers at the same time // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=146331 synchronized (bufManager) { IBuffer existingBuffer = bufManager.getBuffer(this); if (existingBuffer != null) return existingBuffer; // set the buffer source if (buffer.getCharacters() == null) { if (isWorkingCopy) { if (mustSetToOriginalContent) { buffer.setContents(original.getSource()); } else { IFile file = (IFile) getResource(); if (file == null || !file.exists()) { // initialize buffer with empty contents buffer.setContents(CharOperation.NO_CHAR); } else { buffer.setContents(Util.getResourceContentsAsCharArray(file)); } } } else { IFile file = (IFile) getResource(); if (file == null || !file.exists()) throw newNotPresentException(); buffer.setContents(Util.getResourceContentsAsCharArray(file)); } } // add buffer to buffer cache // note this may cause existing buffers to be removed from the buffer cache, but only primary compilation unit's buffer // can be closed, thus no call to a client's IBuffer#close() can be done in this synchronized block. bufManager.addBuffer(buffer); // listen to buffer changes buffer.addBufferChangedListener(this); } return buffer; }
From source file:org.eclipseguru.gwt.internal.core.refactoring.GwtModuleEntryPointChange.java
License:Open Source License
@Override public Change perform(final IProgressMonitor pm) throws CoreException { final IFile moduleDescriptor = (IFile) gwtModule.getModuleDescriptor(); try {/*from w w w . ja v a 2s. c o m*/ final char[] content = Util.getResourceContentsAsCharArray(moduleDescriptor); final char[] newContent = CharOperation.replace(content, oldEntryPointTypeName.toCharArray(), newEntryPointTypeName.toCharArray()); if (CharOperation.equals(content, newContent)) return null; moduleDescriptor.setContents( new ByteArrayInputStream(new String(newContent).getBytes(moduleDescriptor.getCharset())), IResource.KEEP_HISTORY, pm); } catch (final UnsupportedEncodingException e) { throw new CoreException(GwtUi.newErrorStatus(e)); } // return the undo change return new GwtModuleEntryPointChange(GwtCore.create(moduleDescriptor), oldEntryPointTypeName); }