类org.eclipse.jdt.core.dom.StructuralPropertyDescriptor源码实例Demo

下面列出了怎么用org.eclipse.jdt.core.dom.StructuralPropertyDescriptor的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: eclipse-cs   文件: EmptyStatementQuickfix.java
/**
 * {@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;
    }
  };
}
 
源代码2 项目: eclipse-cs   文件: AbstractASTResolution.java
/**
 * 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;
}
 
@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;
        }
    };
}
 
源代码4 项目: vscode-checkstyle   文件: BaseQuickFix.java
/**
 * 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;
}
 
源代码5 项目: SimFix   文件: NodeUtils.java
public static List<ASTNode> getAllSiblingNodes(ASTNode node){
		List<ASTNode> siblings = new ArrayList<>();
		StructuralPropertyDescriptor structuralPropertyDescriptor = node.getLocationInParent();
		if (structuralPropertyDescriptor == null) {
			return siblings;
		} else if(structuralPropertyDescriptor.isChildListProperty()){
			List list = (List) node.getParent().getStructuralProperty(structuralPropertyDescriptor);
			for(Object object : list){
				if(object instanceof ASTNode){
					siblings.add((ASTNode) object);
				}
			}
		} 
//		else if(structuralPropertyDescriptor.isChildProperty()){
//			ASTNode child = (ASTNode) node.getParent().getStructuralProperty(structuralPropertyDescriptor);
//			siblings.add(child);
//		}
		return siblings;
 	}
 
源代码6 项目: eclipse.jdt.ls   文件: SemanticHighlightings.java
@Override
public boolean consumes(SemanticToken token) {

	// 1: match types
	SimpleName name = token.getNode();
	ASTNode node = name.getParent();
	int nodeType = node.getNodeType();
	if (nodeType != ASTNode.SIMPLE_TYPE && nodeType != ASTNode.QUALIFIED_TYPE) {
		return false;
	}

	// 2: match type arguments
	StructuralPropertyDescriptor locationInParent = node.getLocationInParent();
	if (locationInParent == ParameterizedType.TYPE_ARGUMENTS_PROPERTY) {
		return true;
	}

	return false;
}
 
private static ASTNode getInlineableMethodNode(ASTNode node, IJavaElement unit) {
	if (node == null) {
		return null;
	}
	switch (node.getNodeType()) {
		case ASTNode.SIMPLE_NAME:
			StructuralPropertyDescriptor locationInParent = node.getLocationInParent();
			if (locationInParent == MethodDeclaration.NAME_PROPERTY) {
				return node.getParent();
			} else if (locationInParent == MethodInvocation.NAME_PROPERTY || locationInParent == SuperMethodInvocation.NAME_PROPERTY) {
				return unit instanceof ICompilationUnit ? node.getParent() : null; // don't start on invocations in binary
			}
			return null;
		case ASTNode.EXPRESSION_STATEMENT:
			node = ((ExpressionStatement) node).getExpression();
	}
	switch (node.getNodeType()) {
		case ASTNode.METHOD_DECLARATION:
			return node;
		case ASTNode.METHOD_INVOCATION:
		case ASTNode.SUPER_METHOD_INVOCATION:
		case ASTNode.CONSTRUCTOR_INVOCATION:
			return unit instanceof ICompilationUnit ? node : null; // don't start on invocations in binary
	}
	return null;
}
 
源代码8 项目: eclipse.jdt.ls   文件: ExtractTempRefactoring.java
private ASTNode getEnclosingBodyNode() throws JavaModelException {
	ASTNode node = getSelectedExpression().getAssociatedNode();

	// expression must be in a method, lambda or initializer body
	// make sure it is not in method or parameter annotation
	StructuralPropertyDescriptor location = null;
	while (node != null && !(node instanceof BodyDeclaration)) {
		location = node.getLocationInParent();
		node = node.getParent();
		if (node instanceof LambdaExpression) {
			break;
		}
	}
	if (location == MethodDeclaration.BODY_PROPERTY || location == Initializer.BODY_PROPERTY || (location == LambdaExpression.BODY_PROPERTY && ((LambdaExpression) node).resolveMethodBinding() != null)) {
		return (ASTNode) node.getStructuralProperty(location);
	}
	return null;
}
 
源代码9 项目: eclipse.jdt.ls   文件: ExtractFieldRefactoring.java
private ASTNode getEnclosingBodyNode() throws JavaModelException {
	ASTNode node = getSelectedExpression().getAssociatedNode();

	// expression must be in a method, lambda or initializer body.
	// make sure it is not in method or parameter annotation
	StructuralPropertyDescriptor location = null;
	while (node != null && !(node instanceof BodyDeclaration)) {
		location = node.getLocationInParent();
		node = node.getParent();
		if (node instanceof LambdaExpression) {
			break;
		}
	}
	if (location == MethodDeclaration.BODY_PROPERTY || location == Initializer.BODY_PROPERTY || (location == LambdaExpression.BODY_PROPERTY && ((LambdaExpression) node).resolveMethodBinding() != null)) {
		return (ASTNode) node.getStructuralProperty(location);
	}
	return null;
}
 
源代码10 项目: eclipse.jdt.ls   文件: RefactorProcessor.java
private static <T extends ASTNode> T getEnclosingHeader(ASTNode node, Class<T> headerType, StructuralPropertyDescriptor... headerProperties) {
	if (headerType.isInstance(node)) {
		return headerType.cast(node);
	}

	while (node != null) {
		ASTNode parent = node.getParent();
		if (headerType.isInstance(parent)) {
			StructuralPropertyDescriptor locationInParent = node.getLocationInParent();
			for (StructuralPropertyDescriptor property : headerProperties) {
				if (locationInParent == property) {
					return headerType.cast(parent);
				}
			}
			return null;
		}
		node = parent;
	}
	return null;
}
 
private static ASTNode getInlineableMethodNode(ASTNode node, IJavaElement unit) {
	if (node == null)
		return null;
	switch (node.getNodeType()) {
		case ASTNode.SIMPLE_NAME:
			StructuralPropertyDescriptor locationInParent= node.getLocationInParent();
			if (locationInParent == MethodDeclaration.NAME_PROPERTY) {
				return node.getParent();
			} else if (locationInParent == MethodInvocation.NAME_PROPERTY
					|| locationInParent == SuperMethodInvocation.NAME_PROPERTY) {
				return unit instanceof ICompilationUnit ? node.getParent() : null; // don't start on invocations in binary
			}
			return null;
		case ASTNode.EXPRESSION_STATEMENT:
			node= ((ExpressionStatement)node).getExpression();
	}
	switch (node.getNodeType()) {
		case ASTNode.METHOD_DECLARATION:
			return node;
		case ASTNode.METHOD_INVOCATION:
		case ASTNode.SUPER_METHOD_INVOCATION:
		case ASTNode.CONSTRUCTOR_INVOCATION:
			return unit instanceof ICompilationUnit ? node : null; // don't start on invocations in binary
	}
	return null;
}
 
@Override
public boolean visit(Name name) {
	StructuralPropertyDescriptor locationInParent= name.getLocationInParent();
	if (locationInParent == ExpressionMethodReference.NAME_PROPERTY
			|| locationInParent == TypeMethodReference.NAME_PROPERTY
			|| locationInParent == SuperMethodReference.NAME_PROPERTY) {
		return false;
	}

	SimpleName leftmost= getLeftmost(name);

	IBinding leftmostBinding= leftmost.resolveBinding();
	if (leftmostBinding instanceof IVariableBinding || leftmostBinding instanceof IMethodBinding || leftmostBinding instanceof ITypeBinding) {
		if (shouldUnqualify(leftmost))
			unqualifyMemberName(leftmost);
		else
			qualifyUnqualifiedMemberNameIfNecessary(leftmost);
	}

	if (leftmostBinding instanceof ITypeBinding) {
		String addedImport= fNewLocationCuRewrite.getImportRewrite().addImport((ITypeBinding)leftmostBinding, fNewLocationContext);
		fNewLocationCuRewrite.getImportRemover().registerAddedImport(addedImport);
	}

	return false;
}
 
/**
 * Finds and returns the <code>ASTNode</code> for the given source text
 * selection, if it is an entire constructor call or the class name portion
 * of a constructor call or constructor declaration, or null otherwise.
 * @param unit The compilation unit in which the selection was made
 * @param offset The textual offset of the start of the selection
 * @param length The length of the selection in characters
 * @return ClassInstanceCreation or MethodDeclaration
 */
