Java 类org.eclipse.xtext.common.types.JvmConstructor 实例源码

项目:xtext-extras    文件:AbstractConstructorScope.java   
@Override
public Iterable<IEObjectDescription> getElements(EObject object) {
    if (object instanceof JvmConstructor) {
        JvmConstructor constructor = ((JvmConstructor) object);
        String qualifiedNameWithDots = constructor.getQualifiedName('.');
        String qualifiedNameWithDollar = constructor.getQualifiedName();
        if (qualifiedNameWithDollar.equals(qualifiedNameWithDots)) {
            final Set<IEObjectDescription> result = singleton(
                    EObjectDescription.create(getQualifiedNameConverter().toQualifiedName(qualifiedNameWithDots), object));
            return result;
        } else {
            return Arrays.asList(
                    EObjectDescription.create(getQualifiedNameConverter().toQualifiedName(qualifiedNameWithDots), object),
                    EObjectDescription.create(getQualifiedNameConverter().toQualifiedName(qualifiedNameWithDollar), object));
        }
    }
    return emptySet();
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void test_staticNestedTypes_constructor() {
    String typeName = Bug347739.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    List<JvmMember> members = type.getMembers();
    for (JvmMember member : members) {
        if (member instanceof JvmGenericType) {
            if ("StackItem".equals(member.getSimpleName())) {
                JvmGenericType stackItem = (JvmGenericType) member;
                Iterable<JvmConstructor> constructors = stackItem.getDeclaredConstructors();
                for (JvmConstructor constructor : constructors) {
                    assertEquals(2, constructor.getParameters().size());
                }
                return;
            }
        }
    }
    fail("could not find inner class");
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
protected void doTestInnerType_WrappedIterator_02(JvmGenericType wrappedIterator) {
    assertEquals(3, Iterables.size(wrappedIterator.getDeclaredConstructors()));
    JvmConstructor constructor = (JvmConstructor) Iterables.find(wrappedIterator.getMembers(),
            new Predicate<JvmMember>() {
                @Override
                public boolean apply(JvmMember input) {
                    return (input instanceof JvmConstructor) && input.getSimpleName().equals("WrappedIterator")
                            && ((JvmConstructor) input).getParameters().size() == 3;
                }
            });
    assertNotNull(constructor);
    JvmFormalParameter firstParameter = constructor.getParameters().get(0);
    assertEquals(1, firstParameter.getAnnotations().size());
    assertEquals("java.lang.String", firstParameter.getParameterType().getIdentifier());
    assertEquals(TestAnnotationWithDefaults.class.getName(),
            firstParameter.getAnnotations().get(0).getAnnotation().getQualifiedName());
    JvmFormalParameter secondParameter = constructor.getParameters().get(1);
    assertEquals(0, secondParameter.getAnnotations().size());
    assertEquals("int", secondParameter.getParameterType().getIdentifier());
    JvmFormalParameter thirdParameter = constructor.getParameters().get(2);
    assertEquals(1, thirdParameter.getAnnotations().size());
    assertEquals("java.util.Iterator<V>", thirdParameter.getParameterType().getIdentifier());
    assertEquals(TestAnnotation.NestedAnnotation.class.getName(),
            thirdParameter.getAnnotations().get(0).getAnnotation().getQualifiedName());
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void testEnum_04() throws Exception {
    String typeName = TestEnum.class.getName();
    JvmEnumerationType type = (JvmEnumerationType) getTypeProvider().findTypeByName(typeName);
    List<JvmMember> members = type.getMembers();
    boolean constructorFound = false;
    for (JvmMember member : members) {
        if (member instanceof JvmConstructor) {
            assertFalse(constructorFound);
            constructorFound = true;
            List<JvmFormalParameter> parameters = ((JvmConstructor) member).getParameters();
            assertEquals(1, parameters.size()); // synthetic parameters are not returned
        }
    }
    assertTrue(constructorFound);
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void testNestedEnum_04() throws Exception {
    String typeName = TestEnum.Nested.class.getName();
    JvmEnumerationType type = (JvmEnumerationType) getTypeProvider().findTypeByName(typeName);
    List<JvmMember> members = type.getMembers();
    boolean constructorFound = false;
    for (JvmMember member : members) {
        if (member instanceof JvmConstructor) {
            assertFalse(constructorFound);
            constructorFound = true;
            List<JvmFormalParameter> parameters = ((JvmConstructor) member).getParameters();
            assertEquals(0, parameters.size()); // synthetic parameters are not returned
        }
    }
    assertTrue(constructorFound);
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
public JvmAnnotationValue getConstructorParameterAnnotationValue(String name, boolean defaultValue) {
    String typeName = TestAnnotation.Annotated.class.getName();
    JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName);
    JvmConstructor constructor = getConstructorFromType(type, TestAnnotation.Annotated.class,
            "Annotated(java.lang.String,java.lang.String,java.lang.String)");
    JvmAnnotationTarget target = constructor.getParameters().get(0);
    JvmAnnotationValue result = getDefaultOrExplicitAnnotationValue(name, target);
    if (defaultValue) {
        if (isDefaultValueSupported()) {
            assertTrue(result.eContainer() instanceof JvmOperation);
        } else {
            assertFalse(result.eContainer() instanceof JvmOperation);
        }
    } else {
        assertFalse(result.eContainer() instanceof JvmOperation);
    }
    return result;
}
项目:xtext-extras    文件:XbaseValidator.java   
@Check
public void checkDelegateConstructorIsFirst(XFeatureCall featureCall) {
    JvmIdentifiableElement feature = featureCall.getFeature();
    if (feature != null && !feature.eIsProxy() && feature instanceof JvmConstructor) {
        JvmIdentifiableElement container = logicalContainerProvider.getNearestLogicalContainer(featureCall);
        if (container != null) {
            if (container instanceof JvmConstructor) {
                XExpression body = logicalContainerProvider.getAssociatedExpression(container);
                if (body == featureCall)
                    return;
                if (body instanceof XBlockExpression) {
                    List<XExpression> expressions = ((XBlockExpression) body).getExpressions();
                    if (expressions.isEmpty() || expressions.get(0) != featureCall) {
                        error("Constructor call must be the first expression in a constructor", null, INVALID_CONSTRUCTOR_INVOCATION);
                    }
                }
            } else {
                error("Constructor call must be the first expression in a constructor", null, INVALID_CONSTRUCTOR_INVOCATION);
            }
        }
    }
}
项目:xtext-extras    文件:LogicalContainerAwareReentrantTypeResolver.java   
protected void doPrepare(ResolvedTypes resolvedTypes, IFeatureScopeSession featureScopeSession, JvmIdentifiableElement element, Map<JvmIdentifiableElement, ResolvedTypes> resolvedTypesByContext) {
    XExpression expression = getLogicalContainerProvider().getAssociatedExpression(element);
    if (expression != null) {
        if (!rootedInstances.contains(expression)) {
            throw new IllegalStateException("Expression not yet recorded: " + expression);
        }
    }
    if (element instanceof JvmDeclaredType) {
        _doPrepare(resolvedTypes, featureScopeSession, (JvmDeclaredType) element, resolvedTypesByContext);
    } else if (element instanceof JvmConstructor) {
        _doPrepare(resolvedTypes, featureScopeSession, (JvmConstructor) element, resolvedTypesByContext);
    } else if (element instanceof JvmField) {
        _doPrepare(resolvedTypes, featureScopeSession, (JvmField) element, resolvedTypesByContext);
    } else if (element instanceof JvmOperation) {
        _doPrepare(resolvedTypes, featureScopeSession, (JvmOperation) element, resolvedTypesByContext);
    }
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
protected void doTestInnerType_WrappedIterator_02(JvmGenericType wrappedIterator) {
    assertEquals(3, Iterables.size(wrappedIterator.getDeclaredConstructors()));
    JvmConstructor constructor = (JvmConstructor) Iterables.find(wrappedIterator.getMembers(),
            new Predicate<JvmMember>() {
                @Override
                public boolean apply(JvmMember input) {
                    return (input instanceof JvmConstructor) && input.getSimpleName().equals("WrappedIterator")
                            && ((JvmConstructor) input).getParameters().size() == 3;
                }
            });
    assertNotNull(constructor);
    JvmFormalParameter firstParameter = constructor.getParameters().get(0);
    assertEquals(1, firstParameter.getAnnotations().size());
    assertEquals("java.lang.String", firstParameter.getParameterType().getIdentifier());
    assertEquals(TestAnnotationWithDefaults.class.getName(),
            firstParameter.getAnnotations().get(0).getAnnotation().getQualifiedName());
    JvmFormalParameter secondParameter = constructor.getParameters().get(1);
    assertEquals(0, secondParameter.getAnnotations().size());
    assertEquals("int", secondParameter.getParameterType().getIdentifier());
    JvmFormalParameter thirdParameter = constructor.getParameters().get(2);
    assertEquals(1, thirdParameter.getAnnotations().size());
    assertEquals("java.util.Iterator<V>", thirdParameter.getParameterType().getIdentifier());
    assertEquals(TestAnnotation.NestedAnnotation.class.getName(),
            thirdParameter.getAnnotations().get(0).getAnnotation().getQualifiedName());
}
项目:xtext-extras    文件:ScopeProviderAccess.java   
protected IConstructorLinkingCandidate getKnownConstructor(XConstructorCall constructorCall, AbstractTypeComputationState state,
        ResolvedTypes resolvedTypes) {
    IConstructorLinkingCandidate result = resolvedTypes.getConstructor(constructorCall);
    if (result != null) {
        return result;
    }
    EObject proxyOrResolved = (EObject) constructorCall.eGet(XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR, false);
    if (proxyOrResolved == null) {
        result = new NullConstructorLinkingCandidate(constructorCall, state);
        return result;
    }
    if (!proxyOrResolved.eIsProxy()) {
        result = state.createResolvedLink(constructorCall, (JvmConstructor) proxyOrResolved);
        return result;
    }
    if (!encoder.isCrossLinkFragment(constructorCall.eResource(), EcoreUtil.getURI(proxyOrResolved).fragment())) {
        JvmConstructor constructor = constructorCall.getConstructor();
        if (!constructor.eIsProxy()) {
            return state.createResolvedLink(constructorCall, constructor);
        }
    }
    return null;
}
项目:xtext-extras    文件:ResolvedTypes.java   
protected JvmTypeReference getDeclaredType(JvmIdentifiableElement identifiable) {
    if (identifiable instanceof JvmOperation) {
        return ((JvmOperation) identifiable).getReturnType();
    }
    if (identifiable instanceof JvmField) {
        return ((JvmField) identifiable).getType();
    }
    if (identifiable instanceof JvmConstructor) {
        return shared.resolver.getServices().getTypeReferences().createTypeRef(((JvmConstructor) identifiable).getDeclaringType());
    }
    if (identifiable instanceof JvmFormalParameter) {
        JvmTypeReference parameterType = ((JvmFormalParameter) identifiable).getParameterType();
        return parameterType;
    }
    return null;
}
项目:xtext-extras    文件:JvmModelCompleter.java   
public void complete(JvmIdentifiableElement element) {
    if (element instanceof JvmGenericType) {
        completeJvmGenericType((JvmGenericType)element);
    }
    if (element instanceof JvmDeclaredType) {
        JvmDeclaredType declaredType = (JvmDeclaredType) element;
        complete(declaredType.getMembers());
    }
    if(element instanceof JvmConstructor) {
        completeJvmConstructor((JvmConstructor) element);
    }
    if (element instanceof JvmEnumerationType) {
        completeJvmEnumerationType((JvmEnumerationType)element);
    }
    if (element instanceof JvmEnumerationLiteral) {
        completeJvmEnumerationLiteral((JvmEnumerationLiteral)element);
    }
    if (element instanceof JvmAnnotationType) {
        completeJvmAnnotationType((JvmAnnotationType)element);
    }
}
项目:xtext-extras    文件:JvmModelCompleter.java   
protected void completeJvmGenericType(JvmGenericType element) {
    // if no super type add Object
    ensureSuperTypeObject(element);
    addAnnotations(element);
    if (!element.isInterface()) {
        // if no constructors have been added, add a default constructor
        if (isEmpty(element.getDeclaredConstructors())) {
            JvmConstructor constructor = TypesFactory.eINSTANCE.createJvmConstructor();
            constructor.setSimpleName(element.getSimpleName());
            constructor.setVisibility(JvmVisibility.PUBLIC);
            typeExtensions.setSynthetic(constructor, true);
            EObject primarySourceElement = associations.getPrimarySourceElement(element);
            if (primarySourceElement != null) {
                associator.associate(primarySourceElement, constructor);
            }
            element.getMembers().add(constructor);
        }
    }
}
项目:xtext-extras    文件:SerializerScopeProvider.java   
public IScope createFeatureCallSerializationScope(EObject context) {
    if (!(context instanceof XAbstractFeatureCall)) {
        return IScope.NULLSCOPE;
    }
    XAbstractFeatureCall call = (XAbstractFeatureCall) context;
    JvmIdentifiableElement feature = call.getFeature();
    // this and super - logical container aware FeatureScopes
    if (feature instanceof JvmType) {
        return getTypeScope(call, (JvmType) feature);
    }
    if (feature instanceof JvmConstructor) {
        return getThisOrSuperScope(call, (JvmConstructor) feature);
    }
    if (feature instanceof JvmExecutable) {
        return getExecutableScope(call, feature);
    }
    if (feature instanceof JvmFormalParameter || feature instanceof JvmField || feature instanceof XVariableDeclaration || feature instanceof XSwitchExpression) {
        return new SingletonScope(EObjectDescription.create(feature.getSimpleName(), feature), IScope.NULLSCOPE);
    }
    return IScope.NULLSCOPE;
}
项目:xtext-extras    文件:AbstractConstructorScope.java   
@Override
public Iterable<IEObjectDescription> getElements(final QualifiedName name) {
    IEObjectDescription typeDescription = typeScope.getSingleElement(name);
    if (typeDescription == null)
        return emptySet();
    JvmType type = (JvmType) typeDescription.getEObjectOrProxy();
    if (type.eIsProxy() || !(type instanceof JvmGenericType)) {
        return emptySet();
    }
    final JvmGenericType castedType = (JvmGenericType) type;
    if (castedType.isInterface()) {
        return emptySet();
    }
    Iterable<JvmConstructor> constructors = new Iterable<JvmConstructor>() {
        @Override
        public Iterator<JvmConstructor> iterator() {
            return castedType.getDeclaredConstructors().iterator();
        }
    };
    return transform(constructors, new Function<JvmConstructor,IEObjectDescription>(){
        @Override
        public IEObjectDescription apply(JvmConstructor from) {
            return EObjectDescription.create(name, from);
        }
    });
}
项目:xtext-extras    文件:ConstructorTypeScopeWrapper.java   
protected void addFeatureDescriptions(IEObjectDescription typeDescription, List<IEObjectDescription> result) {
    EObject proxy = getResolvedProxy(typeDescription);
    if (!proxy.eIsProxy() && proxy instanceof JvmGenericType) {
        JvmGenericType type = (JvmGenericType) proxy;
        if (!type.isInterface()) {
            for(JvmConstructor constructor: type.getDeclaredConstructors()) {
                boolean visible = visibilityHelper.isVisible(constructor);
                ConstructorDescription constructorDescription = createConstructorDescription(typeDescription, constructor, visible);
                result.add(constructorDescription);
            }
        } else if (!strict) {
            result.add(new SimpleIdentifiableElementDescription(typeDescription));
        }
    } else if (proxy instanceof JvmType) {
        if (!strict)
            result.add(new SimpleIdentifiableElementDescription(typeDescription));
    }
}
项目:xtext-extras    文件:AbstractXbaseCompiler.java   
protected boolean hasJvmConstructorCall(XExpression obj) {
    if (!(obj instanceof XBlockExpression)) {
        return false;
    }
    XBlockExpression blockExpression = (XBlockExpression) obj;
    EList<XExpression> expressions = blockExpression.getExpressions();
    if (expressions.isEmpty()) {
        return false;
    }
    XExpression expr = expressions.get(0);
    if (!(expr instanceof XFeatureCall)) {
        return false;
    }
    XFeatureCall featureCall = (XFeatureCall) expr;
    return featureCall.getFeature() instanceof JvmConstructor;
}
项目:xtext-extras    文件:XbaseInterpreter.java   
protected Object _doEvaluate(XConstructorCall constructorCall, IEvaluationContext context, CancelIndicator indicator) {
    JvmConstructor jvmConstructor = constructorCall.getConstructor();
    List<Object> arguments = evaluateArgumentExpressions(jvmConstructor, constructorCall.getArguments(), context, indicator);
    Constructor<?> constructor = javaReflectAccess.getConstructor(jvmConstructor);
    try {
        if (constructor == null)
            throw new NoSuchMethodException("Could not find constructor " + jvmConstructor.getIdentifier());
        constructor.setAccessible(true);
        Object result = constructor.newInstance(arguments.toArray(new Object[arguments.size()]));
        return result;
    } catch (InvocationTargetException targetException) {
        throw new EvaluationException(targetException.getTargetException());
    } catch (Exception e) {
        throw new IllegalStateException("Could not invoke constructor: " + jvmConstructor.getIdentifier(), e);
    }
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void test_staticNestedTypes_constructor() {
    String typeName = Bug347739.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    List<JvmMember> members = type.getMembers();
    for (JvmMember member : members) {
        if (member instanceof JvmGenericType) {
            if ("StackItem".equals(member.getSimpleName())) {
                JvmGenericType stackItem = (JvmGenericType) member;
                Iterable<JvmConstructor> constructors = stackItem.getDeclaredConstructors();
                for (JvmConstructor constructor : constructors) {
                    assertEquals(2, constructor.getParameters().size());
                }
                return;
            }
        }
    }
    fail("could not find inner class");
}
项目:xtext-extras    文件:JvmModelGenerator.java   
protected ITreeAppendable _generateMember(final JvmConstructor it, final ITreeAppendable appendable, final GeneratorConfig config) {
  ITreeAppendable _xblockexpression = null;
  {
    appendable.newLine();
    appendable.openScope();
    this.generateJavaDoc(it, appendable, config);
    final ITreeAppendable tracedAppendable = appendable.trace(it);
    this.generateAnnotations(it.getAnnotations(), tracedAppendable, true, config);
    this.generateModifier(it, tracedAppendable, config);
    this.generateTypeParameterDeclaration(it, tracedAppendable, config);
    this._treeAppendableUtil.traceSignificant(tracedAppendable, it).append(this.makeJavaIdentifier(it.getSimpleName()));
    tracedAppendable.append("(");
    this.generateParameters(it, tracedAppendable, config);
    tracedAppendable.append(")");
    this.generateThrowsClause(it, tracedAppendable, config);
    tracedAppendable.append(" ");
    this.generateExecutableBody(it, tracedAppendable, config);
    appendable.closeScope();
    _xblockexpression = appendable;
  }
  return _xblockexpression;
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void testEnum_04() throws Exception {
    String typeName = TestEnum.class.getName();
    JvmEnumerationType type = (JvmEnumerationType) getTypeProvider().findTypeByName(typeName);
    List<JvmMember> members = type.getMembers();
    boolean constructorFound = false;
    for (JvmMember member : members) {
        if (member instanceof JvmConstructor) {
            assertFalse(constructorFound);
            constructorFound = true;
            List<JvmFormalParameter> parameters = ((JvmConstructor) member).getParameters();
            assertEquals(1, parameters.size()); // synthetic parameters are not returned
        }
    }
    assertTrue(constructorFound);
}
项目:xtext-extras    文件:JvmModelGenerator.java   
public ITreeAppendable generateModifier(final JvmMember it, final ITreeAppendable appendable, final GeneratorConfig config) {
  if (it instanceof JvmConstructor) {
    return _generateModifier((JvmConstructor)it, appendable, config);
  } else if (it instanceof JvmOperation) {
    return _generateModifier((JvmOperation)it, appendable, config);
  } else if (it instanceof JvmField) {
    return _generateModifier((JvmField)it, appendable, config);
  } else if (it instanceof JvmGenericType) {
    return _generateModifier((JvmGenericType)it, appendable, config);
  } else if (it instanceof JvmDeclaredType) {
    return _generateModifier((JvmDeclaredType)it, appendable, config);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it, appendable, config).toString());
  }
}
项目:xtext-extras    文件:JvmModelGenerator.java   
public ITreeAppendable generateMember(final JvmMember it, final ITreeAppendable appendable, final GeneratorConfig config) {
  if (it instanceof JvmConstructor) {
    return _generateMember((JvmConstructor)it, appendable, config);
  } else if (it instanceof JvmOperation) {
    return _generateMember((JvmOperation)it, appendable, config);
  } else if (it instanceof JvmField) {
    return _generateMember((JvmField)it, appendable, config);
  } else if (it instanceof JvmDeclaredType) {
    return _generateMember((JvmDeclaredType)it, appendable, config);
  } else if (it != null) {
    return _generateMember(it, appendable, config);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it, appendable, config).toString());
  }
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void test_nestedInterface_Outer_02() {
    String typeName = NestedInterfaces.class.getName() + "$Outer";
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    List<JvmConstructor> constructors = Lists.newArrayList(type.getDeclaredConstructors());
    assertEquals(0, constructors.size());
    assertEquals(JvmVisibility.DEFAULT, type.getVisibility());
    assertTrue(type.isStatic());
    assertTrue(type.isAbstract());
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void test_nestedInterface_Outer_Inner_02() {
    String typeName = NestedInterfaces.class.getName() + "$Outer$Inner";
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    List<JvmConstructor> constructors = Lists.newArrayList(type.getDeclaredConstructors());
    assertEquals(0, constructors.size());
    assertEquals(JvmVisibility.PUBLIC, type.getVisibility());
    assertTrue(type.isStatic());
    assertTrue(type.isAbstract());
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void test_nestedTypes_Outer_02() {
    String typeName = NestedTypes.Outer.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    List<JvmConstructor> constructors = Lists.newArrayList(type.getDeclaredConstructors());
    assertEquals(1, constructors.size());
    JvmConstructor parameterlessConstructor = constructors.get(0);
    assertEquals(0, parameterlessConstructor.getParameters().size());
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
protected JvmConstructor getConstructorFromType(EObject context, Class<?> type, String constructor) {
    String methodName = type.getName() + "." + constructor;
    assertNotNull(context);
    JvmConstructor result = (JvmConstructor) context.eResource().getEObject(methodName);
    assertNotNull(methodName, result);
    return result;
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void test_nestedTypes_Outer_Inner_02() {
    String typeName = NestedTypes.Outer.Inner.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    List<JvmConstructor> constructors = Lists.newArrayList(type.getDeclaredConstructors());
    assertEquals(1, constructors.size());
    JvmConstructor parameterlessConstructor = constructors.get(0);
    assertEquals(1, parameterlessConstructor.getParameters().size());
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
public JvmAnnotationValue getConstructorParameterAnnotationValue(String name) {
    String typeName = TestAnnotation.Annotated.class.getName();
    JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName);
    JvmConstructor constructor = getConstructorFromType(type, TestAnnotation.Annotated.class,
            "Annotated(java.lang.String,java.lang.String,java.lang.String)");
    JvmAnnotationTarget target = constructor.getParameters().get(0);
    return getExplicitAnnotationValue(name, target);
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void testAnnotatedConstructor_01() throws Exception {
    String typeName = TestAnnotation.Annotated.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    JvmConstructor constructor = getConstructorFromType(type, TestAnnotation.Annotated.class, "Annotated()");
    assertNotNull(constructor);
    JvmStringAnnotationValue value = (JvmStringAnnotationValue) getExplicitAnnotationValue("value", constructor);
    assertEquals(1, value.getValues().size());
    String s = value.getValues().get(0);
    assertEquals("constructor", s);
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void testAnnotatedConstructor_02() throws Exception {
    String typeName = TestAnnotation.Annotated.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    JvmConstructor constructor = getConstructorFromType(type, TestAnnotation.Annotated.class,
            "Annotated(java.lang.String)");
    assertNotNull(constructor);
    JvmStringAnnotationValue value = (JvmStringAnnotationValue) getExplicitAnnotationValue("value", constructor);
    assertEquals(1, value.getValues().size());
    String s = value.getValues().get(0);
    assertEquals("secondConstructor", s);
}
项目:xtext-extras    文件:JavaReflectAccess.java   
/**
 * @return the {@link Constructor} corresponding to the given {@link JvmConstructor} or <code>null</code>.
 */
public Constructor<?> getConstructor(JvmConstructor constructor) {
    Class<?> declaringType = getRawType(constructor.getDeclaringType());
    if (declaringType == null)
        return null;
    Class<?>[] paramTypes = getParamTypes(constructor);
    try {
        return declaringType.getDeclaredConstructor(paramTypes);
    } catch (Exception e) {
        if (log.isDebugEnabled())
            log.debug(e.getMessage(), e);
    }
    return null;
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void testAnnotatedConstructor_04() throws Exception {
    String typeName = TestAnnotation.Annotated.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    JvmConstructor constructor = getConstructorFromType(type, TestAnnotation.Annotated.class,
            "Annotated(java.lang.String,java.lang.String)");
    assertNotNull(constructor);
    JvmStringAnnotationValue value = (JvmStringAnnotationValue) getExplicitAnnotationValue("value", constructor);
    assertEquals(1, value.getValues().size());
    String s = value.getValues().get(0);
    assertEquals("thirdConstructorWithBody", s);
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void testAnnotatedParameter_02() throws Exception {
    String typeName = TestAnnotation.Annotated.class.getName();
    JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName);
    JvmConstructor constructor = getConstructorFromType(type, TestAnnotation.Annotated.class,
            "Annotated(java.lang.String,java.lang.String,java.lang.String)");
    JvmAnnotationTarget target = constructor.getParameters().get(1);
    assertEquals(0, target.getAnnotations().size());
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void testAnnotatedParameter_03() throws Exception {
    String typeName = TestAnnotation.Annotated.class.getName();
    JvmAnnotationType annotationType = (JvmAnnotationType) getTypeProvider()
            .findTypeByName(TestAnnotation.NestedAnnotation.class.getName());
    JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName);
    JvmConstructor constructor = getConstructorFromType(type, TestAnnotation.Annotated.class,
            "Annotated(java.lang.String,java.lang.String,java.lang.String)");
    JvmAnnotationTarget target = constructor.getParameters().get(2);
    assertEquals(1, target.getAnnotations().size());
    JvmAnnotationReference annotationReference = target.getAnnotations().get(0);
    assertSame(annotationType, annotationReference.getAnnotation());
}
项目:xtext-extras    文件:JvmDeclaredTypeImpl.java   
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public Iterable<JvmConstructor> getDeclaredConstructors()
{
    // TODO: implement this method
    // Ensure that you remove @generated or mark it @generated NOT
    throw new UnsupportedOperationException();
}
项目:xtext-extras    文件:JvmDeclaredTypeSignatureHashProvider.java   
protected SignatureHashBuilder appendSignature(JvmConstructor operation) {
    appendVisibility(operation.getVisibility()).appendTypeParameters(operation).append("(");
    for (JvmFormalParameter p : operation.getParameters()) {
        appendType(p.getParameterType()).append(" ");
    }
    append(") ");
    for (JvmTypeReference ex : operation.getExceptions()) {
        appendType(ex).append(" ");
    }
    return this;
}
项目:xtext-extras    文件:XbaseValidator.java   
protected boolean isStaticContext(EObject element) {
    if(element instanceof JvmConstructor)
        return false;
    if(element instanceof JvmFeature)
        return ((JvmFeature) element).isStatic();
    if(element instanceof JvmDeclaredType)
        return ((JvmDeclaredType) element).isStatic() || (
                ((JvmDeclaredType)element).getDeclaringType() == null && !isLocalType(element));
    return false;
}
项目:xtext-extras    文件:AbstractTypeProviderTest.java   
@Test
public void test_nestedInterface_Outer_02() {
    String typeName = NestedInterfaces.class.getName() + "$Outer";
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    List<JvmConstructor> constructors = Lists.newArrayList(type.getDeclaredConstructors());
    assertEquals(0, constructors.size());
    assertEquals(JvmVisibility.DEFAULT, type.getVisibility());
    assertTrue(type.isStatic());
    assertTrue(type.isAbstract());
}
项目:xtext-extras    文件:XbaseValidator.java   
@Check
public void checkConstructorArgumentsAreValid(XFeatureCall featureCall) {
    JvmIdentifiableElement feature = featureCall.getFeature();
    if (feature != null && !feature.eIsProxy() && feature instanceof JvmConstructor) {
        JvmType containerType = EcoreUtil2.getContainerOfType(logicalContainerProvider.getNearestLogicalContainer(featureCall), JvmType.class);
        for(XExpression argument: featureCall.getFeatureCallArguments()) {
            checkIsValidConstructorArgument(argument, containerType);
        }
    }
}