org.eclipse.jdt.core.dom.ChildPropertyDescriptor Java Examples

The following examples show how to use org.eclipse.jdt.core.dom.ChildPropertyDescriptor. 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 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 #2
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 #3
Source File: ControlStatementsFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void handle(Statement body, ChildPropertyDescriptor bodyProperty) {
	if ((body.getFlags() & ASTNode.RECOVERED) != 0)
		return;
	Statement parent= (Statement)body.getParent();
	if ((parent.getFlags() & ASTNode.RECOVERED) != 0)
		return;

	if (fRemoveUnnecessaryBlocksOnlyWhenReturnOrThrow) {
		if (!(body instanceof Block)) {
			if (body.getNodeType() != ASTNode.IF_STATEMENT && body.getNodeType() != ASTNode.RETURN_STATEMENT && body.getNodeType() != ASTNode.THROW_STATEMENT) {
				fResult.add(new AddBlockOperation(bodyProperty, body, parent));
			}
		} else {
			if (RemoveBlockOperation.satisfiesCleanUpPrecondition(parent, bodyProperty, true)) {
				fResult.add(new RemoveBlockOperation(parent, bodyProperty));
			}
		}
	} else if (fFindControlStatementsWithoutBlock) {
		if (!(body instanceof Block)) {
			fResult.add(new AddBlockOperation(bodyProperty, body, parent));
		}
	} else if (fRemoveUnnecessaryBlocks) {
		if (RemoveBlockOperation.satisfiesCleanUpPrecondition(parent, bodyProperty, false)) {
			fResult.add(new RemoveBlockOperation(parent, bodyProperty));
		}
	}
}
 
Example #4
Source File: ASTFlattenerUtils.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public ASTNode genericChildProperty(final ASTNode node, final String propertyName) {
  final Function1<ChildPropertyDescriptor, Boolean> _function = (ChildPropertyDescriptor it) -> {
    String _id = it.getId();
    return Boolean.valueOf(Objects.equal(propertyName, _id));
  };
  final ChildPropertyDescriptor property = IterableExtensions.<ChildPropertyDescriptor>head(IterableExtensions.<ChildPropertyDescriptor>filter(Iterables.<ChildPropertyDescriptor>filter(node.structuralPropertiesForType(), ChildPropertyDescriptor.class), _function));
  if ((property != null)) {
    Object _structuralProperty = node.getStructuralProperty(property);
    return ((ASTNode) _structuralProperty);
  }
  return null;
}
 
Example #5
Source File: SourceProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public boolean isDangligIf() {
	List<Statement> statements= fDeclaration.getBody().statements();
	if (statements.size() != 1)
		return false;

	ASTNode p= statements.get(0);

	while (true) {
		if (p instanceof IfStatement) {
			return ((IfStatement) p).getElseStatement() == null;
		} else {

			ChildPropertyDescriptor childD;
			if (p instanceof WhileStatement) {
				childD= WhileStatement.BODY_PROPERTY;
			} else if (p instanceof ForStatement) {
				childD= ForStatement.BODY_PROPERTY;
			} else if (p instanceof EnhancedForStatement) {
				childD= EnhancedForStatement.BODY_PROPERTY;
			} else if (p instanceof DoStatement) {
				childD= DoStatement.BODY_PROPERTY;
			} else if (p instanceof LabeledStatement) {
				childD= LabeledStatement.BODY_PROPERTY;
			} else {
				return false;
			}
			Statement body= (Statement) p.getStructuralProperty(childD);
			if (body instanceof Block) {
				return false;
			} else {
				p= body;
			}
		}
	}
}
 
Example #6
Source File: ControlStatementsFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private static boolean satisfiesPrecondition(Statement controlStatement, ChildPropertyDescriptor childDescriptor, boolean onlyReturnAndThrows, boolean cleanUpCheck) {
	Object child= controlStatement.getStructuralProperty(childDescriptor);

	if (!(child instanceof Block))
		return false;

	Block block= (Block)child;
	List<Statement> list= block.statements();
	if (list.size() != 1)
		return false;

	ASTNode singleStatement= list.get(0);

	if (onlyReturnAndThrows)
		if (!(singleStatement instanceof ReturnStatement) && !(singleStatement instanceof ThrowStatement))
			return false;

	if (controlStatement instanceof IfStatement) {
		// if (true) {
		//  while (true)
		// 	 if (false)
		//    ;
		// } else
		//   ;

		if (((IfStatement)controlStatement).getThenStatement() != child)
			return true;//can always remove blocks in else part

		IfStatement ifStatement= (IfStatement)controlStatement;
		if (ifStatement.getElseStatement() == null)
			return true;//can always remove if no else part

		return !hasUnblockedIf((Statement)singleStatement, onlyReturnAndThrows, cleanUpCheck);
	} else {
		//if (true)
		// while (true) {
		//  if (false)
		//   ;
		// }
		//else
		// ;
		if (!hasUnblockedIf((Statement)singleStatement, onlyReturnAndThrows, cleanUpCheck))
			return true;

		ASTNode currentChild= controlStatement;
		ASTNode parent= currentChild.getParent();
		while (true) {
			Statement body= null;
			if (parent instanceof IfStatement) {
				body= ((IfStatement)parent).getThenStatement();
				if (body == currentChild && ((IfStatement)parent).getElseStatement() != null)//->currentChild is an unblocked then part
					return false;
			} else if (parent instanceof WhileStatement) {
				body= ((WhileStatement)parent).getBody();
			} else if (parent instanceof DoStatement) {
				body= ((DoStatement)parent).getBody();
			} else if (parent instanceof ForStatement) {
				body= ((ForStatement)parent).getBody();
			} else if (parent instanceof EnhancedForStatement) {
				body= ((EnhancedForStatement)parent).getBody();
			} else {
				return true;
			}
			if (body != currentChild)//->parents child is a block
				return true;

			currentChild= parent;
			parent= currentChild.getParent();
		}
	}
}
 
