Package org.eclipse.jdt.core

Examples of org.eclipse.jdt.core.ISourceRange


    if (op != null){
      String lineDelim = src.findRecommendedLineSeparator();
      IImportDeclaration[] imports = src.getImports();
      int importsEnd = -1;
      if (imports.length > 0){
        ISourceRange last = imports[imports.length - 1].getSourceRange();
        importsEnd = last.getOffset() + last.getLength() + lineDelim.length();
      }

      op.run(null);

      // an op.getResultingEdit() would be nice here, but we'll make do w/ what
      // we got and caculate our own edit offset/length combo so we can format
      // the new code.
      int offset = pos != -1 ? pos : (len - 1 - lineDelim.length());
      int newLen = src.getBuffer().getLength();
      int length = newLen - len - 1;

      // a more accurate length estimate can be found by locating the
      //  sibling at its new position and taking the difference.
      //  this prevents the formatting from screwing up the sibling's formatting
      final IJavaElement[] newSiblings = sibling == null ?
          null : src.findElements(sibling);
      if (newSiblings != null && newSiblings.length == 1) {
        // not sure what it would mean if there were more than one...
        length = getOffset(newSiblings[0]) - offset;
      }

      // the change in length may include newly added imports, so handle that as
      // best we can
      int importLenChange = 0;
      imports = src.getImports();
      if (importsEnd != -1){
        ISourceRange last = imports[imports.length - 1].getSourceRange();
        importLenChange = last.getOffset() + last.getLength() +
          lineDelim.length() - importsEnd;
      }else if(imports.length > 0){
        ISourceRange first = imports[0].getSourceRange();
        ISourceRange last = imports[imports.length - 1].getSourceRange();
        importLenChange = last.getOffset() + last.getLength() +
          (lineDelim.length() * 2) - first.getOffset();
      }

      offset += importLenChange;
      length -= importLenChange;
View Full Code Here


        // Is it possible to have multiple roots? If so we'll need
        // to change this.
        result = formatRoot(roots[0], comparator, callees);

        IResource resource = method.getResource();
        ISourceRange sourceRange = method.getSourceRange();
        // The root element doesn't get his location like all the others
        // (this happens with the GUI too). So add it ourselves.
        result.put("position", Position.fromOffset(
              resource.getLocation().toOSString(), null, sourceRange.getOffset(),
              sourceRange.getLength()));
      }
    }

    return result;
  }
View Full Code Here

    }

    IType resultType = result.getTypes()[0];
    String name = resultType.getElementName();
    ISourceReference ref = resultType;
    ISourceRange docRange = resultType.getJavadocRange();

    IJavaElement element = src.getElementAt(offset);
    if(element != null && element.getElementType() == IJavaElement.METHOD){
      IMethod method = null;
      if (finder.isTest(src.getTypes()[0])){
        method = JUnitUtils.findClassMethod(result, (IMethod)element);
      }else{
        method = JUnitUtils.findTestMethod(result, (IMethod)element);
      }
      if (method != null){
        name = method.getElementName();
        ref = method;
        docRange = method.getJavadocRange();
      }
    }

    String lineDelim = result.findRecommendedLineSeparator();
    int docLength = docRange != null ?
      docRange.getLength() + lineDelim.length() : 0;
    return Position.fromOffset(
        result.getResource().getLocation().toOSString(), name,
        ref.getSourceRange().getOffset() + docLength, 0);
  }
View Full Code Here

  public ISourceRange getLast() {
    if (isEmpty())
      return null;
    int size= fHistory.size();
    ISourceRange result= (ISourceRange)fHistory.remove(size - 1);
//    fHistoryAction.update(); TODO correctement
    return result;
  }
View Full Code Here

    Annotation[] astAnnotations = new Annotation[length];
    if (length > 0) {
      char[] cuSource = getSource();
      int recordedAnnotations = 0;
      for (int i = 0; i < length; i++) {
        ISourceRange positions = annotations[i].getSourceRange();
        int start = positions.getOffset();
        int end = start + positions.getLength();
        char[] annotationSource = CharOperation.subarray(cuSource, start, end);
        if (annotationSource != null) {
            Expression expression = parseMemberValue(annotationSource);
            /*
             * expression can be null or not an annotation if the source has changed between
View Full Code Here

        if (buf == null) {
          // no source attachment found. This method maybe the one. Stop.
          return InheritDocVisitor.STOP_BRANCH;
        }

        ISourceRange javadocRange= member.getJavadocRange();
        if (javadocRange == null)
          return InheritDocVisitor.CONTINUE;  // this method doesn't have javadoc, continue to look.
        String rawJavadoc= buf.getText(javadocRange.getOffset(), javadocRange.getLength());
        if (rawJavadoc != null) {
          return overridden;
        }
        return InheritDocVisitor.CONTINUE;
      }
View Full Code Here

        System.out.print("SELECTION - accept method("); //$NON-NLS-1$
        System.out.print(method.toString());
        System.out.println(")"); //$NON-NLS-1$
      }
    } else {
      ISourceRange range = method.getSourceRange();
      if (range.getOffset() != -1 && range.getLength() != 0 ) {
        if (uniqueKey != null) {
          ResolvedBinaryMethod resolvedMethod = new ResolvedBinaryMethod(
              (JavaElement)method.getParent(),
              method.getElementName(),
              method.getParameterTypes(),
View Full Code Here

    if(type != null) {
      try {
        IField[] fields = type.getFields();
        for (int i = 0; i < fields.length; i++) {
          IField field = fields[i];
          ISourceRange range = field.getNameRange();
          if(range.getOffset() <= start
              && range.getOffset() + range.getLength() >= end
              && field.getElementName().equals(new String(name))) {
            addElement(fields[i]);
            if(SelectionEngine.DEBUG){
              System.out.print("SELECTION - accept field("); //$NON-NLS-1$
              System.out.print(field.toString());
View Full Code Here

  String name = new String(selector);
  IMethod[] methods = null;
  try {
    methods = type.getMethods();
    for (int i = 0; i < methods.length; i++) {
      ISourceRange range = methods[i].getNameRange();
      if(range.getOffset() <= start
          && range.getOffset() + range.getLength() >= end
          && methods[i].getElementName().equals(name)) {
        addElement(methods[i]);
        if(SelectionEngine.DEBUG){
          System.out.print("SELECTION - accept method("); //$NON-NLS-1$
          System.out.print(this.elements[0].toString());
View Full Code Here

    IMethod[] methods = null;

    try {
      methods = type.getMethods();
      done : for (int i = 0; i < methods.length; i++) {
        ISourceRange range = methods[i].getNameRange();
        if(range.getOffset() >= selectorStart
            && range.getOffset() + range.getLength() <= selectorEnd
            && methods[i].getElementName().equals(name)) {
          method = methods[i];
          break done;
        }
      }
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.core.ISourceRange

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.