本文整理匯總了Java中org.eclipse.jdt.core.dom.ASTNode.getNodeType方法的典型用法代碼示例。如果您正苦於以下問題:Java ASTNode.getNodeType方法的具體用法?Java ASTNode.getNodeType怎麽用?Java ASTNode.getNodeType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jdt.core.dom.ASTNode
的用法示例。
在下文中一共展示了ASTNode.getNodeType方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: isLiteralNodeSelected
import org.eclipse.jdt.core.dom.ASTNode; //導入方法依賴的package包/類
public boolean isLiteralNodeSelected() {
ASTNode[] nodes = getSelectedNodes();
if (nodes.length != 1) {
return false;
}
ASTNode node = nodes[0];
switch (node.getNodeType()) {
case ASTNode.BOOLEAN_LITERAL:
case ASTNode.CHARACTER_LITERAL:
case ASTNode.NULL_LITERAL:
case ASTNode.NUMBER_LITERAL:
return true;
default:
return false;
}
}
示例2: getMethodDeclaration
import org.eclipse.jdt.core.dom.ASTNode; //導入方法依賴的package包/類
public static MethodDeclaration getMethodDeclaration(String methodName) {
IJavaElement javaElem = EditorUtility.getActiveEditorJavaInput();
if (javaElem.getElementType() == IJavaElement.COMPILATION_UNIT) {
ICompilationUnit iCompUnit = (ICompilationUnit) javaElem;
ASTNode astNode = Crystal.getInstance()
.getASTNodeFromCompilationUnit(iCompUnit);
if (astNode != null
&& astNode.getNodeType() == ASTNode.COMPILATION_UNIT) {
CompilationUnit compUnit = (CompilationUnit) astNode;
for (Object declaration : compUnit.types()) {
if (declaration instanceof TypeDeclaration) {
for (MethodDeclaration method : ((TypeDeclaration) declaration)
.getMethods()) {
if (methodName.contentEquals(method.getName()
.getFullyQualifiedName())) {
return method;
}
}
}
}
}
}
return null;
}
示例3: isNotInBlock
import org.eclipse.jdt.core.dom.ASTNode; //導入方法依賴的package包/類
private static boolean isNotInBlock(ASTNode parent) {
ASTNode statement = parent.getParent();
boolean isStatement = statement.getNodeType() != ASTNode.EXPRESSION_STATEMENT;
ASTNode block = statement.getParent();
boolean isBlock = block.getNodeType() == ASTNode.BLOCK || block.getNodeType() == ASTNode.SWITCH_STATEMENT;
boolean isControlStatemenBody = ASTNodes.isControlStatementBody(statement.getLocationInParent());
return isStatement || !(isBlock || isControlStatemenBody);
}
示例4: getSelectedTypeNode
import org.eclipse.jdt.core.dom.ASTNode; //導入方法依賴的package包/類
public static ASTNode getSelectedTypeNode(CompilationUnit root, IProblemLocation problem) {
ASTNode selectedNode= problem.getCoveringNode(root);
if (selectedNode == null) {
return null;
}
if (selectedNode.getNodeType() == ASTNode.ANONYMOUS_CLASS_DECLARATION) { // bug 200016
selectedNode= selectedNode.getParent();
}
if (selectedNode.getLocationInParent() == EnumConstantDeclaration.NAME_PROPERTY) {
selectedNode= selectedNode.getParent();
}
if (selectedNode.getNodeType() == ASTNode.SIMPLE_NAME && selectedNode.getParent() instanceof AbstractTypeDeclaration) {
return selectedNode.getParent();
} else if (selectedNode.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION) {
return ((ClassInstanceCreation) selectedNode).getAnonymousClassDeclaration();
} else if (selectedNode.getNodeType() == ASTNode.ENUM_CONSTANT_DECLARATION) {
EnumConstantDeclaration enumConst= (EnumConstantDeclaration) selectedNode;
if (enumConst.getAnonymousClassDeclaration() != null) {
return enumConst.getAnonymousClassDeclaration();
}
return enumConst;
} else {
return null;
}
}
示例5: hasSideEffect
import org.eclipse.jdt.core.dom.ASTNode; //導入方法依賴的package包/類
private static boolean hasSideEffect(SimpleName reference) {
ASTNode parent= reference.getParent();
while (parent instanceof QualifiedName) {
parent= parent.getParent();
}
if (parent instanceof FieldAccess) {
parent= parent.getParent();
}
ASTNode node= null;
int nameParentType= parent.getNodeType();
if (nameParentType == ASTNode.ASSIGNMENT) {
Assignment assignment= (Assignment) parent;
node= assignment.getRightHandSide();
} else if (nameParentType == ASTNode.SINGLE_VARIABLE_DECLARATION) {
SingleVariableDeclaration decl= (SingleVariableDeclaration)parent;
node= decl.getInitializer();
if (node == null) {
return false;
}
} else if (nameParentType == ASTNode.VARIABLE_DECLARATION_FRAGMENT) {
node= parent;
} else {
return false;
}
ArrayList<Expression> sideEffects= new ArrayList<>();
node.accept(new SideEffectFinder(sideEffects));
return sideEffects.size() > 0;
}
示例6: hasCorrectNesting
import org.eclipse.jdt.core.dom.ASTNode; //導入方法依賴的package包/類
public boolean hasCorrectNesting(ASTNode node) {
if (fNodes.size() == 0) {
return true;
}
ASTNode parent = node.getParent();
if (fNodes.get(0).getParent() != parent) {
return false;
}
// Here we know that we have two elements. In this case the
// parent must be a block or a switch statement. Otherwise a
// snippet like "if (true) foo(); else foo();" would match
// the pattern "foo(); foo();"
int nodeType = parent.getNodeType();
return nodeType == ASTNode.BLOCK || nodeType == ASTNode.SWITCH_STATEMENT;
}
示例7: isInvalidNode
import org.eclipse.jdt.core.dom.ASTNode; //導入方法依賴的package包/類
/**
* Tests whether the node to be replaced is invalid.
*
* @return true if the node is invalid, false otherwise
*
*/
public boolean isInvalidNode() {
ASTNode first = fNodes.get(0);
ASTNode candidate = first.getParent();
if (candidate == null) {
return false;
}
// return invalid if the opening and closing parenthesis of the method signature is part of the node to be replaced
if (candidate.getNodeType() == ASTNode.METHOD_DECLARATION) {
return true;
}
return false;
}
示例8: needsInnerParantheses
import org.eclipse.jdt.core.dom.ASTNode; //導入方法依賴的package包/類
private static boolean needsInnerParantheses(ASTNode nodeToCast) {
int nodeType= nodeToCast.getNodeType();
// nodes have weaker precedence than cast
return nodeType == ASTNode.INFIX_EXPRESSION || nodeType == ASTNode.CONDITIONAL_EXPRESSION
|| nodeType == ASTNode.ASSIGNMENT || nodeType == ASTNode.INSTANCEOF_EXPRESSION;
}
示例9: serializeAll
import org.eclipse.jdt.core.dom.ASTNode; //導入方法依賴的package包/類
private void serializeAll(CompilationUnit cu, ASTNode node, JsonGenerator jG, SerializerProvider provider) throws IOException {
List<StructuralPropertyDescriptor> descriptorList = node.structuralPropertiesForType();
jG.writeStartObject();
final int Ntype = node.getNodeType();
String ClassName = node.nodeClassForType(Ntype).getName().substring(25);
jG.writeFieldName("internalClass");
jG.writeString(ClassName);
for (StructuralPropertyDescriptor descriptor : descriptorList) {
Object child = node.getStructuralProperty(descriptor);
if (child instanceof List) {
serializeChildList(cu, (List<ASTNode>) child, jG, descriptor, provider);
} else if (child instanceof ASTNode) {
serializeChild(cu, (ASTNode) child, jG, descriptor, provider);
} else if (child != null) {
jG.writeFieldName(descriptor.getId());
jG.writeString(child.toString());
serializePosition(cu, node, jG);
}
}
if (node == cu) {
List<Comment> cl = cu.getCommentList();
if (!cl.isEmpty()) {
jG.writeFieldName("comments");
jG.writeStartArray();
for (Comment c: (List<Comment>) cu.getCommentList()) {
if (c.getParent() != null) continue;
jG.writeStartObject();
final int type = c.getNodeType();
String name = c.nodeClassForType(type).getName().substring(25);
jG.writeFieldName("internalClass");
jG.writeString(name);
serializePosition(cu, (ASTNode)c, jG);
jG.writeEndObject();
}
jG.writeEndArray();
}
}
jG.writeEndObject();
}
示例10: getAssignedValue
import org.eclipse.jdt.core.dom.ASTNode; //導入方法依賴的package包/類
/**
* Converts an assignment, postfix expression or prefix expression into an
* assignable equivalent expression using the getter.
*
* @param node
* the assignment/prefix/postfix node
* @param astRewrite
* the astRewrite to use
* @param getterExpression
* the expression to insert for read accesses or
* <code>null</code> if such an expression does not exist
* @param variableType
* the type of the variable that the result will be assigned to
* @param is50OrHigher
* <code>true</code> if a 5.0 or higher environment can be used
* @return an expression that can be assigned to the type variableType with
* node being replaced by a equivalent expression using the getter
*/
public static Expression getAssignedValue(ASTNode node, ASTRewrite astRewrite, Expression getterExpression, ITypeBinding variableType, boolean is50OrHigher) {
InfixExpression.Operator op = null;
AST ast = astRewrite.getAST();
if (isNotInBlock(node)) {
return null;
}
if (node.getNodeType() == ASTNode.ASSIGNMENT) {
Assignment assignment = ((Assignment) node);
Expression rightHandSide = assignment.getRightHandSide();
Expression copiedRightOp = (Expression) astRewrite.createCopyTarget(rightHandSide);
if (assignment.getOperator() == Operator.ASSIGN) {
ITypeBinding rightHandSideType = rightHandSide.resolveTypeBinding();
copiedRightOp = createNarrowCastIfNessecary(copiedRightOp, rightHandSideType, ast, variableType, is50OrHigher);
return copiedRightOp;
}
if (getterExpression != null) {
InfixExpression infix = ast.newInfixExpression();
infix.setLeftOperand(getterExpression);
infix.setOperator(ASTNodes.convertToInfixOperator(assignment.getOperator()));
ITypeBinding infixType = infix.resolveTypeBinding();
if (NecessaryParenthesesChecker.needsParenthesesForRightOperand(rightHandSide, infix, variableType)) {
ParenthesizedExpression p = ast.newParenthesizedExpression();
p.setExpression(copiedRightOp);
copiedRightOp = p;
}
infix.setRightOperand(copiedRightOp);
return createNarrowCastIfNessecary(infix, infixType, ast, variableType, is50OrHigher);
}
} else if (node.getNodeType() == ASTNode.POSTFIX_EXPRESSION) {
PostfixExpression po = (PostfixExpression) node;
if (po.getOperator() == PostfixExpression.Operator.INCREMENT) {
op = InfixExpression.Operator.PLUS;
}
if (po.getOperator() == PostfixExpression.Operator.DECREMENT) {
op = InfixExpression.Operator.MINUS;
}
} else if (node.getNodeType() == ASTNode.PREFIX_EXPRESSION) {
PrefixExpression pe = (PrefixExpression) node;
if (pe.getOperator() == PrefixExpression.Operator.INCREMENT) {
op = InfixExpression.Operator.PLUS;
}
if (pe.getOperator() == PrefixExpression.Operator.DECREMENT) {
op= InfixExpression.Operator.MINUS;
}
}
if (op != null && getterExpression != null) {
return createInfixInvocationFromPostPrefixExpression(op, getterExpression, ast, variableType, is50OrHigher);
}
return null;
}
示例11: guessTypeForReference
import org.eclipse.jdt.core.dom.ASTNode; //導入方法依賴的package包/類
public static Type guessTypeForReference(AST ast, ASTNode node) {
ASTNode parent= node.getParent();
while (parent != null) {
switch (parent.getNodeType()) {
case ASTNode.VARIABLE_DECLARATION_FRAGMENT:
if (((VariableDeclarationFragment) parent).getInitializer() == node) {
return ASTNodeFactory.newType(ast, (VariableDeclaration) parent);
}
return null;
case ASTNode.SINGLE_VARIABLE_DECLARATION:
if (((VariableDeclarationFragment) parent).getInitializer() == node) {
return ASTNodeFactory.newType(ast, (VariableDeclaration) parent);
}
return null;
case ASTNode.ARRAY_ACCESS:
if (!((ArrayAccess) parent).getIndex().equals(node)) {
Type type= guessTypeForReference(ast, parent);
if (type != null) {
return ASTNodeFactory.newArrayType(type);
}
}
return null;
case ASTNode.FIELD_ACCESS:
if (node.equals(((FieldAccess) parent).getName())) {
node= parent;
parent= parent.getParent();
} else {
return null;
}
break;
case ASTNode.SUPER_FIELD_ACCESS:
case ASTNode.PARENTHESIZED_EXPRESSION:
node= parent;
parent= parent.getParent();
break;
case ASTNode.QUALIFIED_NAME:
if (node.equals(((QualifiedName) parent).getName())) {
node= parent;
parent= parent.getParent();
} else {
return null;
}
break;
default:
return null;
}
}
return null;
}
示例12: isConstructor
import org.eclipse.jdt.core.dom.ASTNode; //導入方法依賴的package包/類
@Override
protected boolean isConstructor() {
ASTNode node= getInvocationNode();
return node.getNodeType() != ASTNode.METHOD_INVOCATION && node.getNodeType() != ASTNode.SUPER_METHOD_INVOCATION;
}
示例13: getHoverInfo
import org.eclipse.jdt.core.dom.ASTNode; //導入方法依賴的package包/類
@Override
// XXX. Refactor logic to avoid code duplication with SummaryView
// XXX. This is triggering way too early, before the UI is ready!
public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
RuntimeModel instance = RuntimeModel.getInstance();
if(instance != null ) {
summary = instance.getSummaryInfo();
}
if(summary!=null){
ASTNode node = ASTUtils.getASTNode(hoverRegion.getOffset(),
hoverRegion.getLength(), this.editor);
if (node != null) {
if (node.getNodeType() == ASTNode.SIMPLE_NAME) {
SimpleName simpleName = (SimpleName) node;
ITypeBinding typeBinding = simpleName.resolveTypeBinding();
if(typeBinding != null)
if (typeBinding.isInterface() || Modifier.isAbstract(typeBinding.getModifiers())) {
String fieldType = typeBinding.getQualifiedName();
// XXX. Fill in the rest of the arguments
Set<Info<IElement>> classesBehindInterface = summary.getClassesBehindInterface("", fieldType, "");
StringBuffer buffer = new StringBuffer();
if (classesBehindInterface != null) {
HTMLPrinter.addSmallHeader(buffer, fieldType);
HTMLPrinter.startBulletList(buffer);
for (Info i : classesBehindInterface) {
HTMLPrinter.addBullet(buffer, i.getKey());
}
HTMLPrinter.endBulletList(buffer);
}else{
return null;
}
return buffer.toString();
}
}
}
}
return null;
}
示例14: getParent
import org.eclipse.jdt.core.dom.ASTNode; //導入方法依賴的package包/類
/**
* Returns the closest ancestor of <code>node</code> whose type is <code>nodeType</code>, or <code>null</code> if none.
* <p>
* <b>Warning:</b> This method does not stop at any boundaries like parentheses, statements, body declarations, etc.
* The resulting node may be in a totally different scope than the given node.
* Consider using one of the {@link ASTResolving}<code>.find(..)</code> methods instead.
* </p>
* @param node the node
* @param nodeType the node type constant from {@link ASTNode}
* @return the closest ancestor of <code>node</code> whose type is <code>nodeType</code>, or <code>null</code> if none
*/
public static ASTNode getParent(ASTNode node, int nodeType) {
do {
node= node.getParent();
} while (node != null && node.getNodeType() != nodeType);
return node;
}