Package org.eclipse.dltk.core

Examples of org.eclipse.dltk.core.IModelElement


  public void apply(ICompletionReporter reporter) throws Exception {

    SuperclassMethodContext context = (SuperclassMethodContext) getContext();
    ISourceModule module = context.getSourceModule();

    IModelElement element = module.getElementAt(context.getOffset());

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


      return false;
    }

    try {

      IModelElement elem = sourceModule.getElementAt(offset);

      if (elem instanceof SourceType) {
        SourceType type = (SourceType) elem;

        if (type.getSuperClasses().length > 0) {
View Full Code Here

   *            <code>false</code> otherwise
   * @return the corresponding PHP element, or <code>null</code> if no such
   *         element exists
   */
  public static IModelElement handleToElement(final WorkingCopyOwner owner, final String project, final String handle, final boolean check) {
    IModelElement element = owner == null ? element = DLTKCore.create(handle) : DLTKCore.create(handle, owner);

    if (element == null && project != null) {
      final IScriptProject phpProject = DLTKCore.create(ResourcesPlugin.getWorkspace().getRoot()).getScriptProject(project);
      final String identifier = phpProject.getHandleIdentifier();
      element = owner == null ? DLTKCore.create(identifier + handle) : DLTKCore.create(identifier + handle, owner);
    }

    if (check && element instanceof IMethod) {
      /*
       * Resolve the method based on simple names of parameter types
       * (to accommodate for different qualifications when refactoring is e.g.
       * recorded in source but applied on binary method):
       */
      final IMethod method = (IMethod) element;
      final IMethod[] methods = method.getDeclaringType().findMethods(method);
      if (methods != null && methods.length > 0) {
        element = methods[0];
      }
    }

    if (element == null) {
      return null;
    } else {
      if (check) {
        if (element.exists()) {
          return element;
        } else {
          return null;
        }
      } else {
View Full Code Here

                try {
                  moduleDeclaration.traverse(new PHPASTVisitor() {
                    @Override
                    public boolean visit(FullyQualifiedReference s) throws Exception {
                      if (s.sourceStart() == match.getOffset() && s.sourceEnd() == match.getOffset() + match.getLength()) {
                        IModelElement sourceElement = PDTModelUtils.getSourceElement(module, s.sourceStart(), s.matchLength());
                        if (sourceElement != null) {
                          IType sourceType = (IType) sourceElement.getAncestor(IModelElement.TYPE);
                          if (sourceType != null && new PHPType(sourceType).isInstanceOf((IType) modelElement)) {
                            int offset;
                            if (s.getNamespace() == null) {
                              offset = s.sourceStart();
                            } else {
View Full Code Here

                    } catch (MalformedTreeException e) {
                      // conflicting update -> omit text match
                    }
                  }
                } else {
                  IModelElement sourceElement = PDTModelUtils.getSourceElement(module, expression.getCallName().sourceStart(), expression.getCallName().matchLength());
                  if (sourceElement != null && sourceElement.getElementType() == IModelElement.METHOD) {
                    IType declaringType = ((IMethod) sourceElement).getDeclaringType();
                    if (declaringType != null && new PHPType(declaringType).isInstanceOf(method.getDeclaringType())) {
                      try {
                        addTextEdit(
                          changeManager.get(module),
View Full Code Here

      IProject project = null;
     
      if (receiver instanceof IImplForPhp) {
       
        IImplForPhp phpElement = (ElementImplForPhp) receiver;
        IModelElement element = phpElement.getModelElement();
       
        if (element == null) {
          return false;
        }
       
        project = element.getScriptProject().getProject();
      } else if (receiver instanceof ISourceModule) {
        ISourceModule source = (ISourceModule) receiver;
        project = source.getScriptProject().getProject();
      } else if (receiver instanceof IProject) {
        project = (IProject) receiver;
View Full Code Here

    IDocument document = viewer.getDocument();
    PHPStructuredEditor textEditor = (PHPStructuredEditor) ((PHPStructuredTextViewer) viewer)
        .getTextEditor();

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

        IModelElement input = EditorUtility.getEditorInputModelElement(textEditor, false);

        if (input instanceof ICodeAssist) {
         
          try {
           
            int repOffset = getReplacementOffset();
            int length = getReplacementLength();
            IDLTKSearchScope scope = SearchEngine.createSearchScope(input.getScriptProject());
            String type = document.get(repOffset, length);
            IType[] types = PhpModelAccess.getDefault().findTypes(null, type, MatchRule.EXACT, 0, 0, scope, new NullProgressMonitor());
           
            if (types.length == 1) {
              this.type = types[0];
View Full Code Here

    IDocument document = viewer.getDocument();
    ITextEditor textEditor = ((PHPStructuredTextViewer) viewer)
        .getTextEditor();

    if (textEditor instanceof PHPStructuredEditor) {
      IModelElement editorElement = ((PHPStructuredEditor) textEditor)
          .getModelElement();
      if (editorElement != null) {
       
        ISourceModule sourceModule = ((ModelElement) editorElement)
            .getSourceModule();
View Full Code Here

    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

  @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

TOP

Related Classes of org.eclipse.dltk.core.IModelElement

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.