List of usage examples for org.eclipse.jdt.internal.core.util Util getLineSeparator
private static String getLineSeparator(char[] text, char[] buffer)
From source file:org.codehaus.jdt.groovy.model.GroovyClassFileWorkingCopy.java
License:Open Source License
/** * @see Openable#openBuffer(IProgressMonitor, Object) *///ww w. j a v a 2 s . c o m protected IBuffer openBuffer(IProgressMonitor pm, Object info) throws JavaModelException { // create buffer IBuffer buffer = this.owner.createBuffer(this); if (buffer == null) return null; // set the buffer source if (buffer.getCharacters() == null) { IBuffer classFileBuffer = this.classFile.getBuffer(); if (classFileBuffer != null) { buffer.setContents(classFileBuffer.getCharacters()); } else { // Disassemble IClassFileReader reader = ToolFactory.createDefaultClassFileReader(this.classFile, IClassFileReader.ALL); Disassembler disassembler = new Disassembler(); String contents = disassembler.disassemble(reader, Util.getLineSeparator("", getJavaProject()), //$NON-NLS-1$ ClassFileBytesDisassembler.WORKING_COPY); buffer.setContents(contents); } } // add buffer to buffer cache BufferManager bufManager = getBufferManager(); // GROOVY Change access to private member // old // bufManager.addBuffer(buffer); // new if (buffer.getContents() != null) { ReflectionUtils.executePrivateMethod(BufferManager.class, "addBuffer", new Class<?>[] { IBuffer.class }, //$NON-NLS-1$ bufManager, new Object[] { buffer }); } // GROOVY End // listen to buffer changes buffer.addBufferChangedListener(this); return buffer; }
From source file:org.eclipse.che.jdt.internal.core.Openable.java
License:Open Source License
public String findRecommendedLineSeparator() throws JavaModelException { IBuffer buffer = getBuffer();/*from www . j av a2 s.co m*/ String source = buffer == null ? null : buffer.getContents(); return Util.getLineSeparator(source, getJavaProject()); }
From source file:org.eclipse.jdt.internal.core.CompilationUnit.java
License:Open Source License
/** * @see ICompilationUnit#createType(String, IJavaElement, boolean, IProgressMonitor) *///from w w w . j a v a 2 s. c o m public IType createType(String content, IJavaElement sibling, boolean force, IProgressMonitor monitor) throws JavaModelException { if (!exists()) { //autogenerate this compilation unit IPackageFragment pkg = (IPackageFragment) getParent(); String source = ""; //$NON-NLS-1$ if (!pkg.isDefaultPackage()) { //not the default package...add the package declaration String lineSeparator = Util.getLineSeparator(null/*no existing source*/, getJavaProject()); source = "package " + pkg.getElementName() + ";" + lineSeparator + lineSeparator; //$NON-NLS-1$ //$NON-NLS-2$ } CreateCompilationUnitOperation op = new CreateCompilationUnitOperation(pkg, this.name, source, force); op.runOperation(monitor); } CreateTypeOperation op = new CreateTypeOperation(this, content, force); if (sibling != null) { op.createBefore(sibling); } op.runOperation(monitor); return (IType) op.getResultElements()[0]; }
From source file:org.eclipse.jdt.internal.core.JavaProject.java
License:Open Source License
/** * @see IJavaProject#newEvaluationContext() */// w w w .j a v a 2 s .co m public IEvaluationContext newEvaluationContext() { EvaluationContext context = new EvaluationContext(); context.setLineSeparator(Util.getLineSeparator(null/*no existing source*/, this)); return new EvaluationContextWrapper(context, this); }
From source file:org.eclipse.virgo.ide.jdt.internal.core.classpath.ServerClasspathUtils.java
License:Open Source License
/** * Persists the given {@link IClasspathEntry}s to a file *///from w w w . java 2s . co m protected static void persistClasspathEntries(IJavaProject project, IClasspathEntry[] entries) { // Get the line separator from the platform configuration String lineSeparator = Util.getLineSeparator((String) null, project); // Create the xml string representation of the classpath entries StringBuilder builder = new StringBuilder("<classpath>").append(lineSeparator); if (project instanceof JavaProject) { JavaProject javaProject = (JavaProject) project; for (IClasspathEntry entry : entries) { builder.append(javaProject.encodeClasspathEntry(entry)); } } builder.append("</classpath>").append(lineSeparator); // Save the contents to the settings file saveFile(project, builder); }
From source file:org.jboss.tools.vscode.java.internal.HoverInfoProvider.java
License:Open Source License
/** * Returns source as hover//from ww w . java 2s .com * @param curr * @return */ private String computeSourceHover(IJavaElement curr) { if ((curr instanceof IMember || curr instanceof ILocalVariable || curr instanceof ITypeParameter) && curr instanceof ISourceReference) { try { String source = ((ISourceReference) curr).getSource(); String[] sourceLines = getTrimmedSource(source, curr); if (sourceLines == null) return null; String delim = Util.getLineSeparator(source, unit.getJavaProject()); source = concatenate(sourceLines, delim); return source; } catch (JavaModelException ex) { //do nothing } } return null; }