Example #7
Source File: ControlStatementsFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public static boolean satisfiesQuickAssistPrecondition(Statement controlStatement, ChildPropertyDescriptor childDescriptor) {
	return satisfiesPrecondition(controlStatement, childDescriptor, false, false);
}
 
Example #8
Source File: ControlStatementsFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public static boolean satisfiesCleanUpPrecondition(Statement controlStatement, ChildPropertyDescriptor childDescriptor, boolean onlyReturnAndThrows) {
	return satisfiesPrecondition(controlStatement, childDescriptor, onlyReturnAndThrows, true);
}
 
Example #9
Source File: ControlStatementsFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public RemoveBlockOperation(Statement controlStatement, ChildPropertyDescriptor child) {
	fStatement= controlStatement;
	fChild= child;
}
 
Example #10
Source File: ControlStatementsFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public AddBlockOperation(ChildPropertyDescriptor bodyProperty, Statement body, Statement controlStatement) {
	fBodyProperty= bodyProperty;
	fBody= body;
	fControlStatement= controlStatement;
}
 
Example #11
Source File: DelegateFieldCreator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected ChildPropertyDescriptor getBodyProperty() {
	return VariableDeclarationFragment.INITIALIZER_PROPERTY;
}
 
Example #12
Source File: DelegateFieldCreator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected ChildPropertyDescriptor getJavaDocProperty() {
	return FieldDeclaration.JAVADOC_PROPERTY;
}
 
Example #13
Source File: DelegateMethodCreator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected ChildPropertyDescriptor getBodyProperty() {
	return MethodDeclaration.BODY_PROPERTY;
}
 
Example #14
Source File: DelegateMethodCreator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected ChildPropertyDescriptor getJavaDocProperty() {
	return MethodDeclaration.JAVADOC_PROPERTY;
}
 
Example #15
Source File: DelegateFieldCreator.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected ChildPropertyDescriptor getBodyProperty() {
	return VariableDeclarationFragment.INITIALIZER_PROPERTY;
}
 
Example #16
Source File: DelegateFieldCreator.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected ChildPropertyDescriptor getJavaDocProperty() {
	return FieldDeclaration.JAVADOC_PROPERTY;
}
 
Example #17
Source File: DelegateMethodCreator.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected ChildPropertyDescriptor getBodyProperty() {
	return MethodDeclaration.BODY_PROPERTY;
}
 
Example #18
Source File: DelegateMethodCreator.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected ChildPropertyDescriptor getJavaDocProperty() {
	return MethodDeclaration.JAVADOC_PROPERTY;
}
 
Example #19
Source File: DelegateCreator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Returns the body property descriptor. The body of the delegate will be
 * added using this descriptor.
 *
 * @return property descriptor
 */
protected abstract ChildPropertyDescriptor getBodyProperty();
 
Example #20
Source File: DelegateCreator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Returns the javadoc property descriptor. The javadoc will be added using
 * this descriptor.
 *
 * @return property descriptor
 */
protected abstract ChildPropertyDescriptor getJavaDocProperty();
 
Example #21
Source File: DelegateCreator.java    From eclipse.jdt.ls with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Returns the body property descriptor. The body of the delegate will be
 * added using this descriptor.
 *
 * @return property descriptor
 */
protected abstract ChildPropertyDescriptor getBodyProperty();
 
Example #22
Source File: DelegateCreator.java    From eclipse.jdt.ls with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Returns the javadoc property descriptor. The javadoc will be added using
 * this descriptor.
 *
 * @return property descriptor
 */
protected abstract ChildPropertyDescriptor getJavaDocProperty();