示例#1
0
 /**
  * Compute a region that represents the portion of the string literal between the opening and
  * closing quotes.
  *
  * @param nodeStart the index of the first character of the string literal
  * @param nodeLength the length of the string literal (including quotes)
  * @return the region that was computed
  */
 private IRegion computeInternalStringRegion(int nodeStart, int nodeLength) {
   int start = nodeStart;
   int end = nodeStart + nodeLength - 1;
   try {
     String source = compilationUnit.getBuffer().getContents();
     if (source.charAt(start) == '@') {
       start++;
     }
     if (source.charAt(start) == '\'') {
       while (source.charAt(start) == '\'') {
         start++;
       }
       while (source.charAt(end) == '\'') {
         end--;
       }
     } else {
       while (source.charAt(start) == '"') {
         start++;
       }
       while (source.charAt(end) == '"') {
         end--;
       }
     }
   } catch (DartModelException exception) {
   }
   if (start >= end) {
     return new Region(nodeStart, nodeLength);
   }
   return new Region(start, end - start + 1);
 }
示例#2
0
 /**
  * Return the existing document for the given compilation unit, or a DocumentAdapter if none.
  *
  * @return the existing document for the given compilation unit
  */
 protected IDocument getDocument(CompilationUnit cu) throws DartModelException {
   Buffer buffer = cu.getBuffer();
   if (buffer instanceof IDocument) {
     return (IDocument) buffer;
   }
   return new DocumentAdapter(buffer);
 }
示例#3
0
 /**
  * Compute a region representing the portion of the source containing a binary operator.
  *
  * @param left the index of the first character to the right of the left operand
  * @param right the index of the first character to the left of the right operand
  * @return the region that was computed
  */
 private IRegion computeOperatorRegion(int left, int right) {
   int start = left;
   int end = right;
   try {
     String source = compilationUnit.getBuffer().getContents();
     // TODO(brianwilkerson) This doesn't handle comments that occur between left and right, but
     // should.
     while (Character.isWhitespace(source.charAt(start))) {
       start++;
     }
     while (Character.isWhitespace(source.charAt(end))) {
       end--;
     }
   } catch (DartModelException exception) {
   }
   if (start > end) {
     return new Region(left, right - left + 1);
   }
   return new Region(start, end - start + 1);
 }