List of usage examples for org.eclipse.jdt.core.dom ASTNode getNodeType
public final int getNodeType()
From source file:JavaCompleter.java
License:Apache License
public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); Scanner s = null;/* www .ja va 2 s. c om*/ for (String filename = in.readLine(); filename != null; filename = in.readLine()) { s = new Scanner(new File(filename)); s.useDelimiter("\\Z"); ASTParser parser = ASTParser.newParser(AST.JLS4); parser.setSource(s.next().toCharArray()); parser.setKind(ASTParser.K_COMPILATION_UNIT); ASTNode file = parser.createAST(null); ASTNode range = NodeFinder.perform(file, 200, 201); System.out.println(range.getNodeType()); } }
From source file:br.ufal.cideei.util.MethodDeclarationSootMethodBridge.java
License:Open Source License
/** * Gets the parent method./* ww w.java 2 s . c om*/ * * @param node * the node * @return the parent method */ public static MethodDeclaration getParentMethod(ASTNode node) { if (node == null) { return null; } else { if (node.getNodeType() == ASTNode.METHOD_DECLARATION) { return (MethodDeclaration) node; } else { return getParentMethod(node.getParent()); } } }
From source file:ca.ecliptical.pde.internal.ds.AnnotationProcessor.java
License:Open Source License
private boolean isNestedPublicStatic(TypeDeclaration type) { if (Modifier.isStatic(type.getModifiers())) { ASTNode parent = type.getParent(); if (parent != null && parent.getNodeType() == ASTNode.TYPE_DECLARATION) { TypeDeclaration parentType = (TypeDeclaration) parent; if (Modifier.isPublic(parentType.getModifiers())) return parentType.isPackageMemberTypeDeclaration() || isNestedPublicStatic(parentType); }//from w w w . j a va2s . c o m } return false; }
From source file:ca.mcgill.cs.swevo.jayfx.ASTCrawler.java
License:Open Source License
@SuppressWarnings({ "unchecked", "unused" }) // private static List<AdviceElement> getApplicableAdvice(final IJavaElement // je) {// ww w . j a v a 2 s . c o m // final List<AdviceElement> advisedBy = new ArrayList<AdviceElement>(); // final List<AdviceElement> direct = AJModel.getInstance() // .getRelatedElements(AJRelationshipManager.ADVISED_BY, je); // if (direct != null) // advisedBy.addAll(direct); // // // check for advised code elements // final List extras = AJModel.getInstance().getExtraChildren(je); // if (extras != null) // for (final Iterator iter = extras.iterator(); iter.hasNext();) { // final IJavaElement element = (IJavaElement) iter.next(); // final List<AdviceElement> indirect = AJModel.getInstance() // .getRelatedElements(AJRelationshipManager.ADVISED_BY, // element); // if (indirect != null) // advisedBy.addAll(indirect); // } // return advisedBy; // } private static Assignment getAssignment(final ASTNode node) { if (node == null) return null; if (node.getNodeType() == ASTNode.ASSIGNMENT) return (Assignment) node; else return ASTCrawler.getAssignment(node.getParent()); }
From source file:ca.mcgill.cs.swevo.jayfx.ASTCrawler.java
License:Open Source License
@Override public boolean visit(final MarkerAnnotation node) { final ITypeBinding binding = node.resolveTypeBinding(); if (ASTCrawler.checkForNull(binding)) return false; final IElement annoteElem = ASTCrawler.convertBinding(binding); this.aDB.addElement(annoteElem, binding.getModifiers()); final ASTNode annotatedNode = node.getParent(); switch (annotatedNode.getNodeType()) { case ASTNode.METHOD_DECLARATION: { final MethodDeclaration annotatedMethod = (MethodDeclaration) annotatedNode; final IMethodBinding mBinding = annotatedMethod.resolveBinding(); return this.addAnnotationRelation(annoteElem, mBinding); }// w w w.ja v a 2s . co m case ASTNode.ANNOTATION_TYPE_DECLARATION: { final AnnotationTypeDeclaration annotatedAnnotation = (AnnotationTypeDeclaration) annotatedNode; final ITypeBinding tBinding = annotatedAnnotation.resolveBinding(); return this.addAnnotationRelation(annoteElem, tBinding); } case ASTNode.VARIABLE_DECLARATION_STATEMENT: { return processVariableDeclarationStatement(annoteElem, (VariableDeclarationStatement) annotatedNode); } case ASTNode.VARIABLE_DECLARATION_FRAGMENT: { return processVariableDeclarationFragment(annoteElem, (VariableDeclarationFragment) annotatedNode); } case ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION: { AnnotationTypeMemberDeclaration atmd = (AnnotationTypeMemberDeclaration) annotatedNode; IMethodBinding methodBinding = atmd.resolveBinding(); return this.addAnnotationRelation(annoteElem, methodBinding); } case ASTNode.PACKAGE_DECLARATION: { final PackageDeclaration packDecl = (PackageDeclaration) annotatedNode; final IPackageBinding pBinding = packDecl.resolveBinding(); return this.addAnnotationRelation(annoteElem, pBinding); } case ASTNode.SINGLE_VARIABLE_DECLARATION: { final SingleVariableDeclaration svd = (SingleVariableDeclaration) annotatedNode; final IVariableBinding vBinding = svd.resolveBinding(); return this.addAnnotationRelation(annoteElem, vBinding); } case ASTNode.TYPE_DECLARATION: { final TypeDeclaration tDecl = (TypeDeclaration) annotatedNode; final ITypeBinding tBinding = tDecl.resolveBinding(); return this.addAnnotationRelation(annoteElem, tBinding); } case ASTNode.ENUM_DECLARATION: { final EnumDeclaration eDecl = (EnumDeclaration) annotatedNode; final ITypeBinding tBinding = eDecl.resolveBinding(); return this.addAnnotationRelation(annoteElem, tBinding); } case ASTNode.FIELD_DECLARATION: { final FieldDeclaration fieldDecl = (FieldDeclaration) annotatedNode; for (final Object obj : fieldDecl.fragments()) { final VariableDeclarationFragment vdf = (VariableDeclarationFragment) obj; final IVariableBinding vBinding = vdf.resolveBinding(); return this.addAnnotationRelation(annoteElem, vBinding); } } default: { throw new IllegalStateException("Illegal annotated node type: " + annotatedNode); } } }
From source file:ca.mcgill.cs.swevo.jayfx.ASTCrawler.java
License:Open Source License
@Override public boolean visit(final NormalAnnotation node) { final ITypeBinding binding = node.resolveTypeBinding(); if (ASTCrawler.checkForNull(binding)) return false; final IElement annoteElem = ASTCrawler.convertBinding(binding); this.aDB.addElement(annoteElem, binding.getModifiers()); final ASTNode annotatedNode = node.getParent(); switch (annotatedNode.getNodeType()) { case ASTNode.METHOD_DECLARATION: { final MethodDeclaration annotatedMethod = (MethodDeclaration) annotatedNode; final IMethodBinding mBinding = annotatedMethod.resolveBinding(); return this.addAnnotationRelation(annoteElem, mBinding); }//from ww w .j ava2s . com case ASTNode.ANNOTATION_TYPE_DECLARATION: { final AnnotationTypeDeclaration annotatedAnnotation = (AnnotationTypeDeclaration) annotatedNode; final ITypeBinding tBinding = annotatedAnnotation.resolveBinding(); return this.addAnnotationRelation(annoteElem, tBinding); } case ASTNode.VARIABLE_DECLARATION_STATEMENT: { return processVariableDeclarationStatement(annoteElem, (VariableDeclarationStatement) annotatedNode); } case ASTNode.VARIABLE_DECLARATION_FRAGMENT: { return processVariableDeclarationFragment(annoteElem, (VariableDeclarationFragment) annotatedNode); } case ASTNode.PACKAGE_DECLARATION: { final PackageDeclaration packDecl = (PackageDeclaration) annotatedNode; final IPackageBinding pBinding = packDecl.resolveBinding(); return this.addAnnotationRelation(annoteElem, pBinding); } case ASTNode.SINGLE_VARIABLE_DECLARATION: { final SingleVariableDeclaration svd = (SingleVariableDeclaration) annotatedNode; final IVariableBinding vBinding = svd.resolveBinding(); return this.addAnnotationRelation(annoteElem, vBinding); } case ASTNode.TYPE_DECLARATION: { final TypeDeclaration tDecl = (TypeDeclaration) annotatedNode; final ITypeBinding tBinding = tDecl.resolveBinding(); return this.addAnnotationRelation(annoteElem, tBinding); } case ASTNode.ENUM_DECLARATION: { final EnumDeclaration eDecl = (EnumDeclaration) annotatedNode; final ITypeBinding tBinding = eDecl.resolveBinding(); return this.addAnnotationRelation(annoteElem, tBinding); } case ASTNode.FIELD_DECLARATION: { final FieldDeclaration fieldDecl = (FieldDeclaration) annotatedNode; for (final Object obj : fieldDecl.fragments()) { final VariableDeclarationFragment vdf = (VariableDeclarationFragment) obj; final IVariableBinding vBinding = vdf.resolveBinding(); return this.addAnnotationRelation(annoteElem, vBinding); } } default: { throw new IllegalStateException("Illegal annotated node type: " + annotatedNode); } } }
From source file:ca.mcgill.cs.swevo.jayfx.ASTCrawler.java
License:Open Source License
@Override public boolean visit(final SingleMemberAnnotation node) { final ITypeBinding binding = node.resolveTypeBinding(); if (ASTCrawler.checkForNull(binding)) return false; final IElement annoteElem = ASTCrawler.convertBinding(binding); this.aDB.addElement(annoteElem, binding.getModifiers()); final ASTNode annotatedNode = node.getParent(); switch (annotatedNode.getNodeType()) { case ASTNode.METHOD_DECLARATION: { final MethodDeclaration annotatedMethod = (MethodDeclaration) annotatedNode; final IMethodBinding mBinding = annotatedMethod.resolveBinding(); return this.addAnnotationRelation(annoteElem, mBinding); }/*from ww w.ja v a 2 s.co m*/ case ASTNode.ANNOTATION_TYPE_DECLARATION: { final AnnotationTypeDeclaration annotatedAnnotation = (AnnotationTypeDeclaration) annotatedNode; final ITypeBinding tBinding = annotatedAnnotation.resolveBinding(); return this.addAnnotationRelation(annoteElem, tBinding); } case ASTNode.VARIABLE_DECLARATION_STATEMENT: { VariableDeclarationStatement vds = (VariableDeclarationStatement) annotatedNode; return processVariableDeclarationStatement(annoteElem, vds); } case ASTNode.VARIABLE_DECLARATION_FRAGMENT: { return processVariableDeclarationFragment(annoteElem, (VariableDeclarationFragment) annotatedNode); } case ASTNode.PACKAGE_DECLARATION: { final PackageDeclaration packDecl = (PackageDeclaration) annotatedNode; final IPackageBinding pBinding = packDecl.resolveBinding(); return this.addAnnotationRelation(annoteElem, pBinding); } case ASTNode.SINGLE_VARIABLE_DECLARATION: { final SingleVariableDeclaration svd = (SingleVariableDeclaration) annotatedNode; final IVariableBinding vBinding = svd.resolveBinding(); return this.addAnnotationRelation(annoteElem, vBinding); } case ASTNode.TYPE_DECLARATION: { final TypeDeclaration tDecl = (TypeDeclaration) annotatedNode; final ITypeBinding tBinding = tDecl.resolveBinding(); return this.addAnnotationRelation(annoteElem, tBinding); } case ASTNode.ENUM_DECLARATION: { final EnumDeclaration eDecl = (EnumDeclaration) annotatedNode; final ITypeBinding tBinding = eDecl.resolveBinding(); return this.addAnnotationRelation(annoteElem, tBinding); } case ASTNode.FIELD_DECLARATION: { final FieldDeclaration fieldDecl = (FieldDeclaration) annotatedNode; for (final Object obj : fieldDecl.fragments()) { final VariableDeclarationFragment vdf = (VariableDeclarationFragment) obj; final IVariableBinding vBinding = vdf.resolveBinding(); return this.addAnnotationRelation(annoteElem, vBinding); } } default: { throw new IllegalStateException("Illegal annotated node type: " + annotatedNode); } } }
From source file:ca.mcgill.cs.swevo.ppa.PPAASTUtil.java
License:Open Source License
public static ASTNode getSpecificParentType(ASTNode node, int type) { ASTNode specificParent = null;/*from ww w .jav a2 s.c o m*/ if (node != null) { if (node.getNodeType() == type) { specificParent = node; } else { specificParent = getSpecificParentType(node.getParent(), type); } } return specificParent; }
From source file:ca.mcgill.cs.swevo.ppa.PPAIndexer.java
License:Open Source License
public int getNodeType(ASTNode node) { int type = node.getNodeType(); if (type == ASTNode.SIMPLE_NAME) { SimpleName sName = (SimpleName) node; IBinding binding = sName.resolveBinding(); if (binding != null) { if (binding instanceof IVariableBinding) { IVariableBinding varBinding = (IVariableBinding) binding; if (varBinding.isField()) { type = FIELD_TYPE;/* www. ja v a2 s.co m*/ } else { type = LOCAL_TYPE; } } else if (binding instanceof IMethodBinding) { type = METHOD_TYPE; } else if (binding instanceof ITypeBinding) { type = TYPE_TYPE; } } } return type; }
From source file:ca.uvic.chisel.diver.sequencediagrams.sc.java.editors.JavaMessageGrouper.java
License:Open Source License
public IMessageGrouping[] calculateGroups2(UMLSequenceViewer viewer, Object activationElement, Object[] children) {/* w ww. j a v a2s . c o m*/ HashMap<ASTNode, MappedMessageGrouping> groups = new HashMap<ASTNode, MappedMessageGrouping>(); if (!(activationElement instanceof IAdaptable)) { return new IMessageGrouping[0]; } ASTNode activationNode = (ASTNode) ((IAdaptable) activationElement).getAdapter(ASTNode.class); if (!(activationNode instanceof MethodDeclaration)) { return new IMessageGrouping[0]; } for (int i = 0; i < children.length; i++) { if (children[i] instanceof IAdaptable) { ASTNode messageNode = (ASTNode) ((IAdaptable) children[i]).getAdapter(ASTNode.class); if (messageNode != null) { ASTNode currentParent = messageNode.getParent(); while (currentParent != null && currentParent != activationNode) { ASTNode block = null; String text = null; Color c = null; Color bc = null; String expressionString = ""; switch (currentParent.getNodeType()) { case ASTNode.IF_STATEMENT: block = checkIfSide((IfStatement) currentParent, messageNode); if (block != null && block == ((IfStatement) currentParent).getElseStatement()) { text = "else"; } else if (block == ((IfStatement) currentParent).getThenStatement()) { text = "if (" + ((IfStatement) currentParent).getExpression().toString() + ")"; } c = ISketchColorConstants.CONDITION_FG; bc = ISketchColorConstants.CONDITION_FG; break; case ASTNode.WHILE_STATEMENT: if (((WhileStatement) currentParent).getExpression() != null) { expressionString = ((WhileStatement) currentParent).getExpression().toString(); } text = "while (" + expressionString + ")"; block = currentParent; c = ISketchColorConstants.LOOP_FG; bc = ISketchColorConstants.LOOP_BG; break; case ASTNode.FOR_STATEMENT: if (((ForStatement) currentParent).getExpression() != null) { expressionString = ((ForStatement) currentParent).getExpression().toString(); } else { expressionString = ";;"; } text = "for (" + expressionString + ")"; block = currentParent; c = ISketchColorConstants.LOOP_FG; bc = ISketchColorConstants.LOOP_BG; break; case ASTNode.TRY_STATEMENT: text = "try"; block = currentParent; c = ISketchColorConstants.ERROR_FG; bc = ISketchColorConstants.ERROR_BG; break; case ASTNode.CATCH_CLAUSE: text = "catch (" + ((CatchClause) currentParent).getException().toString() + ")"; block = currentParent; c = ISketchColorConstants.ERROR_FG; bc = ISketchColorConstants.ERROR_BG; break; case ASTNode.DO_STATEMENT: text = "do while (" + ((DoStatement) currentParent).getExpression().toString() + ")"; block = currentParent; c = ISketchColorConstants.LOOP_FG; bc = ISketchColorConstants.LOOP_BG; break; } if (text != null) { MappedMessageGrouping grouping = groups.get(block); if (grouping == null) { grouping = new MappedMessageGrouping(activationElement, i, 1, text, block); grouping.setBackground(bc); grouping.setForeground(c); groups.put(block, grouping); } else { int length = (i - grouping.getOffset()) + 1; grouping.setLength(length); } } currentParent = currentParent.getParent(); } } } } ArrayList<MappedMessageGrouping> groupList = new ArrayList<MappedMessageGrouping>(groups.values()); Collections.sort(groupList, new Comparator<MappedMessageGrouping>() { public int compare(MappedMessageGrouping o1, MappedMessageGrouping o2) { ASTNode n1 = (ASTNode) o1.getKey(); ASTNode n2 = (ASTNode) o2.getKey(); int diff = n1.getStartPosition() - n2.getStartPosition(); if (diff == 0) { diff = (n1.getStartPosition() + n1.getLength()) - (n2.getStartPosition() + n2.getLength()); } return diff; } }); return groupList.toArray(new IMessageGrouping[groupList.size()]); }