Ejemplo n.º 1
0
  /** Loads the buffer via SourceMapper, and maps it in SourceMapper */
  private IBuffer mapSource(SourceMapper mapper, IBinaryType info, IClassFile bufferOwner) {
    char[] contents = mapper.findSource(getType(), info);
    if (contents != null) {
      // create buffer
      IBuffer buffer = BufferManager.createBuffer(bufferOwner);
      if (buffer == null) return null;
      BufferManager bufManager = getBufferManager();
      bufManager.addBuffer(buffer);

      // set the buffer source
      if (buffer.getCharacters() == null) {
        buffer.setContents(contents);
      }

      // listen to buffer changes
      buffer.addBufferChangedListener(this);

      // do the source mapping
      mapper.mapSource(getOuterMostEnclosingType(), contents, info);

      return buffer;
    } else {
      // create buffer
      IBuffer buffer = BufferManager.createNullBuffer(bufferOwner);
      if (buffer == null) return null;
      BufferManager bufManager = getBufferManager();
      bufManager.addBuffer(buffer);

      // listen to buffer changes
      buffer.addBufferChangedListener(this);
      return buffer;
    }
  }
Ejemplo n.º 2
0
 /*
  * @see ISourceReference
  */
 public ISourceRange getSourceRange() throws JavaModelException {
   SourceMapper mapper = getSourceMapper();
   if (mapper != null) {
     // ensure the class file's buffer is open so that source ranges are computed
     ClassFile classFile = (ClassFile) getClassFile();
     if (classFile != null) {
       classFile.getBuffer();
       return mapper.getSourceRange(this);
     }
   }
   return super.getSourceRange();
 }
Ejemplo n.º 3
0
 public ISourceRange getNameRange() throws JavaModelException {
   SourceMapper mapper = getSourceMapper();
   if (mapper != null) {
     ClassFile classFile = (ClassFile) getClassFile();
     if (classFile != null) {
       // ensure the class file's buffer is open so that source ranges are computed
       classFile.getBuffer();
       return mapper.getNameRange(this);
     }
   }
   AnnotationInfo info = (AnnotationInfo) getElementInfo();
   return new SourceRange(info.nameStart, info.nameEnd - info.nameStart + 1);
 }
Ejemplo n.º 4
0
  /** Loads the buffer via SourceMapper, and maps it in SourceMapper */
  private IBuffer mapSource(
      SourceMapper mapper, ClassFileElementInfo info, IClassFile bufferOwner) {
    char[] contents =
        mapper.findSource(getPart(), info.getEglFileName(), info.getCaseSensitivePackageName());
    // create buffer
    BufferManager bufManager = getBufferManager();
    IBuffer buffer = bufManager.createBuffer(bufferOwner);
    if (buffer == null) return null;
    bufManager.addBuffer(buffer);

    if (contents != null) {
      // set the buffer source
      if (buffer.getCharacters() == null) {
        buffer.setContents(contents);
      }
    } else {
      if (buffer.getCharacters() == null) {
        String result = EGLModelResources.eglarNoSourceAttachmentContent;
        buffer.setContents(result.toCharArray());
      }
    }

    buffer.addBufferChangedListener(this);
    return buffer;
  }
 /**
  * {@inheritDoc}
  *
  * @since 3.7
  */
 public ISourceRange getSourceRange() throws JavaModelException {
   if (this.declarationSourceEnd == -1) {
     SourceMapper mapper = getSourceMapper();
     if (mapper != null) {
       // ensure the class file's buffer is open so that source ranges are computed
       ClassFile classFile = (ClassFile) getClassFile();
       if (classFile != null) {
         classFile.getBuffer();
         return mapper.getSourceRange(this);
       }
     }
     return SourceMapper.UNKNOWN_RANGE;
   }
   return new SourceRange(
       this.declarationSourceStart, this.declarationSourceEnd - this.declarationSourceStart + 1);
 }
