List of usage examples for org.eclipse.jdt.core.dom TypeDeclaration isLocalTypeDeclaration
public boolean isLocalTypeDeclaration()
From source file:de.jevopi.j2og.simpleParser.Visitor.java
License:Open Source License
/** * {@inheritDoc}//from w ww . j a v a 2 s. co m * * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.TypeDeclaration) * @since Aug 18, 2011 */ @Override public boolean visit(TypeDeclaration i_node) { if (i_node.isLocalTypeDeclaration()) return false; return startType(i_node); }
From source file:de.jevopi.j2og.simpleParser.Visitor.java
License:Open Source License
/** * {@inheritDoc}//from ww w. j av a2 s. c om * * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(org.eclipse.jdt.core.dom.TypeDeclaration) * @since Aug 18, 2011 */ @Override public void endVisit(TypeDeclaration i_node) { super.endVisit(i_node); if (i_node.isLocalTypeDeclaration()) return; endType(i_node); }
From source file:edu.uci.ics.sourcerer.extractor.ast.ReferenceExtractorVisitor.java
License:Open Source License
/** * This method writes:/* ww w . ja va 2 s.co m*/ * <ul> * <li>Non-anonymous class or interface entity to <code>IEntityWriter</code>. * <ul> * <li>Inside relation to <code>IRelationWriter</code>.</li> * <li>Extends relation to <code>IRelationWriter</code>.</li> * <li>Implements relation to <code>IRelationWriter</code>.</li> * <li>Synthesized constructors to <code>IEntityWriter</code>. * <ul> * <li>Inside relation to <code>IRelationWriter</code>.</li> * <li>Implicit superconstructor calls to <code>IRelationWriter</code>.</li> * </ul></li> * </ul></li> * </ul> * * Class/interface fully qualified names (FQNs) adhere to the following format: * <ul> * <li>Top-level: package fqn + . + simple name</li> * <li>Member: parent fqn + $ + simple name</li> * <li>Local: parent fqn + $local- + incrementing counter + - + simple name</li> * </ul> */ @SuppressWarnings("unchecked") @Override public boolean visit(TypeDeclaration node) { // Get the fqn String fqn = null; Entity type = null; ITypeBinding binding = node.resolveBinding(); if (binding == null && !bindingFree) { throw new IllegalStateException("Binding resolution appears to have failed!"); } if (node.isPackageMemberTypeDeclaration()) { fqn = fqnStack.getTypeFqn(node.getName().getIdentifier()); } else if (node.isMemberTypeDeclaration()) { if (node.getName().getIdentifier().length() > 0) { fqn = fqnStack.getMemberFqn(node.getName().getIdentifier()); } else { logger.severe("A type declaration should not declare an annonymous type!"); fqn = fqnStack.getAnonymousClassFqn(); } } else if (node.isLocalTypeDeclaration()) { if (binding == null) { fqn = getUnknownFqn(node.getName().getIdentifier()); } else { fqn = fqnStack.getLocalFqn(node.getName().getIdentifier(), binding); } } else { logger.severe("Unsure what type the declaration is!"); fqn = "(ERROR)" + node.getName().getIdentifier(); } // Write the entity Metrics metrics = MetricsCalculator.computeLinesOfCode(getSource(node)); if (node.isInterface()) { entityWriter.writeInterface(fqn, node.getModifiers(), metrics, getLocation(node)); type = Entity.INTERFACE; } else { entityWriter.writeClass(fqn, node.getModifiers(), metrics, getLocation(node)); type = Entity.CLASS; } // Write the inside relation relationWriter.writeInside(fqn, fqnStack.getFqn(), getUnknownLocation()); // Write the extends relation Type superType = node.getSuperclassType(); String superFqn = null; if (superType != null) { superFqn = getTypeFqn(superType); relationWriter.writeExtends(fqn, superFqn, getLocation(superType)); } // Write the implements relation List<Type> superInterfaceTypes = node.superInterfaceTypes(); for (Type superInterfaceType : superInterfaceTypes) { String superInterfaceFqn = getTypeFqn(superInterfaceType); relationWriter.writeImplements(fqn, superInterfaceFqn, getLocation(superInterfaceType)); } fqnStack.push(fqn, type); if (binding != null) { if (binding.isAnonymous()) { logger.log(Level.SEVERE, "A type declaration should not declare an annonymous type!"); } else { // Verify the fqn // String fqn2 = getTypeFqn(binding); // if (!fqn.equals(fqn2)) { // logger.log(Level.SEVERE, "Mismatch between " + fqn + " and " + fqn2); // } // Write out the synthesized constructors for (IMethodBinding method : binding.getDeclaredMethods()) { if (method.isDefaultConstructor()) { // Write the entity String constructorFqn = getMethodFqn(method, true); entityWriter.writeConstructor(constructorFqn, method.getModifiers(), MetricsCalculator.computeLinesOfCode(null), getUnknownLocation()); // Write the inside relation relationWriter.writeInside(constructorFqn, fqn, getUnknownLocation()); // Write the calls relation (implicit superconstructor call) if (superFqn == null) { relationWriter.writeCalls(constructorFqn, "java.lang.Object.<init>()", getUnknownLocation()); } else { relationWriter.writeCalls(constructorFqn, superFqn + ".<init>()", getUnknownLocation()); } } } } } accept(node.getJavadoc()); accept(node.typeParameters()); accept(node.getSuperclassType()); accept(node.superInterfaceTypes()); accept(node.bodyDeclarations()); return false; }
From source file:edu.uci.ics.sourcerer.tools.java.extractor.eclipse.ReferenceExtractorVisitor.java
License:Open Source License
/** * This method writes://from w w w .j a v a 2 s .c o m * <ul> * <li>Non-anonymous class or interface entity to <code>IEntityWriter</code>. * <ul> * <li>Inside relation to <code>IRelationWriter</code>.</li> * <li>Extends relation to <code>IRelationWriter</code>.</li> * <li>Implements relation to <code>IRelationWriter</code>.</li> * <li>Synthesized constructors to <code>IEntityWriter</code>. * <ul> * <li>Inside relation to <code>IRelationWriter</code>.</li> * <li>Implicit superconstructor calls to <code>IRelationWriter</code>.</li> * </ul></li> * </ul></li> * </ul> * * Class/interface fully qualified names (FQNs) adhere to the following format: * <ul> * <li>Top-level: package fqn + . + simple name</li> * <li>Member: parent fqn + $ + simple name</li> * <li>Local: parent fqn + $ + incrementing counter + simple name</li> * </ul> */ @SuppressWarnings("unchecked") @Override public boolean visit(TypeDeclaration node) { // Get the fqn String parentFqn = null; String fqn = null; Entity type = null; ITypeBinding binding = node.resolveBinding(); if (binding == null && !bindingFree) { throw new IllegalStateException("Binding resolution appears to have failed!"); } if (node.isPackageMemberTypeDeclaration()) { EnclosingPackage enc = fqnStack.peek(EnclosingPackage.class); fqn = enc.getTypeFqn(node.getName().getIdentifier()); parentFqn = enc.getFqn(); } else if (node.isMemberTypeDeclaration()) { if (node.getName().getIdentifier().length() > 0) { EnclosingDeclaredType enc = fqnStack.peek(EnclosingDeclaredType.class); fqn = enc.getMemberFqn(node.getName().getIdentifier()); parentFqn = enc.getFqn(); } else { throw new IllegalStateException("A type declaration should not declare an annonymous type!"); } } else if (node.isLocalTypeDeclaration()) { EnclosingBlock enc = fqnStack.peek(EnclosingBlock.class); if (binding == null) { fqn = createUnknownFqn(node.getName().getIdentifier()); } else { fqn = enc.getLocalFqn(node.getName().getIdentifier(), binding); } parentFqn = enc.getFqn(); } else { throw new IllegalStateException("Unknown declaration: " + node); } if (node.isInterface()) { type = Entity.INTERFACE; } else { type = Entity.CLASS; } // Push the stack fqnStack.push(fqn, type); // Visit the children accept(node.getJavadoc()); accept(node.modifiers()); accept(node.typeParameters()); accept(node.getSuperclassType()); accept(node.superInterfaceTypes()); accept(node.bodyDeclarations()); // Write the contains relation relationWriter.writeRelation(Relation.CONTAINS, parentFqn, fqn, createUnknownLocation()); // Write the entity entityWriter.writeEntity(type, fqn, node.getModifiers(), createMetrics(node), createLocation(node)); // Write the extends relation Type superType = node.getSuperclassType(); String superFqn = null; if (superType == null) { if (!fqn.equals("java.lang.Object")) { superFqn = "java.lang.Object"; relationWriter.writeRelation(Relation.EXTENDS, fqn, superFqn, createUnknownLocation()); } } else { superFqn = getTypeFqn(superType); relationWriter.writeRelation(Relation.EXTENDS, fqn, superFqn, createLocation(superType)); } // Write the implements relation List<Type> superInterfaceTypes = node.superInterfaceTypes(); for (Type superInterfaceType : superInterfaceTypes) { String superInterfaceFqn = getTypeFqn(superInterfaceType); relationWriter.writeRelation(Relation.IMPLEMENTS, fqn, superInterfaceFqn, createLocation(superInterfaceType)); } if (binding != null) { if (binding.isAnonymous()) { logger.log(Level.SEVERE, "A type declaration should not declare an annonymous type!"); } else { // Write out the synthesized constructors for (IMethodBinding method : binding.getDeclaredMethods()) { if (method.isDefaultConstructor()) { // Write the entity String constructorFqn = getMethodName(method, true); entityWriter.writeEntity(Entity.CONSTRUCTOR, constructorFqn, "()", null, method.getModifiers(), null, createUnknownLocation()); constructorFqn += "()"; // Write the contains relation relationWriter.writeRelation(Relation.CONTAINS, fqn, constructorFqn, createUnknownLocation()); // Write the calls relation (implicit superconstructor call) if (superFqn == null) { relationWriter.writeRelation(Relation.CALLS, constructorFqn, "java.lang.Object.<init>()", createUnknownLocation()); } else { if (superType == null) { relationWriter.writeRelation(Relation.CALLS, constructorFqn, superFqn + ".<init>()", createUnknownLocation()); } else { relationWriter.writeRelation(Relation.CALLS, constructorFqn, getErasedTypeFqn(superType) + ".<init>()", createUnknownLocation()); } } } } } } fqnStack.pop(); return false; }
From source file:org.eclipse.virgo.ide.bundlor.jdt.core.ArtifactAnalyserTypeVisitor.java
License:Open Source License
/** * {@inheritDoc}// w ww . j a va 2 s.c o m */ @Override public boolean visit(TypeDeclaration node) { ITypeBinding binding = node.resolveBinding(); if (binding == null) { return false; } String name = binding.getBinaryName(); this.typePackage = getPackageBinding(binding).getName(); if (!node.isLocalTypeDeclaration()) { this.partialManifest.recordType(name); } for (String referencedType : this.referencedTypes) { recordFullyQualifiedName(referencedType); } if (node.getSuperclassType() != null) { ITypeBinding superClassBinding = node.getSuperclassType().resolveBinding(); recordTypeBinding(superClassBinding); this.partialManifest.recordUsesPackage(this.typePackage, getPackageBinding(superClassBinding).getName()); } for (int i = 0; i < node.superInterfaceTypes().size(); i++) { org.eclipse.jdt.core.dom.Type interfaceType = (org.eclipse.jdt.core.dom.Type) node.superInterfaceTypes() .get(i); ITypeBinding interfaceBinding = interfaceType.resolveBinding(); recordTypeBinding(interfaceBinding); this.partialManifest.recordUsesPackage(this.typePackage, getPackageBinding(interfaceBinding).getName()); } return true; }