List of usage examples for org.eclipse.jdt.core.dom EnumDeclaration isLocalTypeDeclaration
public boolean isLocalTypeDeclaration()
From source file:edu.uci.ics.sourcerer.extractor.ast.ReferenceExtractorVisitor.java
License:Open Source License
/** * This method writes://from w w w. ja v a 2 s .co m * <ul> * <li>Enum entity to <code>IEntityWriter</code>. * <ul> * <li>Inside relation to <code>IRelationWriter</code>.</li> * <li>Implements relation to <code>IRelationWriter</code>.</li> * <li>Parametrized by relation to <code>IRelationWriter</code>.</li> * <li>Synthesized constructors to <code>IEntityWriter</code>. * <ul> * <li>Inside relation to <code>IRelationWriter</code>.</li> * </ul></li> * </ul></li> * </ul> * * Enum qualified names (FQNs) adhere to the following format: * <ul> * <li>Top-level: package fqn + . + simple name</li> * <li>Member: parent fqn + $ + simple name</li> * </ul> */ @SuppressWarnings("unchecked") @Override public boolean visit(EnumDeclaration node) { // Get the fqn String fqn = null; if (node.isPackageMemberTypeDeclaration()) { fqn = fqnStack.getTypeFqn(node.getName().getIdentifier()); } else if (node.isMemberTypeDeclaration()) { fqn = fqnStack.getFqn() + "$" + node.getName().getIdentifier(); } else if (node.isLocalTypeDeclaration()) { logger.log(Level.WARNING, "Can't have local enums! eclipse error"); fqnStack.push(null, null); return false; } else { logger.log(Level.SEVERE, "Unsure what type the declaration is!"); fqn = "(ERROR)"; } // Write the entity entityWriter.writeEnum(fqn, node.getModifiers(), MetricsCalculator.computeLinesOfCode(getSource(node)), getLocation(node)); // Write the inside relation relationWriter.writeInside(fqn, fqnStack.getFqn(), getUnknownLocation()); // Write the implements relation for (Type superInterfaceType : (List<Type>) node.superInterfaceTypes()) { relationWriter.writeImplements(fqn, getTypeFqn(superInterfaceType), getLocation(superInterfaceType)); } ITypeBinding binding = node.resolveBinding(); if (binding != null) { // 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(getSource(node)), getUnknownLocation()); // Write the inside relation relationWriter.writeInside(constructorFqn, fqn, getUnknownLocation()); } } } fqnStack.push(fqn, Entity.ENUM); accept(node.getJavadoc()); accept(node.enumConstants()); 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 ava2 s .c om * <ul> * <li>Enum entity to <code>IEntityWriter</code>. * <ul> * <li>Inside relation to <code>IRelationWriter</code>.</li> * <li>Implements relation to <code>IRelationWriter</code>.</li> * <li>Parametrized by relation to <code>IRelationWriter</code>.</li> * <li>Synthesized constructors to <code>IEntityWriter</code>. * <ul> * <li>Inside relation to <code>IRelationWriter</code>.</li> * </ul></li> * </ul></li> * </ul> * * Enum qualified names (FQNs) adhere to the following format: * <ul> * <li>Top-level: package fqn + . + simple name</li> * <li>Member: parent fqn + $ + simple name</li> * </ul> */ @SuppressWarnings("unchecked") @Override public boolean visit(EnumDeclaration node) { // Get the fqn String fqn = null; if (node.isPackageMemberTypeDeclaration()) { fqn = fqnStack.peek(EnclosingPackage.class).getTypeFqn(node.getName().getIdentifier()); } else if (node.isMemberTypeDeclaration()) { fqn = fqnStack.peek(EnclosingDeclaredType.class).getMemberFqn(node.getName().getIdentifier()); } else if (node.isLocalTypeDeclaration()) { throw new IllegalStateException("Can't have local enums!"); } else { logger.log(Level.SEVERE, "Unsure what type the declaration is!"); fqn = "(ERROR)"; } String parentFqn = fqnStack.getFqn(); fqnStack.push(fqn, Entity.ENUM); // Visit the children accept(node.getJavadoc()); accept(node.enumConstants()); accept(node.bodyDeclarations()); Location unknown = createUnknownLocation(); // Write the entity entityWriter.writeEntity(Entity.ENUM, fqn, node.getModifiers(), createMetrics(node), createLocation(node)); // Write the contains relation relationWriter.writeRelation(Relation.CONTAINS, parentFqn, fqn, unknown); // Write the implements relation for (Type superInterfaceType : (List<Type>) node.superInterfaceTypes()) { relationWriter.writeRelation(Relation.IMPLEMENTS, fqn, getTypeFqn(superInterfaceType), createLocation(superInterfaceType)); } // Write the extends relation relationWriter.writeRelation(Relation.EXTENDS, fqn, "java.lang.Enum<" + fqn + ">", unknown); ITypeBinding binding = node.resolveBinding(); if (binding != null) { // 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(), createMetrics(node), unknown); constructorFqn += "()"; // Write the contains relation relationWriter.writeRelation(Relation.CONTAINS, fqn, constructorFqn, unknown); // Write the calls relation relationWriter.writeRelation(Relation.CALLS, constructorFqn, "java.lang.Enum.<init>(java.lang.String,int)", unknown); } } } // Write the values method { String methodFqn = fqn + ".values"; entityWriter.writeEntity(Entity.METHOD, methodFqn, "()", null, 9, null, unknown); methodFqn += "()"; relationWriter.writeRelation(Relation.CONTAINS, fqn, methodFqn, unknown); relationWriter.writeRelation(Relation.RETURNS, methodFqn, fqn + "[]", unknown); } // Write the valueOf method { String methodFqn = fqn + ".valueOf"; entityWriter.writeEntity(Entity.METHOD, methodFqn, "(java.lang.String)", null, 9, null, unknown); methodFqn += "(java.lang.String)"; relationWriter.writeRelation(Relation.CONTAINS, fqn, methodFqn, unknown); relationWriter.writeRelation(Relation.RETURNS, methodFqn, fqn, unknown); localVariableWriter.writeLocalVariable(LocalVariable.PARAM, "name", 0, "java.lang.String", unknown, methodFqn, 0, unknown); } fqnStack.pop(); return false; }