@Override
 public void delete() throws IncorrectOperationException {
   LOG.assertTrue(getTreeParent() != null);
   CheckUtil.checkWritable(this);
   getTreeParent().deleteChildInternal(this);
   this.invalidate();
 }
Ejemplo n.º 2
0
 @Override
 public void checkDelete() throws IncorrectOperationException {
   if (!getViewProvider().isEventSystemEnabled()) {
     throw new IncorrectOperationException();
   }
   CheckUtil.checkWritable(this);
 }
  @Override
  public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
    CheckUtil.checkWritable(this);
    if (isReferenceTo(element)) return this;

    if (element instanceof PsiMethod) {
      final PsiMethod method = (PsiMethod) element;
      final String methodName = method.getName();
      if (isDirectlyVisible(method)) return replaceReference(methodName);

      final AbstractQualifiedReference result =
          replaceReference(method.getContainingClass().getQualifiedName() + "." + methodName);
      final AbstractQualifiedReference qualifier = result.getQualifier();
      assert qualifier != null;
      qualifier.shortenReferences();
      return result;
    }
    if (element instanceof PsiClass) {
      return replaceReference(((PsiClass) element).getQualifiedName()).shortenReferences();
    }
    if (element instanceof PsiPackage) {
      return replaceReference(((PsiPackage) element).getQualifiedName());
    }
    if (element instanceof PsiMetaOwner) {
      final PsiMetaData metaData = ((PsiMetaOwner) element).getMetaData();
      if (metaData != null) {
        final String name = metaData.getName(this);
        if (name != null) {
          return replaceReference(name);
        }
      }
    }
    return this;
  }
Ejemplo n.º 4
0
 @Override
 public PsiElement add(@NotNull PsiElement element) throws IncorrectOperationException {
   CheckUtil.checkWritable(this);
   TreeElement elementCopy = ChangeUtil.copyToElement(element);
   calcTreeElement().addInternal(elementCopy, elementCopy, null, null);
   elementCopy = ChangeUtil.decodeInformation(elementCopy);
   return SourceTreeToPsiMap.treeElementToPsi(elementCopy);
 }
Ejemplo n.º 5
0
 @Override
 public PsiElement addAfter(@NotNull PsiElement element, PsiElement anchor)
     throws IncorrectOperationException {
   CheckUtil.checkWritable(this);
   TreeElement elementCopy = ChangeUtil.copyToElement(element);
   calcTreeElement()
       .addInternal(
           elementCopy, elementCopy, SourceTreeToPsiMap.psiElementToTree(anchor), Boolean.FALSE);
   elementCopy = ChangeUtil.decodeInformation(elementCopy);
   return SourceTreeToPsiMap.treeElementToPsi(elementCopy);
 }
Ejemplo n.º 6
0
 public static void deleteClass(@NotNull JetClassOrObject clazz) {
   CheckUtil.checkWritable(clazz);
   JetFile file = (JetFile) clazz.getContainingFile();
   List<JetDeclaration> declarations = file.getDeclarations();
   if (declarations.size() == 1) {
     file.delete();
   } else {
     PsiElement parent = clazz.getParent();
     CodeEditUtil.removeChild(parent.getNode(), clazz.getNode());
   }
 }
Ejemplo n.º 7
0
 @Override
 public void shortenClassReferences(@NotNull PsiElement element, int startOffset, int endOffset)
     throws IncorrectOperationException {
   CheckUtil.checkWritable(element);
   if (SourceTreeToPsiMap.hasTreeElement(element)) {
     final ReferenceAdjuster adjuster =
         ReferenceAdjuster.Extension.getReferenceAdjuster(element.getLanguage());
     if (adjuster != null) {
       adjuster.processRange(element.getNode(), startOffset, endOffset, myProject);
     }
   }
 }
  @Override
  public PsiElement replace(@NotNull PsiElement newElement) throws IncorrectOperationException {
    LOG.assertTrue(getTreeParent() != null);
    CheckUtil.checkWritable(this);
    TreeElement elementCopy = ChangeUtil.copyToElement(newElement);
    getTreeParent().replaceChildInternal(this, elementCopy);
    elementCopy = ChangeUtil.decodeInformation(elementCopy);
    final PsiElement result = SourceTreeToPsiMap.treeElementToPsi(elementCopy);

    this.invalidate();
    return result;
  }
Ejemplo n.º 9
0
 @Override
 public void optimizeImports(@NotNull PsiFile file) throws IncorrectOperationException {
   CheckUtil.checkWritable(file);
   if (file instanceof PsiJavaFile) {
     PsiImportList newList = prepareOptimizeImportsResult((PsiJavaFile) file);
     if (newList != null) {
       final PsiImportList importList = ((PsiJavaFile) file).getImportList();
       if (importList != null) {
         importList.replace(newList);
       }
     }
   }
 }
Ejemplo n.º 10
0
 @Override
 public void deleteChildRange(PsiElement first, PsiElement last)
     throws IncorrectOperationException {
   CheckUtil.checkWritable(this);
   if (first == null) {
     LOG.assertTrue(last == null);
     return;
   }
   ASTNode firstElement = SourceTreeToPsiMap.psiElementToTree(first);
   ASTNode lastElement = SourceTreeToPsiMap.psiElementToTree(last);
   CompositeElement treeElement = calcTreeElement();
   LOG.assertTrue(firstElement.getTreeParent() == treeElement);
   LOG.assertTrue(lastElement.getTreeParent() == treeElement);
   CodeEditUtil.removeChildren(treeElement, firstElement, lastElement);
 }
 @Override
 public PsiElement handleElementRename(final String newElementName)
     throws IncorrectOperationException {
   CheckUtil.checkWritable(this);
   final PsiElement firstChildNode = ObjectUtils.assertNotNull(getFirstChild());
   final PsiElement firstInIdentifier =
       getClass().isInstance(firstChildNode)
           ? ObjectUtils.assertNotNull(firstChildNode.getNextSibling()).getNextSibling()
           : firstChildNode;
   getNode().removeRange(firstInIdentifier.getNode(), null);
   final PsiElement referenceName =
       ObjectUtils.assertNotNull(parseReference(newElementName).getReferenceNameElement());
   getNode().addChild(referenceName.getNode());
   return this;
 }
Ejemplo n.º 12
0
  @Override
  public PsiElement shortenClassReferences(@NotNull PsiElement element, int flags)
      throws IncorrectOperationException {
    CheckUtil.checkWritable(element);
    if (!SourceTreeToPsiMap.hasTreeElement(element)) return element;

    final boolean addImports = (flags & DO_NOT_ADD_IMPORTS) == 0;
    final boolean incompleteCode = (flags & UNCOMPLETE_CODE) != 0;

    final ReferenceAdjuster adjuster =
        ReferenceAdjuster.Extension.getReferenceAdjuster(element.getLanguage());
    if (adjuster != null) {
      final ASTNode reference =
          adjuster.process(element.getNode(), addImports, incompleteCode, myProject);
      return SourceTreeToPsiMap.treeToPsiNotNull(reference);
    } else {
      return element;
    }
  }
Ejemplo n.º 13
0
 @Override
 public final void checkAdd(@NotNull PsiElement element) throws IncorrectOperationException {
   CheckUtil.checkWritable(this);
 }
 @Override
 public void checkDelete() throws IncorrectOperationException {
   CheckUtil.checkWritable(this);
 }