org.eclipse.xtext.common.types.JvmConstructor Java Examples

The following examples show how to use org.eclipse.xtext.common.types.JvmConstructor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JvmTypeDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
public MutableConstructorDeclaration addConstructor(final Procedure1<MutableConstructorDeclaration> initializer) {
  this.checkMutable();
  Preconditions.checkArgument((initializer != null), "initializer cannot be null");
  final Function1<JvmConstructor, Boolean> _function = (JvmConstructor it) -> {
    return Boolean.valueOf(this.getCompilationUnit().getTypeExtensions().isSingleSyntheticDefaultConstructor(it));
  };
  final JvmConstructor constructor = IterableExtensions.<JvmConstructor>findFirst(Iterables.<JvmConstructor>filter(this.getDelegate().getMembers(), JvmConstructor.class), _function);
  if ((constructor != null)) {
    EcoreUtil.remove(constructor);
  }
  final JvmConstructor newConstructor = TypesFactory.eINSTANCE.createJvmConstructor();
  newConstructor.setVisibility(JvmVisibility.PUBLIC);
  newConstructor.setSimpleName(this.getSimpleName());
  this.getDelegate().getMembers().add(newConstructor);
  MemberDeclaration _memberDeclaration = this.getCompilationUnit().toMemberDeclaration(newConstructor);
  final MutableConstructorDeclaration mutableConstructorDeclaration = ((MutableConstructorDeclaration) _memberDeclaration);
  initializer.apply(mutableConstructorDeclaration);
  return mutableConstructorDeclaration;
}
 
Example #2
Source File: XtendEObjectAtOffsetHelper.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected EObject resolveCrossReferencedElement(INode node) {
	EObject referencedElement = super.resolveCrossReferencedElement(node);
	EObject referenceOwner = NodeModelUtils.findActualSemanticObjectFor(node);
	if(referenceOwner instanceof XConstructorCall) {
		if (referenceOwner.eContainer() instanceof AnonymousClass) {
			AnonymousClass anon = (AnonymousClass) referenceOwner.eContainer();
			JvmGenericType superType = anonymousClassUtil.getSuperType(anon);
			if(superType != null) {
				if (referencedElement instanceof JvmGenericType)  
					return superType;
				else if(referencedElement instanceof JvmConstructor) {
					if(superType.isInterface())
						return superType;
					JvmConstructor superConstructor = anonymousClassUtil.getSuperTypeConstructor(anon);
					if(superConstructor != null)
						return superConstructor;
				}
			}
		}
	}
	return referencedElement;
}
 
Example #3
Source File: JvmModelCompleter.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
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);
	}
}
 
Example #4
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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);
}
 
Example #5
Source File: RenameStrategyTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testInferredClassRenamed() throws Exception {
	XtendClass fooClass = (XtendClass) testHelper.xtendFile("Foo", "class Foo { }").getXtendTypes().get(0);
	IRenameStrategy renameStrategy = createRenameStrategy(fooClass);
	renameStrategy.applyDeclarationChange("Bar", fooClass.eResource().getResourceSet());
	JvmGenericType inferredType = associations.getInferredType(fooClass);
	JvmConstructor inferredConstructor = associations.getInferredConstructor(fooClass);
	assertEquals("Bar", fooClass.getName());
	assertEquals("Bar", inferredType.getSimpleName());
	assertEquals("Bar", inferredConstructor.getSimpleName());
	renameStrategy.revertDeclarationChange(fooClass.eResource().getResourceSet());
	inferredType = associations.getInferredType(fooClass);
	inferredConstructor = associations.getInferredConstructor(fooClass);
	assertEquals("Foo", fooClass.getName());
	assertEquals("Foo", inferredType.getSimpleName());
	assertEquals("Foo", inferredConstructor.getSimpleName());
}
 
Example #6
Source File: SerializerScopeProvider.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
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;
}
 
Example #7
Source File: AbstractConstructorScope.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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();
}
 
Example #8
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
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;
}
 
Example #9
Source File: SARLValidator.java    From sarl with Apache License 2.0 6 votes vote down vote up
private Collection<ActionParameterTypes> doGetConstructorParameterTypes(Class<?> type, Notifier context) {
	final Collection<ActionParameterTypes> parameters = new ArrayList<>();
	final JvmTypeReference typeReference = this.typeReferences.getTypeForName(type, context);
	final JvmType jvmType = typeReference.getType();
	if (jvmType instanceof JvmDeclaredType) {
		final JvmDeclaredType declaredType = (JvmDeclaredType) jvmType;
		for (final JvmConstructor constructor : declaredType.getDeclaredConstructors()) {
			final ActionParameterTypes types = this.sarlActionSignatures.createParameterTypesFromJvmModel(
					constructor.isVarArgs(), constructor.getParameters());
			if (types != null) {
				parameters.add(types);
			}
		}
	}
	if (parameters.isEmpty()) {
		parameters.add(this.sarlActionSignatures.createParameterTypesForVoid());
	}
	return parameters;
}
 
