Examples of IModelElement


Examples of org.eclipse.dltk.core.IModelElement

    if (!(arguments instanceof ScriptRefactoringArguments))
      return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.InitializableRefactoring_inacceptable_arguments);
    final ScriptRefactoringArguments extended = (ScriptRefactoringArguments) arguments;
    final String handle = extended.getAttribute(ScriptRefactoringDescriptor.ATTRIBUTE_INPUT);
    if (handle != null) {
      final IModelElement element = ScriptRefactoringDescriptor.handleToElement(extended.getProject(), handle, false);
      if (element != null && element.exists()) {
        if (element.getElementType() == IModelElement.SOURCE_MODULE) {
          cu = (ISourceModule) element;
        } else if (element.getElementType() == IModelElement.LOCAL_VARIABLE) {
          modelElement = (ILocalVariable) element;
          cu = (ISourceModule) modelElement.getAncestor(IModelElement.SOURCE_MODULE);
          if (cu == null)
            return ScriptableRefactoring.createInputFatalStatus(element, getProcessorName(), IPHPRefactorings.RENAME_LOCAL_VARIABLE);
        } else
          return ScriptableRefactoring.createInputFatalStatus(element, getProcessorName(), IPHPRefactorings.RENAME_LOCAL_VARIABLE);
      } else
        return ScriptableRefactoring.createInputFatalStatus(element, getProcessorName(), IPHPRefactorings.RENAME_LOCAL_VARIABLE);
    } else {
      return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, ScriptRefactoringDescriptor.ATTRIBUTE_INPUT));
    }
    final String name = extended.getAttribute(ScriptRefactoringDescriptor.ATTRIBUTE_NAME);
    if (name != null && !"".equals(name)) //$NON-NLS-1$
      setNewElementName(name);
    else
      return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, ScriptRefactoringDescriptor.ATTRIBUTE_NAME));
    if (cu != null && modelElement == null) {
      final String selection = extended.getAttribute(ScriptRefactoringDescriptor.ATTRIBUTE_SELECTION);
      if (selection != null) {
        int offset= -1;
        int length= -1;
        final StringTokenizer tokenizer = new StringTokenizer(selection);
        if (tokenizer.hasMoreTokens())
          offset = Integer.valueOf(tokenizer.nextToken()).intValue();
        if (tokenizer.hasMoreTokens())
          length = Integer.valueOf(tokenizer.nextToken()).intValue();
        if (offset >= 0 && length >= 0) {
          try {
            final IModelElement[] elements = cu.codeSelect(offset, length);
            if (elements != null) {
              for (int index = 0; index < elements.length; index++) {
                final IModelElement element = elements[index];
                if (element instanceof ILocalVariable)
                  modelElement = (ILocalVariable) element;
              }
            }
            if (modelElement == null)
View Full Code Here

Examples of org.eclipse.dltk.core.IModelElement

  @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 {
                return visit((VariableReference) s);
              }

              @Override
              public boolean visit(VariableReference s) throws Exception {
                if (s.sourceStart() >= enclosingElementSourceStart && s.sourceEnd() <= enclosingElementSourceEnd
                    && s.getName().equals(modelElement.getElementName())
                    && s.sourceStart() != declarationSourceRange.getOffset()) {
                  IModelElement sourceElement = PDTModelUtils.getSourceElement(cu, s.sourceStart(), s.matchLength());
                  if (sourceElement != null && sourceElement.equals(modelElement)) {
                    addTextEdit(changeManager.get(cu), getProcessorName(), new ReplaceEdit(s.sourceStart(), getCurrentElementName().length(), getNewElementName()));
                  }
                }

                return true;
View Full Code Here

Examples of org.eclipse.dltk.core.IModelElement

          }
        } else if (element instanceof IImplForPhp) {
          element = ((IImplForPhp) element).getModelElement();
          if (element != null && ActionUtil.isEditable(getShell(), (IModelElement) element)) {
            if (element instanceof ISourceModule && selection instanceof ITextSelection) {
              IModelElement sourceElement = getSourceElement((ISourceModule) element, ((ITextSelection) selection).getOffset(), ((ITextSelection) selection).getLength());
              if (sourceElement != null && ActionUtil.isEditable(getShell(), sourceElement) && isRenameAvailable(sourceElement)) {
                run(sourceElement);
                return;
              }
            }
View Full Code Here

Examples of org.eclipse.dltk.core.IModelElement

  public void run(ITextSelection selection) {
    if (editor != null && ActionUtil.isEditable(editor)) {
      try {
        IModelElement[] elements = SelectionConverter.codeResolve(editor);
        if (elements != null && elements.length == 1) {
          IModelElement sourceElement = getSourceElement(elements[0], selection.getOffset(), selection.getLength());
          if (sourceElement != null && ActionUtil.isEditable(getShell(), sourceElement) && isRenameAvailable(sourceElement)) {
            run(sourceElement);
            return;
          }
        }
View Full Code Here

Examples of org.eclipse.dltk.core.IModelElement

    return getSourceElement(sourceModule, offset, length);
  }

  private static IModelElement getSourceElement(ISourceModule sourceModule, int offset, int length) throws CoreException {
    IModelElement sourceElement = PDTModelUtils.getSourceElement(sourceModule, offset, length);
    if (sourceElement instanceof IMethod) {
      IMethod farthestOverriddenMethod = new PHPMethod((IMethod) sourceElement).getFarthestOverriddenMethod();
      if (sourceElement.equals(farthestOverriddenMethod)) {
        return sourceElement;
      } else {
        return farthestOverriddenMethod;
      }
    } else {
View Full Code Here

Examples of org.eclipse.dltk.core.IModelElement

 
  @SuppressWarnings("rawtypes")
  @Override
  public Object execute(ExecutionEvent event) throws ExecutionException {

    IModelElement element = getCurrentModelElement(event);
   
    if (element == null) {     
        return exitMessage();
    }
   
    if (!(element instanceof SourceType)) {     
      while(element.getParent() != null) {       
        element = element.getParent();       
        if (element instanceof SourceType) {
          break;
        }
      }
    }
View Full Code Here

Examples of org.eclipse.dltk.core.IModelElement

        .getTextEditor();

    try {

      if (textEditor instanceof PHPStructuredEditor) {
        IModelElement editorElement = ((PHPStructuredEditor) textEditor)
            .getModelElement();
        if (editorElement != null) {

          char indentChar = FormatterUtils
              .getFormatterCommonPrferences()
View Full Code Here

Examples of org.eclipse.dltk.core.IModelElement

      public Object visitDubElement(IDubElement dubElement) {
        return dubElement.getParent();
      }
      @Override
      public Object visitModelElement(IModelElement element, IParent elementAsParent) {
        IModelElement parent = element.getParent();
        if(parent instanceof IProjectFragment) {
          // TODO: need to map to DepSourceContainer
          return null;
        }
        return parent;
View Full Code Here

Examples of org.eclipse.dltk.core.IModelElement

          for (Reference pair : expectedReferences) {
            Reference reference = pair;
           
            String refModuleName = reference.getModuleNode().getModuleFullyQualifiedName();
           
            IModelElement modelElement = downCast(referenceMatch.getElement());
            ISourceModule matchSrcModule = DeeSearchEngineTestUtils.getSourceModule(modelElement);
           
            String matchModuleName = DeeSearchEngineTestUtils.getSourceModuleFQName(matchSrcModule);
           
            if(areEqual(refModuleName, matchModuleName) &&
View Full Code Here

Examples of org.eclipse.dltk.core.IModelElement

        }
        if (found)
          break;
      }
    }
    IModelElement elements[] = null;
    namespaceStack.push(fileNameWithoutExtension);
    try {
      elements = sourceModule.getChildren();
      for (int i = 0; i < elements.length; i++) {
        IModelElement modelElement = elements[i];
        int elementType = modelElement.getElementType();
        if (elementType == type) {
          if (elementType == IModelElement.METHOD) {
            imports.add(namespaceStack.peek() + "." + modelElement.getElementName());
          } else if (appendPath) {
            imports.add(path + "." + modelElement.getElementName());
          } else {
            imports.add(modelElement.getElementName());
          }
        }
        if (elementType == IModelElement.METHOD) {
          String nSpace = namespaceStack.empty() ? modelElement.getElementName() : namespaceStack
                  .peek() + "." + modelElement.getElementName();
          namespaceStack.push(nSpace);
          imports.addAll(collectElements((IMethod) modelElement, type, namespaceStack));
          namespaceStack.pop();
        }
      }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.