org.eclipse.xtext.common.types.JvmDeclaredType Java Examples
The following examples show how to use
org.eclipse.xtext.common.types.JvmDeclaredType.
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: PyGenerator.java From sarl with Apache License 2.0 | 6 votes |
/** Generate the given object. * * @param behavior the behavior. * @param context the context. */ protected void _generate(SarlBehavior behavior, IExtraLanguageGeneratorContext context) { final JvmDeclaredType jvmType = getJvmModelAssociations().getInferredType(behavior); final PyAppendable appendable = createAppendable(jvmType, context); final List<JvmTypeReference> superTypes; if (behavior.getExtends() != null) { superTypes = Collections.singletonList(behavior.getExtends()); } else { superTypes = Collections.singletonList(getTypeReferences().getTypeForName(Behavior.class, behavior)); } final String qualifiedName = this.qualifiedNameProvider.getFullyQualifiedName(behavior).toString(); if (generateTypeDeclaration( qualifiedName, behavior.getName(), behavior.isAbstract(), superTypes, getTypeBuilder().getDocumentation(behavior), true, behavior.getMembers(), appendable, context, (it, context2) -> { generateGuardEvaluators(qualifiedName, it, context2); })) { final QualifiedName name = getQualifiedNameProvider().getFullyQualifiedName(behavior); writeFile(name, appendable, context); } }
Example #2
Source File: JvmModelGeneratorTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
public String generate(final Resource res, final JvmDeclaredType type) { String _xblockexpression = null; { res.eSetDeliver(false); EList<EObject> _contents = res.getContents(); this.builder.<JvmDeclaredType>operator_add(_contents, type); res.eSetDeliver(true); final InMemoryFileSystemAccess fsa = new InMemoryFileSystemAccess(); this.generator.doGenerate(res, fsa); Map<String, CharSequence> _textFiles = fsa.getTextFiles(); String _replace = type.getIdentifier().replace(".", "/"); String _plus = (IFileSystemAccess.DEFAULT_OUTPUT + _replace); String _plus_1 = (_plus + ".java"); _xblockexpression = _textFiles.get(_plus_1).toString(); } return _xblockexpression; }
Example #3
Source File: AbstractNewSarlElementWizardPage.java From sarl with Apache License 2.0 | 6 votes |
private static void createInfoCall(IExpressionBuilder builder, String message) { final JvmParameterizedTypeReference capacity = builder.newTypeRef(null, LOGGING_CAPACITY_NAME); final String objectType = Object.class.getName(); final String objectArrayType = objectType + "[]"; //$NON-NLS-1$ final JvmOperation infoMethod = Iterables.find( ((JvmDeclaredType) capacity.getType()).getDeclaredOperations(), it -> { if (Objects.equals(it.getSimpleName(), "info") //$NON-NLS-1$ && it.getParameters().size() == 2) { final String type1 = it.getParameters().get(0).getParameterType().getIdentifier(); final String type2 = it.getParameters().get(1).getParameterType().getIdentifier(); return Objects.equals(objectType, type1) && Objects.equals(objectArrayType, type2); } return false; }, null); if (infoMethod != null) { builder.setExpression("info(\"" + message + "\")"); //$NON-NLS-1$ //$NON-NLS-2$ ((XFeatureCall) builder.getXExpression()).setFeature(infoMethod); } }
Example #4
Source File: XtendOutlineSourceTreeBuilder.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
protected void buildDispatchers(final JvmDeclaredType inferredType, final JvmDeclaredType baseType, final IXtendOutlineContext context) { final Function1<JvmOperation, Boolean> _function = (JvmOperation it) -> { return Boolean.valueOf(this.dispatchHelper.isDispatcherFunction(it)); }; Iterable<JvmOperation> _filter = IterableExtensions.<JvmOperation>filter(inferredType.getDeclaredOperations(), _function); for (final JvmOperation dispatcher : _filter) { { final List<JvmOperation> dispatchCases = this.getDispatchCases(dispatcher, baseType, context); final IXtendOutlineContext dispatcherContext = this.xtendOutlineNodeBuilder.buildDispatcherNode(baseType, dispatcher, dispatchCases, context).markAsProcessed(dispatcher); for (final JvmOperation dispatchCase : dispatchCases) { EObject _elvis = null; XtendFunction _xtendFunction = this._iXtendJvmAssociations.getXtendFunction(dispatchCase); if (_xtendFunction != null) { _elvis = _xtendFunction; } else { _elvis = dispatchCase; } this.buildFeature(baseType, dispatchCase, _elvis, dispatcherContext).markAsProcessed(dispatchCase); } } } }
Example #5
Source File: XtendValidator.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
private boolean contributesToConflict(JvmDeclaredType type, Set<JvmDeclaredType> involvedInterfaces, RecursionGuard<JvmDeclaredType> guard) { if (!guard.tryNext(type)) { return false; } if (involvedInterfaces.contains(type)) { return true; } for (JvmTypeReference typeRef : type.getExtendedInterfaces()) { JvmType rawType = typeRef.getType(); if (rawType instanceof JvmDeclaredType && contributesToConflict((JvmDeclaredType) rawType, involvedInterfaces, guard)) { return true; } } return false; }
Example #6
Source File: JvmModelGenerator.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected ITreeAppendable _generateMember(final JvmDeclaredType it, final ITreeAppendable appendable, final GeneratorConfig config) { ITreeAppendable _xblockexpression = null; { appendable.newLine(); appendable.openScope(); this.assignThisAndSuper(appendable, it, config); ITreeAppendable _xtrycatchfinallyexpression = null; try { _xtrycatchfinallyexpression = this.generateBody(it, appendable, config); } finally { appendable.closeScope(); } _xblockexpression = _xtrycatchfinallyexpression; } return _xblockexpression; }
Example #7
Source File: OverrideProposalUtil.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected boolean isCandidate(LightweightTypeReference type, IResolvedExecutable executable, IVisibilityHelper visibilityHelper) { JvmDeclaredType declaringType = executable.getDeclaration().getDeclaringType(); if (type.getType() != declaringType && isVisible(executable, visibilityHelper)) { JvmExecutable rawExecutable = executable.getDeclaration(); if (rawExecutable instanceof JvmOperation) { JvmOperation operation = (JvmOperation) rawExecutable; if (operation.isFinal() || operation.isStatic()) { return false; } else { if (type.getType() instanceof JvmGenericType && ((JvmGenericType) type.getType()).isInterface()) { return declaringType instanceof JvmGenericType && ((JvmGenericType) declaringType).isInterface() && !operation.isAbstract(); } else { return true; } } } else { return true; } } return false; }
Example #8
Source File: MemberFromSuperImplementor.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
protected void initializeExecutableBuilder(final AbstractExecutableBuilder builder, final JvmDeclaredType overrider, final IResolvedExecutable overridden) { final JvmExecutable executable = overridden.getDeclaration(); builder.setContext(overrider); builder.setVisibility(overridden.getDeclaration().getVisibility()); final Procedure2<LightweightTypeReference, Integer> _function = (LightweightTypeReference it, Integer index) -> { final JvmFormalParameter declaredParameter = executable.getParameters().get((index).intValue()); final AbstractParameterBuilder parameterBuilder = builder.newParameterBuilder(); parameterBuilder.setName(declaredParameter.getSimpleName()); parameterBuilder.setType(it); JvmAnnotationReference _findAnnotation = this.annotationLookup.findAnnotation(declaredParameter, Extension.class); boolean _tripleNotEquals = (_findAnnotation != null); parameterBuilder.setExtensionFlag(_tripleNotEquals); }; IterableExtensions.<LightweightTypeReference>forEach(overridden.getResolvedParameterTypes(), _function); builder.setVarArgsFlag(executable.isVarArgs()); builder.setExceptions(overridden.getResolvedExceptions()); }
Example #9
Source File: FeatureCallCompiler.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
private boolean isPotentialJavaOperation(XAbstractFeatureCall featureCall) { if (featureCall.isOperation()) { return true; } if (featureCall.eClass() == XbasePackage.Literals.XMEMBER_FEATURE_CALL && featureCall.isStatic() && featureCall.isExtension() && featureCall.getActualArguments().size() == 2) { JvmIdentifiableElement feature = featureCall.getFeature(); if (feature.eClass() == TypesPackage.Literals.JVM_OPERATION) { JvmDeclaredType declarator = ((JvmOperation) feature).getDeclaringType(); if (IntegerExtensions.class.getName().equals(declarator.getIdentifier()) || LongExtensions.class.getName().equals(declarator.getIdentifier())) { String simpleName = feature.getSimpleName(); if (simpleName.startsWith("bitwise") || simpleName.startsWith("shift")) { return true; } } } } return false; }
Example #10
Source File: SARLJvmGenerator.java From sarl with Apache License 2.0 | 6 votes |
@Override protected void _internalDoGenerate(JvmDeclaredType type, IFileSystemAccess fsa) { if (DisableCodeGenerationAdapter.isDisabled(type)) { return; } final String qn = type.getQualifiedName(); if (!Strings.isEmpty(qn)) { final String fn = qn.replace('.', '/') + ".java"; //$NON-NLS-1$ final CharSequence content = generateType(type, this.generatorConfigProvider.get(type)); final String outputConfigurationName; final Boolean isTest = this.resourceTypeDetector.isTestResource(type.eResource()); if (isTest != null && isTest.booleanValue()) { outputConfigurationName = SARLConfig.TEST_OUTPUT_CONFIGURATION; } else { outputConfigurationName = IFileSystemAccess.DEFAULT_OUTPUT; } fsa.generateFile(fn, outputConfigurationName, content); } }
Example #11
Source File: JavaDerivedStateComputer.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
public void installStubs(Resource resource) { if (isInfoFile(resource)) { return; } CompilationUnit compilationUnit = getCompilationUnit(resource); ProblemReporter problemReporter = new ProblemReporter(DefaultErrorHandlingPolicies.proceedWithAllProblems(), getCompilerOptions(resource), new DefaultProblemFactory()); Parser parser = new Parser(problemReporter, true); CompilationResult compilationResult = new CompilationResult(compilationUnit, 0, 1, -1); CompilationUnitDeclaration result = parser.dietParse(compilationUnit, compilationResult); if (result.types != null) { for (TypeDeclaration type : result.types) { ImportReference currentPackage = result.currentPackage; String packageName = null; if (currentPackage != null) { char[][] importName = currentPackage.getImportName(); if (importName != null) { packageName = CharOperation.toString(importName); } } JvmDeclaredType jvmType = createType(type, packageName); resource.getContents().add(jvmType); } } }
Example #12
Source File: JvmModelGenerator.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected String reassignThisType(final ITreeAppendable b, final JvmDeclaredType declaredType) { String _xblockexpression = null; { boolean _hasObject = b.hasObject("this"); if (_hasObject) { final Object element = b.getObject("this"); if ((element instanceof JvmDeclaredType)) { boolean _isLocal = ((JvmDeclaredType)element).isLocal(); if (_isLocal) { b.declareVariable(element, ""); } else { String _simpleName = ((JvmDeclaredType)element).getSimpleName(); final String proposedName = (_simpleName + ".this"); b.declareVariable(element, proposedName); } } } String _xifexpression = null; if ((declaredType != null)) { _xifexpression = b.declareVariable(declaredType, "this"); } _xblockexpression = _xifexpression; } return _xblockexpression; }
Example #13
Source File: ThrownExceptionSwitch.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
/** * @since 2.18 */ protected JvmOperation findCloseMethod(LightweightTypeReference resourceType) { // Find the real close method, // which is an operation without arguments. // There can only be one real close method. for(JvmType rawType: resourceType.getRawTypes()) { if (rawType instanceof JvmDeclaredType) { Iterable<JvmFeature> candidates = ((JvmDeclaredType) rawType).findAllFeaturesByName("close"); for(JvmFeature candidate: candidates) { if (candidate instanceof JvmOperation && ((JvmOperation) candidate).getParameters().isEmpty()) { return (JvmOperation) candidate; } } } } return null; }
Example #14
Source File: CreateMemberQuickfixes.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
protected void newMethodQuickfixes(LightweightTypeReference containerType, String name, /* @Nullable */ LightweightTypeReference returnType, List<LightweightTypeReference> argumentTypes, XAbstractFeatureCall call, JvmDeclaredType callersType, final Issue issue, final IssueResolutionAcceptor issueResolutionAcceptor) { boolean isLocal = callersType == containerType.getType(); boolean isStatic = isStaticAccess(call); boolean isAbstract = true; if(containerType.getType() instanceof JvmGenericType) { isAbstract = !((JvmGenericType) containerType.getType()).isInstantiateable(); } else if(containerType.getType() instanceof JvmDeclaredType) { isAbstract = ((JvmDeclaredType) containerType.getType()).isAbstract(); } if(containerType.getType() instanceof JvmDeclaredType) { JvmDeclaredType declaredType = (JvmDeclaredType) containerType.getType(); newMethodQuickfix(declaredType, name, returnType, argumentTypes, isStatic, isAbstract, false, isLocal, call, issue, issueResolutionAcceptor); } if(!isLocal && !isStatic) { List<LightweightTypeReference> extensionMethodParameterTypes = newArrayList(argumentTypes); extensionMethodParameterTypes.add(0, containerType); newMethodQuickfix(callersType, name, returnType, extensionMethodParameterTypes, false, isAbstract, true, true, call, issue, issueResolutionAcceptor); } }
Example #15
Source File: LinkingTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testDeclaredConstructor_01() throws Exception { XtendClass clazz = clazz( "class Foo { " + " int i" + " new(int i) { this.i = i }" + "}"); assertEquals(2, clazz.getMembers().size()); XtendConstructor constructor = (XtendConstructor) clazz.getMembers().get(1); XAssignment assignment = (XAssignment) ((XBlockExpression)constructor.getExpression()).getExpressions().get(0); JvmField field = (JvmField) assignment.getFeature(); assertEquals("i", field.getSimpleName()); XFeatureCall target = (XFeatureCall) assignment.getAssignable(); JvmDeclaredType identifiableElement = (JvmDeclaredType) target.getFeature(); assertEquals("Foo", identifiableElement.getSimpleName()); XFeatureCall value = (XFeatureCall) assignment.getValue(); JvmFormalParameter parameter = (JvmFormalParameter) value.getFeature(); assertEquals("i", parameter.getSimpleName()); }
Example #16
Source File: TypeReferenceSerializer.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
public boolean isLocalTypeParameter(EObject context, JvmTypeParameter parameter) { if (context == parameter.getDeclarator()) return true; if (context instanceof JvmOperation && ((JvmOperation) context).isStatic()) return false; if (context instanceof JvmDeclaredType && ((JvmDeclaredType) context).isStatic()) return false; JvmIdentifiableElement jvmElement = contextProvider.getNearestLogicalContainer(context); if (jvmElement != null) { return isLocalTypeParameter(jvmElement, parameter); } EObject container = context.eContainer(); if (container == null) { return false; } return isLocalTypeParameter(container, parameter); }
Example #17
Source File: NonOverridableTypesProvider.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void addInnerTypes( JvmDeclaredType type, String prefix, IVisibilityHelper visibilityHelper, Map<String, JvmIdentifiableElement> result) { for (JvmMember member : type.getMembers()) { if (member instanceof JvmDeclaredType && visibilityHelper.isVisible(member)) { String localName = prefix + member.getSimpleName(); if (!result.containsKey(localName)) { result.put(localName, member); } addInnerTypes((JvmDeclaredType) member, prefix + member.getSimpleName() + ".", visibilityHelper, result); } } }
Example #18
Source File: ReflectionTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override @Test public void testDeprecatedBit_02() { String typeName = DeprecatedMembers.class.getName(); JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName); assertFalse(type.isSetDeprecated()); for(JvmMember member: type.getMembers()) { assertFalse(member.isSetDeprecated()); } }
Example #19
Source File: JvmModelGenerator.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void _internalDoGenerate(final JvmDeclaredType type, final IFileSystemAccess fsa) { boolean _isDisabled = DisableCodeGenerationAdapter.isDisabled(type); if (_isDisabled) { return; } String _qualifiedName = type.getQualifiedName(); boolean _tripleNotEquals = (_qualifiedName != null); if (_tripleNotEquals) { String _replace = type.getQualifiedName().replace(".", "/"); String _plus = (_replace + ".java"); fsa.generateFile(_plus, this.generateType(type, this.generatorConfigProvider.get(type))); } }
Example #20
Source File: JvmDeclaredTypeSignatureHashProvider.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected SignatureHashBuilder appendSuperTypeSignatures(JvmDeclaredType type) { for(JvmTypeReference superType: type.getSuperTypes()) { append("super "); append(superType.getIdentifier()); append("\n"); } return this; }
Example #21
Source File: LogicalContainerAwareReentrantTypeResolver.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void computeMemberTypes(Map<JvmIdentifiableElement, ResolvedTypes> preparedResolvedTypes, ResolvedTypes resolvedTypes, IFeatureScopeSession featureScopeSession, JvmDeclaredType type) { IFeatureScopeSession childSession = addExtensionsToMemberSession(resolvedTypes, featureScopeSession, type); List<JvmMember> members = type.getMembers(); for(int i = 0; i < members.size(); i++) { computeTypes(preparedResolvedTypes, resolvedTypes, childSession, members.get(i)); } }
Example #22
Source File: JavaElementFinder.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public IJavaElement caseJvmDeclaredType(JvmDeclaredType object) { try { String canonicalName = object.getQualifiedName('.'); IType result = javaProject.findType(canonicalName); return result; } catch (JavaModelException e) { return null; } }
Example #23
Source File: XtendJvmModelInferrer.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected void setNameAndAssociate(XtendFile file, XtendTypeDeclaration xtendType, JvmDeclaredType javaType) { javaType.setPackageName(file.getPackage()); javaType.setSimpleName(xtendType.getName()); javaType.setVisibility(JvmVisibility.PUBLIC); setFileHeader(file, javaType); associator.associatePrimary(xtendType, javaType); }
Example #24
Source File: FeatureScopeSessionWithNestedTypes.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public FeatureScopeSessionWithNestedTypes(AbstractFeatureScopeSession parent, JvmDeclaredType type) { super(parent); this.enclosingTypes = Lists.newLinkedList(); enclosingTypes.add(type); enclosingTypes.addAll(parent.getEnclosingTypes()); this.nestedTypeDeclarators = Lists.newLinkedList(); nestedTypeDeclarators.add(type); nestedTypeDeclarators.addAll(parent.getNestedTypeDeclarators()); }
Example #25
Source File: AbstractRewritableImportSectionTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected JvmDeclaredType jvmType(final Class<?> javaClass) { JvmDeclaredType _xblockexpression = null; { final JvmType type = this._typeReferences.findDeclaredType(javaClass, this.xtendFile); Assert.assertTrue((type instanceof JvmDeclaredType)); _xblockexpression = ((JvmDeclaredType) type); } return _xblockexpression; }
Example #26
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@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 #27
Source File: XbaseWithAnnotationsTypeComputer.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
private ITypeComputationState addEnumImportsIfNecessary(ITypeComputationState state, LightweightTypeReference expectedType, JvmType enumTypeCandidate) { ITypeComputationState expectationState = state.withExpectation(expectedType); if (enumTypeCandidate != null && enumTypeCandidate.eClass() == TypesPackage.Literals.JVM_ENUMERATION_TYPE) { expectationState.addImports(new EnumLiteralImporter((JvmDeclaredType) enumTypeCandidate)); } return expectationState; }
Example #28
Source File: ClasspathTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testBug337307() { String typeName = "ClassWithDefaultPackage"; JvmType type = getTypeProvider().findTypeByName(typeName); assertNotNull(type); assertTrue(type instanceof JvmGenericType); assertEquals(typeName, type.getIdentifier()); assertEquals(typeName, type.getQualifiedName()); assertEquals(typeName, type.getSimpleName()); assertNull(((JvmDeclaredType) type).getPackageName()); diagnose(type); Resource resource = type.eResource(); getAndResolveAllFragments(resource); recomputeAndCheckIdentifiers(resource); }
Example #29
Source File: JarReflectionTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testBug470767_02() { LoggingTester.captureLogging(Level.ERROR, ReflectionTypeFactory.class, new Runnable() { @Override public void run() { String typeName = Bug470767.class.getName(); JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName); assertTrue(Iterables.isEmpty(type.getAllNestedTypes())); } }).assertLogEntry("Incomplete nested types for org.eclipse.xtext.common.types.testSetups.Bug470767"); }
Example #30
Source File: LogicalContainerAwareReentrantTypeResolver.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected LocalVariableCapturerImpl( JvmTypeReference equivalent, JvmDeclaredType localClass, LogicalContainerAwareReentrantTypeResolver typeResolver, ResolvedTypes resolvedTypes, Map<JvmIdentifiableElement, ResolvedTypes> resolvedTypesByContext) { super(equivalent); this.localClass = localClass; this.typeResolver = typeResolver; this.resolvedTypes = resolvedTypes; this.resolvedTypesByContext = resolvedTypesByContext; }