Example #10
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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);
}
 
Example #11
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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);
}
 
Example #12
Source File: JvmModelGenerator.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
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;
}
 
Example #13
Source File: LogicalContainerAwareReentrantTypeResolver.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
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);
	}
}
 
Example #14
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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");
}
 
Example #15
Source File: JvmModelJdtRenameParticipantContext.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected List<? extends IRenameElementContext> createJdtParticipantXtextSourceContexts(
		JdtRenameParticipant participant, 
		EObject indexedJvmElement) {
	if(operatorMappingUtil.isMappedOperator(indexedJvmElement))
		return Collections.emptyList();
	EObject jvmElement;
	if(indexedJvmElement instanceof JvmConstructor)
		jvmElement = ((JvmConstructor) indexedJvmElement).getDeclaringType();
	else 
		jvmElement = indexedJvmElement;
	EObject renameTargetElement = associations.getPrimarySourceElement(jvmElement);
	if (renameTargetElement != null) {
		return singletonList(new JvmModelJdtRenameParticipantContext(participant,
				EcoreUtil2.getPlatformResourceOrNormalizedURI(renameTargetElement), renameTargetElement.eClass()));
	}
	return super.createJdtParticipantXtextSourceContexts(participant, jvmElement);
}
 
Example #16
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
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());
}
 
Example #17
Source File: SourceBasedJdtTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected JvmConstructor getConstructorFromType(EObject context, Class<?> type, String constructor) {
	JvmConstructor result = super.getConstructorFromType(context, type, constructor);
	if (result != null) {
		IJavaElement found = elementFinder.findElementFor(result);
		assertEquals(IJavaElement.METHOD, found.getElementType());
		assertEquals(result.getSimpleName(), found.getElementName());
		IMethod foundMethod = (IMethod) found;
		assertEquals(result.getParameters().size(), foundMethod.getNumberOfParameters());
	}
	return result;
}
 
Example #18
Source File: ConstructorDelegateScope.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected List<IEObjectDescription> createConstructorDescriptions(QualifiedName name, JvmGenericType type, boolean superType) {
	Iterable<JvmConstructor> constructors = type.getDeclaredConstructors();
	List<IEObjectDescription> result = Lists.newArrayListWithCapacity(3);
	for(JvmConstructor constructor: constructors) {
		addToList(createDescription(name, constructor, superType), result);
	}
	return result;
}
 
Example #19
Source File: AbstractExpressionGenerator.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Compute the simple name for the called feature.
 *
 * @param featureCall the feature call.
 * @param logicalContainerProvider the provider of logicial container.
 * @param featureNameProvider the provider of feature name.
 * @param nullKeyword the null-equivalent keyword.
 * @param thisKeyword the this-equivalent keyword.
 * @param superKeyword the super-equivalent keyword.
 * @param referenceNameLambda replies the reference name or {@code null} if none.
 * @return the simple name.
 */
public static String getCallSimpleName(XAbstractFeatureCall featureCall,
		ILogicalContainerProvider logicalContainerProvider,
		IdentifiableSimpleNameProvider featureNameProvider,
		Function0<? extends String> nullKeyword,
		Function0<? extends String> thisKeyword,
		Function0<? extends String> superKeyword,
		Function1<? super JvmIdentifiableElement, ? extends String> referenceNameLambda) {
	String name = null;
	final JvmIdentifiableElement calledFeature = featureCall.getFeature();
	if (calledFeature instanceof JvmConstructor) {
		final JvmDeclaredType constructorContainer = ((JvmConstructor) calledFeature).getDeclaringType();
		final JvmIdentifiableElement logicalContainer = logicalContainerProvider.getNearestLogicalContainer(featureCall);
		final JvmDeclaredType contextType = ((JvmMember) logicalContainer).getDeclaringType();
		if (contextType == constructorContainer) {
			name = thisKeyword.apply();
		} else {
			name = superKeyword.apply();
		}
	} else if (calledFeature != null) {
		final String referenceName = referenceNameLambda.apply(calledFeature);
		if (referenceName != null) {
			name = referenceName;
		} else if (calledFeature instanceof JvmOperation) {
			name = featureNameProvider.getSimpleName(calledFeature);
		} else {
			name = featureCall.getConcreteSyntaxFeatureName();
		}
	}
	if (name == null) {
		return nullKeyword.apply();
	}
	return name;
}
 
