コード例 #1
0
  public List<BashPsiElement> parameters() {
    // return Collections.emptyList();
    PsiElement cmd = commandElement();
    if (cmd == null) {
      return Collections.emptyList();
    }

    List<BashPsiElement> result = Lists.newLinkedList();

    PsiElement nextSibling = cmd.getNextSibling();
    while (nextSibling != null) {
      if (nextSibling instanceof BashPsiElement) {
        result.add((BashPsiElement) nextSibling);
      }
      nextSibling = nextSibling.getNextSibling();
    }

    return result;
  }
コード例 #2
0
  public XmlAttribute setAttribute(String qname, String value) throws IncorrectOperationException {
    final XmlAttribute attribute = getAttribute(qname);

    if (attribute != null) {
      if (value == null) {
        deleteChildInternal(attribute.getNode());
        return null;
      }
      attribute.setValue(value);
      return attribute;
    } else if (value == null) {
      return null;
    } else {
      PsiElement xmlAttribute =
          add(XmlElementFactory.getInstance(getProject()).createXmlAttribute(qname, value));
      while (!(xmlAttribute instanceof XmlAttribute)) xmlAttribute = xmlAttribute.getNextSibling();
      return (XmlAttribute) xmlAttribute;
    }
  }
コード例 #3
0
  private static boolean shouldSkipLine(final PsiFile file, Document doc, int line) {
    final int start = doc.getLineStartOffset(line);
    final int end = doc.getLineEndOffset(line);
    final int _start = CharArrayUtil.shiftForward(doc.getCharsSequence(), start, " \n\t");
    if (_start >= end) {
      return true;
    }

    TextRange alreadyChecked = null;
    for (PsiElement elem = file.findElementAt(_start);
        elem != null
            && elem.getTextOffset() <= end
            && (alreadyChecked == null || !alreadyChecked.contains(elem.getTextRange()));
        elem = elem.getNextSibling()) {
      for (PsiElement _elem = elem; _elem.getTextOffset() >= _start; _elem = _elem.getParent()) {
        alreadyChecked = _elem.getTextRange();

        if (_elem instanceof PsiDeclarationStatement) {
          final PsiElement[] declared = ((PsiDeclarationStatement) _elem).getDeclaredElements();
          for (PsiElement declaredElement : declared) {
            if (declaredElement instanceof PsiVariable) {
              return false;
            }
          }
        }

        if (_elem instanceof PsiJavaCodeReferenceElement) {
          final PsiElement resolved = ((PsiJavaCodeReferenceElement) _elem).resolve();
          if (resolved instanceof PsiVariable) {
            return false;
          }
        }
      }
    }
    return true;
  }