private ASTNode getTargetNode(ICompilationUnit unit, int offset, int length) {
	ASTNode node= ASTNodes.getNormalizedNode(NodeFinder.perform(fCU, offset, length));
	if (node.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION)
		return node;
	if (node.getNodeType() == ASTNode.METHOD_DECLARATION && ((MethodDeclaration)node).isConstructor())
		return node;
	// we have some sub node. Make sure its the right child of the parent
	StructuralPropertyDescriptor location= node.getLocationInParent();
	ASTNode parent= node.getParent();
	if (location == ClassInstanceCreation.TYPE_PROPERTY) {
		return parent;
	} else if (location == MethodDeclaration.NAME_PROPERTY && ((MethodDeclaration)parent).isConstructor()) {
		return parent;
	}
	return null;
}
 
源代码14 项目: Eclipse-Postfix-Code-Completion   文件: Bindings.java
/**
 * Returns the type binding of the node's type context or null if the node is inside
 * an annotation, type parameter, super type declaration, or Javadoc of a top level type.
 * The result of this method is equal to the result of {@link #getBindingOfParentType(ASTNode)} for nodes in the type's body.
 * 
 * @param node an AST node
 * @return the type binding of the node's parent type context, or <code>null</code>
 */
public static ITypeBinding getBindingOfParentTypeContext(ASTNode node) {
	StructuralPropertyDescriptor lastLocation= null;

	while (node != null) {
		if (node instanceof AbstractTypeDeclaration) {
			AbstractTypeDeclaration decl= (AbstractTypeDeclaration) node;
			if (lastLocation == decl.getBodyDeclarationsProperty()
					|| lastLocation == decl.getJavadocProperty()) {
				return decl.resolveBinding();
			} else if (decl instanceof EnumDeclaration && lastLocation == EnumDeclaration.ENUM_CONSTANTS_PROPERTY) {
				return decl.resolveBinding();
			}
		} else if (node instanceof AnonymousClassDeclaration) {
			return ((AnonymousClassDeclaration) node).resolveBinding();
		}
		lastLocation= node.getLocationInParent();
		node= node.getParent();
	}
	return null;
}
 
