Java Code Examples for org.eclipse.jdt.core.dom.StructuralPropertyDescriptor#isChildProperty()

The following examples show how to use org.eclipse.jdt.core.dom.StructuralPropertyDescriptor#isChildProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EmptyStatementQuickfix.java    From eclipse-cs with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected ASTVisitor handleGetCorrectingASTVisitor(final IRegion lineInfo,
        final int markerStartPosition) {

  return new ASTVisitor() {
    @Override
    public boolean visit(EmptyStatement node) {
      if (containsPosition(lineInfo, node.getStartPosition())) {

        // early exit if the statement is mandatory, e.g. only
        // statement in a for-statement without block
        StructuralPropertyDescriptor p = node.getLocationInParent();
        if (p.isChildProperty() && ((ChildPropertyDescriptor) p).isMandatory()) {
          return false;
        }

        node.delete();
      }
      return false;
    }
  };
}
 
Example 2
Source File: AbstractASTResolution.java    From eclipse-cs with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Replaces a node in an AST with another node. If the replacement is successful the original node
 * is deleted.
 *
 * @param node
 *          The node to replace.
 * @param replacement
 *          The replacement node.
 * @return <code>true</code> if the node was successfully replaced.
 */
protected boolean replace(final ASTNode node, final ASTNode replacement) {
  final ASTNode parent = node.getParent();
  final StructuralPropertyDescriptor descriptor = node.getLocationInParent();
  if (descriptor != null) {
    if (descriptor.isChildProperty()) {
      parent.setStructuralProperty(descriptor, replacement);
      node.delete();
      return true;
    } else if (descriptor.isChildListProperty()) {
      @SuppressWarnings("unchecked")
      final List<ASTNode> children = (List<ASTNode>) parent.getStructuralProperty(descriptor);
      children.set(children.indexOf(node), replacement);
      node.delete();
      return true;
    }
  }
  return false;
}
 
Example 3
Source File: EmptyStatementQuickFix.java    From vscode-checkstyle with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public ASTVisitor getCorrectingASTVisitor(IRegion lineInfo, int markerStartOffset) {
    return new ASTVisitor() {
        @Override
        public boolean visit(EmptyStatement node) {
            if (containsPosition(lineInfo, node.getStartPosition())) {

                // early exit if the statement is mandatory, e.g. only
                // statement in a for-statement without block
                final StructuralPropertyDescriptor p = node.getLocationInParent();
                if (p.isChildProperty() && ((ChildPropertyDescriptor) p).isMandatory()) {
                    return false;
                }

                node.delete();
            }
            return false;
        }
    };
}
 
Example 4
Source File: BaseQuickFix.java    From vscode-checkstyle with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Replaces a node in an AST with another node. If the replacement is successful
 * the original node is deleted.
 *
 * @param node        The node to replace.
 * @param replacement The replacement node.
 * @return <code>true</code> if the node was successfully replaced.
 */
protected boolean replace(final ASTNode node, final ASTNode replacement) {
    final ASTNode parent = node.getParent();
    final StructuralPropertyDescriptor descriptor = node.getLocationInParent();
    if (descriptor != null) {
        if (descriptor.isChildProperty()) {
            parent.setStructuralProperty(descriptor, replacement);
            node.delete();
            return true;
        } else if (descriptor.isChildListProperty()) {
            @SuppressWarnings("unchecked")
            final List<ASTNode> children = (List<ASTNode>) parent.getStructuralProperty(descriptor);
            children.set(children.indexOf(node), replacement);
            node.delete();
            return true;
        }
    }
    return false;
}
 
Example 5
Source File: InternalASTRewrite.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
void preAddChildEvent(ASTNode node, ASTNode child,	StructuralPropertyDescriptor property) {
	if(property.isChildProperty()) {
		NodeRewriteEvent event = getNodeEvent(node, property);
		event.setNewValue(child);
		if(child != null) {
			markAsMoveOrCopyTarget(node, child);
		}
	} else if(property.isChildListProperty()) {
		// force event creation
		getListEvent(node, property);
	}
}