Example #20
Source File: SerializerScopeProvider.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public IScope createConstructorCallSerializationScope(EObject context) {
	if (!(context instanceof XConstructorCall)) {
		return IScope.NULLSCOPE;
	}
	XConstructorCall constructorCall = (XConstructorCall) context;
	JvmConstructor constructor = constructorCall.getConstructor();
	if (constructor.eIsProxy()) {
		return IScope.NULLSCOPE;
	}
	return doCreateConstructorCallSerializationScope(constructorCall);
}
 
Example #21
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@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());
}
 
Example #22
Source File: JdtRefactoringContextFactory.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public IRenameElementContext createExternalRenameElementContext(EObject targetElement, XtextEditor editor,
		ITextSelection selection, XtextResource resource) {
	if (isJvmMember(targetElement) && isTypeResource(targetElement)) {
		IJavaElement javaElement;
		if(targetElement instanceof JvmConstructor)
			javaElement = getJavaElementFinder().findExactElementFor(((JvmConstructor) targetElement).getDeclaringType());
		else 
			javaElement = getJavaElementFinder().findExactElementFor((JvmMember) targetElement);
		if (javaElement != null)
			return new JdtRefactoringContext(targetElement, javaElement, editor,
					selection, resource, true);
	}
	return super.createExternalRenameElementContext(targetElement, editor, selection, resource);
}
 
Example #23
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@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);
}
 
Example #24
Source File: MutableJvmFieldDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void markAsInitializedBy(final ConstructorDeclaration constructorDeclaration) {
  this.checkMutable();
  JvmConstructor _switchResult = null;
  boolean _matched = false;
  if (constructorDeclaration instanceof JvmConstructorDeclarationImpl) {
    _matched=true;
    _switchResult = ((JvmConstructorDeclarationImpl)constructorDeclaration).getDelegate();
  }
  if (!_matched) {
    if (constructorDeclaration instanceof XtendConstructorDeclarationImpl) {
      _matched=true;
      JvmConstructor _xblockexpression = null;
      {
        final EObject jvmElement = this.getCompilationUnit().getJvmModelAssociations().getPrimaryJvmElement(((XtendConstructorDeclarationImpl)constructorDeclaration).getDelegate());
        JvmConstructor _xifexpression = null;
        if ((jvmElement instanceof JvmConstructor)) {
          _xifexpression = ((JvmConstructor)jvmElement);
        }
        _xblockexpression = _xifexpression;
      }
      _switchResult = _xblockexpression;
    }
  }
  final JvmConstructor constructor = _switchResult;
  this.getCompilationUnit().getReadAndWriteTracking().markInitialized(this.getDelegate(), constructor);
}
 
Example #25
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@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);
}
 
Example #26
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@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());
}
 
Example #27
Source File: AbstractConstructorScopeTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testGetElementsByInstance_04() {
	QualifiedName qualifiedName = QualifiedName.create("java", "util", "Hashtable", "Entry");
	IEObjectDescription hashMapEntry = getConstructorScope().getSingleElement(qualifiedName);
	JvmConstructor constructor = (JvmConstructor) hashMapEntry.getEObjectOrProxy();
	Iterable<IEObjectDescription> descriptions = getConstructorScope().getElements(constructor);
	List<IEObjectDescription> list = Lists.newArrayList(descriptions);
	assertEquals(2, list.size());
	assertEquals(qualifiedName, list.get(0).getName());
	QualifiedName qualifiedNameWithDollar = QualifiedName.create("java", "util", "Hashtable$Entry");
	assertEquals(qualifiedNameWithDollar, list.get(1).getName());
}
 
Example #28
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@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());
}
 
Example #29
Source File: FeatureCallCompiler.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void _toJavaStatement(final XFeatureCall expr, final ITreeAppendable b, boolean isReferenced) {
	// if it's a call to this() or super() make sure the arguments are forced to be compiled to expressions.
	if (expr.getFeature() instanceof JvmConstructor) {
		b.newLine();
		featureCalltoJavaExpression(expr, b, false);
		b.append(";");
	} else {
		_toJavaStatement((XAbstractFeatureCall) expr, b, isReferenced);
	}
}
 
Example #30
Source File: LogicalContainerAwareReentrantTypeResolver.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void computeTypes(ResolvedTypes resolvedTypes, IFeatureScopeSession featureScopeSession, EObject element) {
	if (element instanceof JvmConstructor) {
		throw new IllegalStateException();
	} else if (element instanceof JvmField) {
		throw new IllegalStateException();
	} else if (element instanceof JvmOperation) {
		throw new IllegalStateException();
	} else if (element instanceof JvmDeclaredType) {
		throw new IllegalStateException();
	} else {
		super.computeTypes(resolvedTypes, featureScopeSession, element);
	}
}