源代码15 项目: Eclipse-Postfix-Code-Completion   文件: ASTNodes.java
public static ASTNode findParent(ASTNode node, StructuralPropertyDescriptor[][] pathes) {
	for (int p= 0; p < pathes.length; p++) {
		StructuralPropertyDescriptor[] path= pathes[p];
		ASTNode current= node;
		int d= path.length - 1;
		for (; d >= 0 && current != null; d--) {
			StructuralPropertyDescriptor descriptor= path[d];
			if (!descriptor.equals(current.getLocationInParent()))
				break;
			current= current.getParent();
		}
		if (d < 0)
			return current;
	}
	return null;
}
 
private static boolean locationNeedsParentheses(StructuralPropertyDescriptor locationInParent) {
	if (locationInParent instanceof ChildListPropertyDescriptor && locationInParent != InfixExpression.EXTENDED_OPERANDS_PROPERTY) {
		// e.g. argument lists of MethodInvocation, ClassInstanceCreation, dimensions of ArrayCreation ...
		return false;
	}
	if (locationInParent == VariableDeclarationFragment.INITIALIZER_PROPERTY
			|| locationInParent == SingleVariableDeclaration.INITIALIZER_PROPERTY
			|| locationInParent == ReturnStatement.EXPRESSION_PROPERTY
			|| locationInParent == EnhancedForStatement.EXPRESSION_PROPERTY
			|| locationInParent == ForStatement.EXPRESSION_PROPERTY
			|| locationInParent == WhileStatement.EXPRESSION_PROPERTY
			|| locationInParent == DoStatement.EXPRESSION_PROPERTY
			|| locationInParent == AssertStatement.EXPRESSION_PROPERTY
			|| locationInParent == AssertStatement.MESSAGE_PROPERTY
			|| locationInParent == IfStatement.EXPRESSION_PROPERTY
			|| locationInParent == SwitchStatement.EXPRESSION_PROPERTY
			|| locationInParent == SwitchCase.EXPRESSION_PROPERTY
			|| locationInParent == ArrayAccess.INDEX_PROPERTY
			|| locationInParent == ThrowStatement.EXPRESSION_PROPERTY
			|| locationInParent == SynchronizedStatement.EXPRESSION_PROPERTY
			|| locationInParent == ParenthesizedExpression.EXPRESSION_PROPERTY) {
		return false;
	}
	return true;
}
 