Ejemplo n.º 6
0
  public IJavaElement getElementAtConsideringSibling(int position) throws JavaModelException {
    IPackageFragment fragment = (IPackageFragment) getParent();
    PackageFragmentRoot root =
        (PackageFragmentRoot) fragment.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
    SourceMapper mapper = root.getSourceMapper();
    if (mapper == null) {
      return null;
    } else {
      int index = this.name.indexOf('$');
      int prefixLength = index < 0 ? this.name.length() : index;

      IType type = null;
      int start = -1;
      int end = Integer.MAX_VALUE;
      IJavaElement[] children = fragment.getChildren();
      for (int i = 0; i < children.length; i++) {
        String childName = children[i].getElementName();

        int childIndex = childName.indexOf('$');
        int childPrefixLength = childIndex < 0 ? childName.indexOf('.') : childIndex;
        if (prefixLength == childPrefixLength
            && this.name.regionMatches(0, childName, 0, prefixLength)) {
          IClassFile classFile = (IClassFile) children[i];

          // ensure this class file's buffer is open so that source ranges are computed
          classFile.getBuffer();

          SourceRange range = mapper.getSourceRange(classFile.getType());
          if (range == SourceMapper.UNKNOWN_RANGE) continue;
          int newStart = range.getOffset();
          int newEnd = newStart + range.getLength() - 1;
          if (newStart > start && newEnd < end && newStart <= position && newEnd >= position) {
            type = classFile.getType();
            start = newStart;
            end = newEnd;
          }
        }
      }
      if (type != null) {
        return findElement(type, position, mapper);
      }
      return null;
    }
  }
 /**
  * {@inheritDoc}
  *
  * @since 3.7
  */
 public ISourceRange getNameRange() {
   if (this.nameEnd == -1) {
     SourceMapper mapper = getSourceMapper();
     if (mapper != null) {
       try {
         // ensure the class file's buffer is open so that source ranges are computed
         ClassFile classFile = (ClassFile) getClassFile();
         if (classFile != null) {
           classFile.getBuffer();
           return mapper.getNameRange(this);
         }
       } catch (JavaModelException e) {
         // ignore
       }
     }
     return SourceMapper.UNKNOWN_RANGE;
   }
   return new SourceRange(this.nameStart, this.nameEnd - this.nameStart + 1);
 }
 /**
  * {@inheritDoc}
  *
  * @since 3.7
  */
 public int getFlags() {
   if (this.flags == -1) {
     SourceMapper mapper = getSourceMapper();
     if (mapper != null) {
       try {
         // ensure the class file's buffer is open so that source ranges are computed
         ClassFile classFile = (ClassFile) getClassFile();
         if (classFile != null) {
           classFile.getBuffer();
           return mapper.getFlags(this);
         }
       } catch (JavaModelException e) {
         // ignore
       }
     }
     return 0;
   }
   return this.flags & ExtraCompilerModifiers.AccJustFlag;
 }
Ejemplo n.º 9
0
 /**
  * Finds the deepest <code>IJavaElement</code> in the hierarchy of
  * <code>elt</elt>'s children (including <code>elt</code> itself)
  * which has a source range that encloses <code>position</code>
  * according to <code>mapper</code>.
  */
 protected IJavaElement findElement(IJavaElement elt, int position, SourceMapper mapper) {
   SourceRange range = mapper.getSourceRange(elt);
   if (range == null
       || position < range.getOffset()
       || range.getOffset() + range.getLength() - 1 < position) {
     return null;
   }
   if (elt instanceof IParent) {
     try {
       IJavaElement[] children = ((IParent) elt).getChildren();
       for (int i = 0; i < children.length; i++) {
         IJavaElement match = findElement(children[i], position, mapper);
         if (match != null) {
           return match;
         }
       }
     } catch (JavaModelException npe) {
       // elt doesn't exist: return the element
     }
   }
   return elt;
 }
Ejemplo n.º 10
0
 /**
  * Return a Reader cooresponding to the source of this location. Return null if not available.
  * Note: returned reader must be closed.
  */
 static BufferedReader sourceReader(Location location) {
   return sourceMapper.sourceReader(location);
 }
Ejemplo n.º 11
0
 static String getSourcePath() {
   return sourceMapper.getSourcePath();
 }