示例#1
0
 @Test
 public void testEnumArtificialMethods() {
   try {
     StringConcatenation _builder = new StringConcatenation();
     _builder.append("package bar");
     _builder.newLine();
     _builder.newLine();
     _builder.append("enum Foo {");
     _builder.newLine();
     _builder.append("}");
     _builder.newLine();
     String _string = _builder.toString();
     XtendEnum _enumeration = this.enumeration(_string);
     JvmEnumerationType _inferredEnumerationType =
         this._iXtendJvmAssociations.getInferredEnumerationType(_enumeration);
     final EList<JvmMember> inferred = _inferredEnumerationType.getMembers();
     int _size = inferred.size();
     Assert.assertEquals(2, _size);
     JvmMember _get = inferred.get(0);
     final JvmOperation values = ((JvmOperation) _get);
     String _identifier = values.getIdentifier();
     Assert.assertEquals("bar.Foo.values()", _identifier);
     boolean _isStatic = values.isStatic();
     Assert.assertTrue(_isStatic);
     JvmVisibility _visibility = values.getVisibility();
     Assert.assertEquals(JvmVisibility.PUBLIC, _visibility);
     JvmMember _get_1 = inferred.get(1);
     final JvmOperation valueOf = ((JvmOperation) _get_1);
     String _identifier_1 = valueOf.getIdentifier();
     Assert.assertEquals("bar.Foo.valueOf(java.lang.String)", _identifier_1);
     boolean _isStatic_1 = valueOf.isStatic();
     Assert.assertTrue(_isStatic_1);
     JvmVisibility _visibility_1 = valueOf.getVisibility();
     Assert.assertEquals(JvmVisibility.PUBLIC, _visibility_1);
   } catch (Throwable _e) {
     throw Exceptions.sneakyThrow(_e);
   }
 }
 protected SignatureHashBuilder appendSignature(JvmOperation operation) {
   appendVisibility(operation.getVisibility()).append(" ");
   if (operation.isAbstract()) append("abstract ");
   if (operation.isStatic()) append("static ");
   if (operation.isFinal()) append("final ");
   appendType(operation.getReturnType())
       .appendTypeParameters(operation)
       .append(" ")
       .append(operation.getSimpleName())
       .append("(");
   for (JvmFormalParameter p : operation.getParameters()) {
     appendType(p.getParameterType());
     append(" ");
   }
   append(") ");
   for (JvmTypeReference ex : operation.getExceptions()) {
     appendType(ex).append(" ");
   }
   return this;
 }
 protected void createFeatureNodesForType(
     IOutlineNode parentNode,
     XtendTypeDeclaration xtendType,
     JvmDeclaredType inferredType,
     final JvmDeclaredType baseType,
     Set<JvmFeature> processedFeatures,
     int inheritanceDepth) {
   if (xtendType instanceof XtendClass) {
     for (JvmOperation operation : inferredType.getDeclaredOperations()) {
       if (dispatchHelper.isDispatcherFunction(operation)) {
         JvmOperation dispatcher = operation;
         XtendFeatureNode dispatcherNode =
             createNodeForFeature(parentNode, baseType, dispatcher, dispatcher, inheritanceDepth);
         if (dispatcherNode != null) {
           dispatcherNode.setDispatch(true);
           processedFeatures.add(dispatcher);
           boolean inheritsDispatchCases = false;
           Iterable<JvmOperation> dispatchCases;
           if (getCurrentMode() == SHOW_INHERITED_MODE)
             dispatchCases = dispatchHelper.getAllDispatchCases(dispatcher);
           else {
             dispatchCases = newArrayList(dispatchHelper.getLocalDispatchCases(dispatcher));
             sort(
                 (List<JvmOperation>) dispatchCases,
                 new Comparator<JvmOperation>() {
                   public int compare(JvmOperation o1, JvmOperation o2) {
                     return baseType.getMembers().indexOf(o1) - baseType.getMembers().indexOf(o2);
                   }
                 });
           }
           for (JvmOperation dispatchCase : dispatchCases) {
             inheritsDispatchCases |= dispatchCase.getDeclaringType() != baseType;
             XtendFunction xtendFunction = associations.getXtendFunction(dispatchCase);
             if (xtendFunction == null) {
               createNodeForFeature(
                   dispatcherNode, baseType, dispatchCase, dispatchCase, inheritanceDepth);
             } else {
               createNodeForFeature(
                   dispatcherNode, baseType, dispatchCase, xtendFunction, inheritanceDepth);
             }
             processedFeatures.add(dispatchCase);
           }
           if (inheritsDispatchCases)
             dispatcherNode.setImageDescriptor(
                 images.forDispatcherFunction(
                     dispatcher.getVisibility(),
                     adornments.get(dispatcher) | JavaElementImageDescriptor.OVERRIDES));
         }
       }
     }
   }
   for (JvmFeature feature : filter(inferredType.getMembers(), JvmFeature.class)) {
     if (!processedFeatures.contains(feature)) {
       EObject primarySourceElement = associations.getPrimarySourceElement(feature);
       createNodeForFeature(
           parentNode,
           baseType,
           feature,
           primarySourceElement != null ? primarySourceElement : feature,
           inheritanceDepth);
     }
   }
   if (getCurrentMode() == SHOW_INHERITED_MODE) {
     if (inferredType instanceof JvmGenericType) {
       JvmTypeReference extendedClass = ((JvmGenericType) inferredType).getExtendedClass();
       if (extendedClass != null)
         createInheritedFeatureNodes(
             parentNode, baseType, processedFeatures, inheritanceDepth, extendedClass);
       for (JvmTypeReference extendedInterface :
           ((JvmGenericType) inferredType).getExtendedInterfaces()) {
         createInheritedFeatureNodes(
             parentNode, baseType, processedFeatures, inheritanceDepth, extendedInterface);
       }
     }
   }
 }