public String initialize(CompilationUnit root, ASTNode node) {
	if (!(node instanceof Name))
		return SearchMessages.ImplementOccurrencesFinder_invalidTarget;

	fSelectedNode= ASTNodes.getNormalizedNode(node);
	if (!(fSelectedNode instanceof Type))
		return SearchMessages.ImplementOccurrencesFinder_invalidTarget;

	StructuralPropertyDescriptor location= fSelectedNode.getLocationInParent();
	if (location != TypeDeclaration.SUPERCLASS_TYPE_PROPERTY && location != TypeDeclaration.SUPER_INTERFACE_TYPES_PROPERTY && location != EnumDeclaration.SUPER_INTERFACE_TYPES_PROPERTY)
		return SearchMessages.ImplementOccurrencesFinder_invalidTarget;

	fSelectedType= ((Type)fSelectedNode).resolveBinding();
	if (fSelectedType == null)
		return SearchMessages.ImplementOccurrencesFinder_invalidTarget;

	fStart= fSelectedNode.getParent(); // type declaration
	fASTRoot= root;
	fDescription= Messages.format(SearchMessages.ImplementOccurrencesFinder_occurrence_description, BasicElementLabels.getJavaElementName(fSelectedType.getName()));

	return null;
}
 
public static ITypeBinding guessBindingForTypeReference(ASTNode node) {
  	StructuralPropertyDescriptor locationInParent= node.getLocationInParent();
  	if (locationInParent == QualifiedName.QUALIFIER_PROPERTY) {
  		return null; // can't guess type for X.A
  	}
if (locationInParent == SimpleType.NAME_PROPERTY ||
		locationInParent == NameQualifiedType.NAME_PROPERTY) {
  		node= node.getParent();
  	}
  	ITypeBinding binding= Bindings.normalizeTypeBinding(getPossibleTypeBinding(node));
  	if (binding != null) {
  		if (binding.isWildcardType()) {
  			return normalizeWildcardType(binding, true, node.getAST());
  		}
  	}
  	return binding;
  }
 
public static BodyDeclaration findParentBodyDeclaration(ASTNode node, boolean treatModifiersOutside) {
	StructuralPropertyDescriptor lastLocation= null;

	while (node != null) {
		if (node instanceof BodyDeclaration) {
			BodyDeclaration decl= (BodyDeclaration) node;
			if (!treatModifiersOutside || lastLocation != decl.getModifiersProperty()) {
				return decl;
			}
			treatModifiersOutside= false;
		}
		lastLocation= node.getLocationInParent();
		node= node.getParent();
	}
	return (BodyDeclaration) node;
}
 
/**
 * Finds the ancestor type of <code>node</code> (includes <code>node</code> in the search).
 *
 * @param node the node to start the search from, can be <code>null</code>
 * @param treatModifiersOutside if set, modifiers are not part of their type, but of the type's
 *            parent
 * @return returns the ancestor type of <code>node</code> (AbstractTypeDeclaration or
 *         AnonymousTypeDeclaration) if any (including <code>node</code>), <code>null</code>
 *         otherwise
 */
public static ASTNode findParentType(ASTNode node, boolean treatModifiersOutside) {
	StructuralPropertyDescriptor lastLocation= null;

	while (node != null) {
		if (node instanceof AbstractTypeDeclaration) {
			AbstractTypeDeclaration decl= (AbstractTypeDeclaration) node;
			if (!treatModifiersOutside || lastLocation != decl.getModifiersProperty()) {
				return decl;
			}
		} else if (node instanceof AnonymousClassDeclaration) {
			return node;
		}
		lastLocation= node.getLocationInParent();
		node= node.getParent();
	}
	return null;
}
 
private static <T extends ASTNode> T getEnclosingHeader(ASTNode node, Class<T> headerType, StructuralPropertyDescriptor... headerProperties) {
	if (headerType.isInstance(node))
		return headerType.cast(node);

	while (node != null) {
		ASTNode parent= node.getParent();
		if (headerType.isInstance(parent)) {
			StructuralPropertyDescriptor locationInParent= node.getLocationInParent();
			for (StructuralPropertyDescriptor property : headerProperties) {
				if (locationInParent == property)
					return headerType.cast(parent);
			}
			return null;
		}
		node= parent;
	}
	return null;
}
 
