Exemple #1
0
 public boolean isTracing(final String traceOption) {
   if (!Platform.inDebugMode()) {
     return false;
   }
   final String globalTraceValue = Platform.getDebugOption(ERLIDE_GLOBAL_TRACE_OPTION);
   final String value = Platform.getDebugOption(ERLIDE_GLOBAL_TRACE_OPTION + "/" + traceOption);
   if ("true".equalsIgnoreCase(globalTraceValue) && "true".equalsIgnoreCase(value)) {
     return true;
   }
   return false;
 }
 /** @return true if the platform is debugging */
 public static boolean isDebugging() {
   return Platform.inDebugMode();
 }
Exemple #3
0
 /**
  * Computes a qualified name for named elements (types, methods, parameters, ...).
  *
  * @param object a model element.
  * @param removeGenerics if we have to remove the generics.
  * @return the qualified name or {@code null} if the object type is not a named type.
  */
 public static String getQualifiedName(final ASTNode object, final boolean removeGenerics) {
   StringBuilder buffer = new StringBuilder();
   if (object instanceof UnresolvedItem) {
     buffer.append(((UnresolvedItem) object).getName());
   } else if (object instanceof AnnotationTypeMemberDeclaration) {
     String containerQName = getQualifiedName((ASTNode) object.eContainer(), removeGenerics);
     buffer.append(containerQName);
     buffer.append("."); // $NON-NLS-1$
     buffer.append(((AnnotationTypeMemberDeclaration) object).getName());
     buffer.append("()"); // $NON-NLS-1$
   } else if (object instanceof EnumConstantDeclaration) {
     String containerQName = getQualifiedName((ASTNode) object.eContainer(), removeGenerics);
     buffer.append(containerQName);
     buffer.append("."); // $NON-NLS-1$
     buffer.append(((EnumConstantDeclaration) object).getName());
   } else if (object instanceof VariableDeclarationFragment) {
     if (object.eContainer() instanceof FieldDeclaration) {
       VariableDeclarationFragment singleVariableDeclaration =
           (VariableDeclarationFragment) object;
       String containerQN =
           getQualifiedName(
               (ASTNode) singleVariableDeclaration.eContainer().eContainer(), removeGenerics);
       buffer.append(containerQN);
       buffer.append("."); // $NON-NLS-1$
       buffer.append(singleVariableDeclaration.getName());
     }
   } else if (object instanceof AbstractMethodDeclaration) {
     AbstractMethodDeclaration methodDeclaration = (AbstractMethodDeclaration) object;
     String containerQName = getQualifiedName((ASTNode) object.eContainer(), removeGenerics);
     buffer.append(containerQName);
     buffer.append('.');
     buffer.append(methodDeclaration.getName());
     buffer.append('(');
     for (int i = 0; i < methodDeclaration.getParameters().size(); i++) {
       if (i > 0) {
         buffer.append(","); // $NON-NLS-1$
       }
       SingleVariableDeclaration svd = methodDeclaration.getParameters().get(i);
       buffer.append(getQualifiedName(svd.getType(), true));
     }
     buffer.append(")"); // $NON-NLS-1$
   } else if (object instanceof ArrayType) {
     ArrayType arraytype = (ArrayType) object;
     buffer.append(arraytype.getName());
   } else if (object instanceof TypeParameter) {
     TypeParameter typeParameter = (TypeParameter) object;
     if (removeGenerics) {
       if (typeParameter.getBounds().size() > 0) {
         // get the erasure
         buffer.append(getQualifiedName(typeParameter.getBounds().get(0), true));
       } else {
         buffer.append("java.lang.Object"); // $NON-NLS-1$
       }
     } else {
       buffer.append(typeParameter.getName());
     }
   } else if (object instanceof WildCardType) {
     WildCardType wildcardType = (WildCardType) object;
     buffer.append(wildcardType.getName());
   } else if (object instanceof ParameterizedType) {
     ParameterizedType parameterizedType = (ParameterizedType) object;
     if (removeGenerics) {
       buffer.append(getQualifiedName(parameterizedType.getType(), removeGenerics));
     } else {
       buffer.append(parameterizedType.getName());
     }
   } else if (object instanceof AbstractTypeDeclaration) {
     AbstractTypeDeclaration typeDeclaration = (AbstractTypeDeclaration) object;
     if (typeDeclaration.eContainer() instanceof AbstractTypeDeclaration) {
       AbstractTypeDeclaration superTypeDeclaration =
           (AbstractTypeDeclaration) typeDeclaration.eContainer();
       buffer.append(getQualifiedName(superTypeDeclaration, removeGenerics));
       buffer.append('.');
     } else if (typeDeclaration.eContainer() instanceof Package) {
       Package packaje = (Package) typeDeclaration.eContainer();
       buffer.append(getQualifiedName(packaje, removeGenerics));
       buffer.append('.');
     } else if (typeDeclaration.eContainer() instanceof Model) {
       // No prefix if container is a Model instance
       assert true; // misc statement for checkstyle rule
     } else if (typeDeclaration.eContainer() != null) {
       MoDiscoLogger.logWarning(
           "Not managed type declaration: typeDeclaration.eContainer().getClass()= " //$NON-NLS-1$
           ,
           JavaPlugin.getDefault());
     } else {
       MoDiscoLogger.logWarning(
           "Type with null container" //$NON-NLS-1$
           ,
           JavaPlugin.getDefault());
     }
     buffer.append(typeDeclaration.getName());
   } else if (object instanceof Package) {
     Package packaje = (Package) object;
     if (packaje.eContainer() instanceof Package) {
       Package superPackage = (Package) packaje.eContainer();
       buffer.append(getQualifiedName(superPackage, removeGenerics));
       buffer.append('.');
     }
     buffer.append(packaje.getName());
   } else if (object instanceof TypeAccess) {
     TypeAccess typeAccess = (TypeAccess) object;
     buffer.append(getQualifiedName(typeAccess.getType(), removeGenerics));
   } else if (object instanceof Model) {
     Exception e =
         new Exception(
             "getQualified name should note be called with a model as parameter"); //$NON-NLS-1$
     IStatus status = new Status(IStatus.ERROR, JavaPlugin.PLUGIN_ID, e.getMessage(), e);
     JavaPlugin.getDefault().getLog().log(status);
   } else if (object instanceof PrimitiveType) {
     PrimitiveType primitiveType = (PrimitiveType) object;
     buffer.append(primitiveType.getName());
   } else if (object instanceof AnonymousClassDeclaration) {
     // No qualified name for AnonymousClassDeclaration
     assert true; // misc statement for checkstyle rule
   } else if (object instanceof SingleVariableDeclaration) {
     SingleVariableDeclaration singleVariableDeclaration = (SingleVariableDeclaration) object;
     if (!(singleVariableDeclaration.eContainer() instanceof CatchClause)) {
       buffer.append(
           getQualifiedName((ASTNode) singleVariableDeclaration.eContainer(), removeGenerics));
       buffer.append('.');
     }
     buffer.append(singleVariableDeclaration.getName());
   } else if (object != null) {
     Exception e =
         new Exception(
             "Not managed type: " //$NON-NLS-1$
                 + object.getClass().getName());
     IStatus status = new Status(IStatus.ERROR, JavaPlugin.PLUGIN_ID, e.getMessage(), e);
     JavaPlugin.getDefault().getLog().log(status);
   } else {
     // May occur when parent model element is not complete (e.g.
     // unresolved type of parameter of method)
     // Exception e = new Exception("Null parameter");
     // IStatus status = new Status(IStatus.ERROR, JavaPlugin.PLUGIN_ID,
     // e
     // .getMessage(), e);
     // JavaPlugin.getDefault().getLog().log(status);
     buffer.append("<<null>>"); // $NON-NLS-1$
   }
   if (Platform.inDebugMode() && JavaUtil.TRACE_GETQNAME) {
     System.out.println(
         "JavaUtil.getQualifiedName(EObject)= " //$NON-NLS-1$
             + buffer.toString());
   }
   return buffer.toString();
 }