Package org.eclipse.dltk.core

Examples of org.eclipse.dltk.core.ISourceRange


  protected RefactoringStatus renameDeclaration(IProgressMonitor pm) throws CoreException {
    return renameDeclaration(pm, modelElement, cu);
  }

  protected RefactoringStatus renameDeclaration(IProgressMonitor pm, IModelElement modelElement, ISourceModule sourceModule) throws CoreException {
    ISourceRange sourceRange = null;
    if (modelElement instanceof IMember) {
      sourceRange = ((IMember) modelElement).getNameRange();
    }
    if (sourceRange != null) {
      addTextEdit(changeManager.get(sourceModule), getProcessorName(), new ReplaceEdit(sourceRange.getOffset(), modelElement.getElementName().length(), getNewElementName()));
    }

    return new RefactoringStatus();
  }
View Full Code Here


  @Override
  protected RefactoringStatus updateReferences(IProgressMonitor pm) throws CoreException {
    ModuleDeclaration moduleDeclaration = SourceParserUtil.getModuleDeclaration(cu);
    if (moduleDeclaration != null) {
      IModelElement enclosingElement = modelElement.getParent();
      final ISourceRange declarationSourceRange = ((IField) modelElement).getNameRange();
      if (enclosingElement != null && declarationSourceRange != null) {
        ISourceRange enclosingElementSourceRange = null;

        if (enclosingElement.getElementType() == IModelElement.METHOD) {
          enclosingElementSourceRange = ((IMethod) enclosingElement).getSourceRange();
        } else if (enclosingElement.getElementType() == IModelElement.SOURCE_MODULE) {
          enclosingElementSourceRange = ((ISourceModule) enclosingElement).getSourceRange();
        }

        if (enclosingElementSourceRange != null) {
          final int enclosingElementSourceStart = enclosingElementSourceRange.getOffset();
          final int enclosingElementSourceEnd = enclosingElementSourceRange.getOffset() + enclosingElementSourceRange.getLength();

          try {
            moduleDeclaration.traverse(new PHPASTVisitor() {
              @Override
              public boolean visit(ArrayVariableReference s) throws Exception {
View Full Code Here

   3. the variable is local (local scope or a parameter for the covering method)
   *
   */
  private void computeRequiredArgumentsForExtractedMethod() {

    ISourceRange selectedRange = getSelectedRange();
    ISourceRange preSelectedRange = getPreSelectedRange();
   
    // Since we're iterating over fMethodVariables (this is gathered by LocalVariableFinder
    // those variables are already local (so 3. is fulfilled)
    // covers 3.
    for(Variable possibleParameter : fMethodVariables)
View Full Code Here

   * which is not the same code! So we have to return $object even though $object is an object.
   *
   */
  private void computeMethodReturnValues() {

    ISourceRange preSelectedRange = getPreSelectedRange();
    ISourceRange postSelectionRange = getPostSelectedRange();
    ISourceRange selectedRange = getSelectedRange();
   
    // again, 3. is fulfilled, since fMethodVariables only contains local variables
    for(Variable var : fMethodVariables)
    {
      // covers 5.
View Full Code Here

   * of $obj at the end of the extracted method, since it's reference was changed.
   *  
   */
  private boolean isUsedAsObject(Variable var) {
   
    ISourceRange preSelectedRange = getPreSelectedRange();
    ISourceRange selectedRange = getSelectedRange();
   
    Variable lastObjectAssignment = null;
   
    // first we collect all assignments to var before the selected code.
    // and we take the last one of it, and hope that the last assignment is an object assignment
View Full Code Here

   
    Program program = parser.createAST(new NullProgressMonitor());     
//    program.recordModifications();   
//    AST ast = program.getAST();   

    ISourceRange range = type.getSourceRange();   
    ASTNode node = program.getElementAt(range.getOffset());

    if (!(node instanceof ClassDeclaration)) {
      return ;       
    }
   
    char indentChar = FormatterUtils
        .getFormatterCommonPrferences().getIndentationChar(document);
    String indent = String.valueOf(indentChar);
   
    ClassDeclaration clazz = (ClassDeclaration) node;
    Block body = clazz.getBody();
    List<Statement> bodyStatements = body.statements();
       

    int end = bodyStatements.get(bodyStatements.size()-1).getEnd();
   
    if (insertFirst) {
      end = bodyStatements.get(0).getStart() - 1;
    } else if (insertAfter != null) {
     
      boolean found = false;
     
      for (IMethod method : type.getMethods()) {       
        if (method == insertAfter) {
          ISourceRange r = method.getSourceRange();
          end = r.getOffset() + r.getLength();
          found = true;
        }
      }
     
      if (!found) {       
        for (IField field : type.getFields()) {
          ISourceRange r = field.getSourceRange();
          end = r.getOffset() + r.getLength() + 1;
        }
      }
    }
   
    lineDelim = TextUtilities.getDefaultLineDelimiter(document);
View Full Code Here

                final int kind = element.getElementType();
                if (kind == IModelElement.TYPE || kind == IModelElement.METHOD) {

                  final ISourceReference reference = (ISourceReference) element;
                  final ISourceRange range = reference.getSourceRange();

                  if (range != null) {
                    viewer.setSelectedRange(range.getOffset(), range.getLength());
                    viewer.doOperation(ISourceViewer.FORMAT);
                  }
                }
              }
            } catch (ModelException exception) {
View Full Code Here

  protected String getHeaderComment(IMember member) {
    if (member instanceof IField) {
      return null;
    }
    try {
      ISourceRange range = member.getSourceRange();
      if (range == null)
        return null;

      IBuffer buf = null;

      ISourceModule compilationUnit = member.getSourceModule();
      if (!compilationUnit.isConsistent()) {
        return null;
      }

      buf = compilationUnit.getBuffer();

      final int start = range.getOffset();

      String contents = buf.getContents();

      String result = "";
View Full Code Here

          default:
            assertFail();
          }
         
          IMember member = (IMember) modelElement;
          ISourceRange nameRange = member.getNameRange();
          if(nameRange != null && nameRange.getOffset() == defUnit.defname.getStartPos()) {
            return member; // We found a perfect match
          }
          bestMatch = member;
        }
      }
View Full Code Here

                final int kind = element.getElementType();
                if (kind == IModelElement.TYPE || kind == IModelElement.METHOD) {

                  final ISourceReference reference = (ISourceReference) element;
                  final ISourceRange range = reference.getSourceRange();

                  if (range != null) {
                    viewer.setSelectedRange(range.getOffset(), range.getLength());
                    viewer.doOperation(ISourceViewer.FORMAT);
                  }
                }
              }
            } catch (ModelException exception) {
View Full Code Here

TOP

Related Classes of org.eclipse.dltk.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.