public void addEvent(ASTNode parent, StructuralPropertyDescriptor childProperty, RewriteEvent event) {
	validateHasChildProperty(parent, childProperty);

	if (event.isListRewrite()) {
		validateIsListProperty(childProperty);
	}

	EventHolder holder= new EventHolder(parent, childProperty, event);

	List entriesList = (List) this.eventLookup.get(parent);
	if (entriesList != null) {
		for (int i= 0; i < entriesList.size(); i++) {
			EventHolder curr= (EventHolder) entriesList.get(i);
			if (curr.childProperty == childProperty) {
				entriesList.set(i, holder);
				this.lastEvent= null;
				return;
			}
		}
	} else {
		entriesList= new ArrayList(3);
		this.eventLookup.put(parent, entriesList);
	}
	entriesList.add(holder);
}
 
public RewriteEvent getEvent(ASTNode parent, StructuralPropertyDescriptor property) {
	validateHasChildProperty(parent, property);

	if (this.lastEvent != null && this.lastEvent.parent == parent && this.lastEvent.childProperty == property) {
		return this.lastEvent.event;
	}

	List entriesList = (List) this.eventLookup.get(parent);
	if (entriesList != null) {
		for (int i= 0; i < entriesList.size(); i++) {
			EventHolder holder= (EventHolder) entriesList.get(i);
			if (holder.childProperty == property) {
				this.lastEvent= holder;
				return holder.event;
			}
		}
	}
	return null;
}
 
void postAddChildEvent(ASTNode node, ASTNode child,	StructuralPropertyDescriptor property) {
	if(property.isChildListProperty()) {

		ListRewriteEvent event = getListEvent(node, property);
		List list = (List)node.getStructuralProperty(property);
		int i = list.indexOf(child);
		int s = list.size();
		int index;
		if(i + 1 < s) {
			ASTNode nextNode = (ASTNode)list.get(i + 1);
			index = event.getIndex(nextNode, ListRewriteEvent.NEW);
		} else {
			index = -1;
		}
		event.insert(child, index);
		if(child != null) {
			markAsMoveOrCopyTarget(node, child);
		}
	}
}
 
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);
	}
}
 
源代码26 项目: eclipse.jdt.ls   文件: ExtractMethodRefactoring.java
private boolean matchesLocationInEnclosingBodyDecl(BodyDeclaration originalEnclosingBodyDeclaration, BodyDeclaration duplicateEnclosingBodyDeclaration, VariableDeclaration originalReturnNode, VariableDeclaration duplicateReturnNode) {
	boolean matches = true;
	ASTNode original = originalReturnNode;
	ASTNode dupliacte = duplicateReturnNode;

	// walk up the parent chains to check if the location of the return nodes in their respective parent chains is same
	do {
		ASTNode originalParent = original.getParent();
		ASTNode duplicateParent = dupliacte.getParent();
		StructuralPropertyDescriptor originalLoc = original.getLocationInParent();
		StructuralPropertyDescriptor duplicateLoc = dupliacte.getLocationInParent();

		if (originalParent != null && duplicateParent != null && originalLoc.getNodeClass().equals(duplicateLoc.getNodeClass()) && originalLoc.getId().equals(duplicateLoc.getId())) {
			if (originalLoc.isChildListProperty() && duplicateLoc.isChildListProperty()) {
				int indexOfOriginal = ((List<?>) originalParent.getStructuralProperty(originalLoc)).indexOf(original);
				int indexOfDuplicate = ((List<?>) duplicateParent.getStructuralProperty(duplicateLoc)).indexOf(dupliacte);
				if (indexOfOriginal != indexOfDuplicate) {
					matches = false;
					break;
				}
			}
		} else {
			matches = false;
			break;
		}

		original = originalParent;
		dupliacte = duplicateParent;

		if ((originalEnclosingBodyDeclaration.equals(original) && !duplicateEnclosingBodyDeclaration.equals(dupliacte)) || (!originalEnclosingBodyDeclaration.equals(original) && duplicateEnclosingBodyDeclaration.equals(dupliacte))) {
			matches = false;
			break;
		}
	} while (!originalEnclosingBodyDeclaration.equals(original) && !duplicateEnclosingBodyDeclaration.equals(dupliacte));

	return matches;
}
 
