/** * Check if the line contains any non blank chars. */ protected static boolean isBlanks(final IStructuredDocument document, final int startOffset, final int endOffset, final int currentOffset) throws BadLocationException { return document.get(startOffset, endOffset - startOffset).trim().length() == 0 || document.get(startOffset, currentOffset - startOffset).trim().length() == 0; }
private static boolean isInMultiLineStatement(IStructuredDocument document, String checkedLineBeginState, String checkedLineEndState, int checkedOffset, int lineStart, int currLineIndex) { // TODO if in phpdoc or php miltiline,return false; try { char[] line = document.get(lineStart, document.getLineLength(currLineIndex)).toCharArray(); for (int i = 0; i < line.length; i++) { char c = line[i]; if (Character.isWhitespace(c)) { } else { // move line start to first non blank char lineStart += i + 1; break; } } } catch (BadLocationException e) { } TextSequence textSequence = PHPTextSequenceUtilities.getStatement(lineStart, document.getRegionAtCharacterOffset(lineStart), true); if (textSequence != null && isRegionTypeAllowedMultiline( FormatterUtils.getRegionType(document, textSequence.getOriginalOffset(0))) && document.getLineOfOffset(textSequence.getOriginalOffset(0)) < currLineIndex) { return true; } return false; }
private int computeAvailableLineWidth(IStructuredDocument doc, int nodeOffset, int lineWidth) { // compute current available line width int currentAvailableLineWidth = 0; try { int lineOffset = doc.getLineInformationOfOffset(nodeOffset).getOffset(); String text = doc.get(lineOffset, nodeOffset - lineOffset); int usedWidth = getIndentationLength(text); currentAvailableLineWidth = lineWidth - usedWidth; } catch (BadLocationException e) { // log for now, unless we find reason not to Logger.log(Logger.INFO, e.getMessage()); } return currentAvailableLineWidth; }
final String lineText = document.get(orginalLineStart, originalLineLength); final IRegion formattedLineInformation = getFormattedLineInformation(originalLineInfo, lineText);
String content = document.get(lineInfo.getOffset(), lineInfo.getLength()); if (content.trim().length() > 0) { break;
String text = node.getStructuredDocument().get(lineOffset, nodeNameOffset - lineOffset); int usedWidth = getIndentationLength(text); currentAvailableLineWidth = preferences.getLineWidth() - usedWidth;
/** * So that the JSPTranslator can be reused. */ public void reset(IDOMNode node, IProgressMonitor progress) { // initialize some things on node configure(node, progress); reset(); // set the jsp text buffer fJspTextBuffer.append(fStructuredDocument.get()); }
/** * Return the blanks at the start of the line. */ public static String getLineBlanks(IStructuredDocument document, IRegion lineInfo) throws BadLocationException { helpBuffer.setLength(0); int startOffset = lineInfo.getOffset(); int length = lineInfo.getLength(); char[] line = document.get(startOffset, length).toCharArray(); for (int i = 0; i < line.length; i++) { char c = line[i]; if (Character.isWhitespace(c)) { helpBuffer.append(c); } else { break; } } return helpBuffer.toString(); }
/** * same as getFullText for this region type ... do we need to take white * space off? */ public String getText() { String result = null; try { IStructuredDocument parentDocument = _getParentDocument(); result = parentDocument.get(start, length); } catch (BadLocationException e) { Logger.logException("program error: unreachable exception", e); //$NON-NLS-1$ } return result; }
protected String primGetIndentString(Node node) { IStructuredDocument flatModel = ((IDOMNode) node).getStructuredDocument(); int nodeStartOff = ((IDOMNode) node).getStartOffset(); int startOff = Math.max(0, nodeStartOff - 100); int endOff = nodeStartOff; try { String text = flatModel.get(startOff, endOff - startOff); int inx = text.length() - 1; if (inx >= 0) { for (; inx >= 0; inx--) { char ch = text.charAt(inx); if (Character.isWhitespace(ch) && ch != '\n' && ch != '\r') { continue; } inx++; break; } return text.substring(inx); } } catch (BadLocationException ex) { Logger.logException(ex); } return ""; //$NON-NLS-1$ }
/** * This method will replace the string at offset and length with a new * string. If the string to be replaced is the same as the new string, the * string will not be replaced. */ protected void replace(IStructuredDocument structuredDocument, int offset, int length, String string) { try { String structuredDocumentString = structuredDocument.get(offset, length); if (structuredDocumentString.compareTo(string) != 0) structuredDocument.replaceText(structuredDocument, offset, length, string); } catch (BadLocationException e) { // log for now, unless we find reason not to Logger.log(Logger.INFO, e.getMessage()); } }
/** * */ protected String getValueForTextContent(List list) { String result = null; if (list.size() > 0) { IDOMNode first = (IDOMNode) list.get(0); IDOMNode last = (IDOMNode) list.get(list.size() - 1); IDOMModel model = first.getModel(); int start = first.getStartOffset(); int end = last.getEndOffset(); try { result = model.getStructuredDocument().get(start, end - start); } catch (Exception e) { } } // we trim the content so that it looks nice when viewed // we need to be carfull to preserve the 'trimmed' text when the value // is set (see setValueForTextContent) if (result != null) { result = result.trim(); } return result; }
String oldData = structuredDocument.get(); if (oldData == null) oldData = "";//$NON-NLS-1$
/** * Returns next word after the cursor position * * @throws BadLocationException */ public String getNextWord() throws BadLocationException { ITextRegion nextTwigToken = getNextTwigToken(); return document.get(regionCollection.getStartOffset() + twigScriptRegion.getStart() + nextTwigToken.getStart(), nextTwigToken.getTextLength()); }
public String getNextWord(int times) throws BadLocationException { ITextRegion nextTwigToken = getNextTwigToken(times); return document.get(regionCollection.getStartOffset() + twigScriptRegion.getStart() + nextTwigToken.getStart(), nextTwigToken.getTextLength()); }
/** * This method will replace the node value with a new string. If the node * value to be replaced is the same as the new string, the node value will * not be replaced. */ protected void replaceNodeValue(IDOMNode node, String string) { IDOMModel structuredModel = node.getModel(); IStructuredDocument structuredDocument = structuredModel.getStructuredDocument(); int offset = node.getStartOffset(); int length = node.getEndOffset() - node.getStartOffset(); try { String structuredDocumentString = structuredDocument.get(offset, length); if (structuredDocumentString.compareTo(string) != 0) replace(structuredDocument, offset, length, string); } catch (BadLocationException e) { // log for now, unless we find reason not to Logger.log(Logger.INFO, e.getMessage()); } }
oldValue = domElement.getModel().getStructuredDocument().get(start, end - start); domElement.getModel().getStructuredDocument().replaceText(documentationElement, start, end - start, newValue);
: flatnode.getParentDocument().get(requestStart, lengthToReplace); final int length = changes.length(); if (startQuoted(deletedText) || startQuoted(changes)) {