源代码27 项目: eclipse.jdt.ls   文件: InvertBooleanUtility.java
private static Expression getBooleanExpression(ASTNode node) {
	if (!(node instanceof Expression)) {
		return null;
	}

	// check if the node is a location where it can be negated
	StructuralPropertyDescriptor locationInParent = node.getLocationInParent();
	if (locationInParent == QualifiedName.NAME_PROPERTY) {
		node = node.getParent();
		locationInParent = node.getLocationInParent();
	}
	while (locationInParent == ParenthesizedExpression.EXPRESSION_PROPERTY) {
		node = node.getParent();
		locationInParent = node.getLocationInParent();
	}
	Expression expression = (Expression) node;
	if (!isBoolean(expression)) {
		return null;
	}
	if (expression.getParent() instanceof InfixExpression) {
		return expression;
	}
	if (locationInParent == Assignment.RIGHT_HAND_SIDE_PROPERTY || locationInParent == IfStatement.EXPRESSION_PROPERTY || locationInParent == WhileStatement.EXPRESSION_PROPERTY || locationInParent == DoStatement.EXPRESSION_PROPERTY
			|| locationInParent == ReturnStatement.EXPRESSION_PROPERTY || locationInParent == ForStatement.EXPRESSION_PROPERTY || locationInParent == AssertStatement.EXPRESSION_PROPERTY
			|| locationInParent == MethodInvocation.ARGUMENTS_PROPERTY || locationInParent == ConstructorInvocation.ARGUMENTS_PROPERTY || locationInParent == SuperMethodInvocation.ARGUMENTS_PROPERTY
			|| locationInParent == EnumConstantDeclaration.ARGUMENTS_PROPERTY || locationInParent == SuperConstructorInvocation.ARGUMENTS_PROPERTY || locationInParent == ClassInstanceCreation.ARGUMENTS_PROPERTY
			|| locationInParent == ConditionalExpression.EXPRESSION_PROPERTY || locationInParent == PrefixExpression.OPERAND_PROPERTY) {
		return expression;
	}
	return null;
}
 
public static void getMissingEnumConstantCaseProposals(IInvocationContext context, IProblemLocationCore problem, Collection<ChangeCorrectionProposal> proposals) {
	for (ChangeCorrectionProposal proposal : proposals) {
		if (CorrectionMessages.LocalCorrectionsSubProcessor_add_missing_cases_description.equals(proposal.getName())) {
			return;
		}
	}

	ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
	if (selectedNode instanceof Expression) {
		StructuralPropertyDescriptor locationInParent = selectedNode.getLocationInParent();
		ASTNode parent = selectedNode.getParent();
		ITypeBinding binding;
		List<Statement> statements;

		if (locationInParent == SwitchStatement.EXPRESSION_PROPERTY) {
			SwitchStatement statement = (SwitchStatement) parent;
			binding = statement.getExpression().resolveTypeBinding();
			statements = statement.statements();
		} else if (locationInParent == SwitchExpression.EXPRESSION_PROPERTY) {
			SwitchExpression switchExpression = (SwitchExpression) parent;
			binding = switchExpression.getExpression().resolveTypeBinding();
			statements = switchExpression.statements();
		} else {
			return;
		}

		if (binding == null || !binding.isEnum()) {
			return;
		}

		ArrayList<String> missingEnumCases = new ArrayList<>();
		boolean hasDefault = evaluateMissingSwitchCases(binding, statements, missingEnumCases);
		if (missingEnumCases.size() == 0 && hasDefault) {
			return;
		}

		createMissingCaseProposals(context, parent, missingEnumCases, proposals);
	}
}
 
private ChildListPropertyDescriptor getProperty() {
	List<StructuralPropertyDescriptor> list= fCallerNode.structuralPropertiesForType();
	for (int i= 0; i < list.size(); i++) {
		StructuralPropertyDescriptor curr= list.get(i);
		if (curr.isChildListProperty() && "arguments".equals(curr.getId())) { //$NON-NLS-1$
			return (ChildListPropertyDescriptor) curr;
		}
	}
	return null;

}
 
源代码30 项目: gwt-eclipse-plugin   文件: EquivalentNodeFinder.java
@SuppressWarnings("unchecked")
private int getIndex(ASTNode node) {
  StructuralPropertyDescriptor locationInParent = node.getLocationInParent();
  if (locationInParent != null && locationInParent.isChildListProperty()) {
    List<ASTNode> parentsChildren =
        (List<ASTNode>) node.getParent().getStructuralProperty(
        locationInParent);
    if (parentsChildren != null) {
      return parentsChildren.indexOf(node);
    }
  }

  // The node is not contained within a list-based property on the parent
  return NOT_FROM_LIST;
}
 
 类所在包
 同包方法