protected String getDeclaratorSimpleName(JvmIdentifiableElement element) { if (element instanceof JvmConstructor) { return null; } if (element instanceof JvmMember) { return ((JvmMember) element).getDeclaringType().getSimpleName(); } return null; }
public void addTypeUsage( JvmDeclaredType typeToImport, String suffix, ITextRegion textRegion, JvmMember context) { simpleName2types.put(typeToImport.getSimpleName(), typeToImport); types2usages.put(typeToImport, new TypeUsage(typeToImport, suffix, textRegion, context)); }
@Override public String getSimpleName() { return this.getDelegate().getSimpleName(); }
public boolean hasImportedType(JvmDeclaredType type) { List<JvmDeclaredType> importedTypes = getImportedTypes(type.getSimpleName()); if (importedTypes == null) { return false; } for (JvmDeclaredType importedType : importedTypes) { if (importedType == type) { return true; } } return false; }
protected String getDeclaratorSimpleName(JvmIdentifiableElement element) { if (element instanceof JvmConstructor) { return null; } if (element instanceof JvmMember) { return ((JvmMember) element).getDeclaringType().getSimpleName(); } return null; }
public boolean addImport(JvmDeclaredType type) { if (plainImports.containsKey(type.getSimpleName()) || !needsImport(type)) return false; Maps2.putIntoListMap(type.getSimpleName(), type, plainImports); XImportDeclaration importDeclaration = XtypeFactory.eINSTANCE.createXImportDeclaration(); importDeclaration.setImportedType(type); addedImportDeclarations.add(importDeclaration); return true; }
public ImportManager(boolean organizeImports, JvmDeclaredType thisType, char innerTypeSeparator) { this.organizeImports = organizeImports; this.innerTypeSeparator = innerTypeSeparator; if (thisType != null) { getThisTypeSimpleNames().add(thisType.getSimpleName()); getThisTypeQualifiedNames().add(thisType.getQualifiedName(innerTypeSeparator)); thisCollidesWithJavaLang |= CodeGenUtil2.isJavaLangType(thisType.getSimpleName()); registerSimpleNamesOfInnerClasses(thisType, new LinkedHashSet<JvmType>()); } }
@Override public String caseAggregatedValue(AggregatedValue object) { return String.format("Aggregate %s %s(%s)", object.getAggregator().getSimpleName(), getCallableName(object.getCall()), PatternLanguageHelper.getCallParameters(object.getCall()).stream().map(this::doSwitch).collect(Collectors.joining(", ")) ); }
private JvmDeclaredType findDeclaringTypeBySimpleName(JvmDeclaredType referencedType, String outerSegment) { if (referencedType.getDeclaringType() == null || outerSegment.equals(referencedType.getSimpleName())) { return referencedType; } return findDeclaringTypeBySimpleName(referencedType.getDeclaringType(), outerSegment); }
private JvmDeclaredType findDeclaringTypeBySimpleName(final JvmDeclaredType referencedType, final String outerSegment) { if (((referencedType.getDeclaringType() == null) || outerSegment.equals(referencedType.getSimpleName()))) { return referencedType; } return this.findDeclaringTypeBySimpleName(referencedType.getDeclaringType(), outerSegment); }
protected void checkConflicts(XImportSection importSection, final Map<String, List<XImportDeclaration>> imports, final Map<String, JvmType> importedNames) { for (JvmDeclaredType declaredType : importsConfiguration.getLocallyDefinedTypes((XtextResource)importSection.eResource())) { if(importedNames.containsKey(declaredType.getSimpleName())){ JvmType importedType = importedNames.get(declaredType.getSimpleName()); if (importedType != declaredType && importedType.eResource() != importSection.eResource()) { List<XImportDeclaration> list = imports.get(importedType.getIdentifier()); if (list != null) { for (XImportDeclaration importDeclaration: list ) { error("The import '" + importedType.getIdentifier() + "' conflicts with a type defined in the same file", importDeclaration, null, IssueCodes.IMPORT_CONFLICT); } } } } } }
public void completeJvmConstructor(JvmConstructor constructor) { JvmDeclaredType declaringType = constructor.getDeclaringType(); if(declaringType != null) { String simpleName = declaringType.getSimpleName(); if(simpleName != null) { constructor.setSimpleName(simpleName); return; } } constructor.setSimpleName("unset"); }
protected String getDeclaratorName(JvmFeature feature) { JvmDeclaredType declarator = feature.getDeclaringType(); if (declarator.isLocal()) { return "new " + Iterables.getLast(declarator.getSuperTypes()).getType().getSimpleName()+ "(){}"; } else { return declarator.getSimpleName(); } }
private String getLocalName(JvmDeclaredType type, JvmMember context) { JvmMember containerCandidate = context; while (containerCandidate != null) { if (containerCandidate == type) { return type.getSimpleName(); } else if (EcoreUtil.isAncestor(containerCandidate, type)) { String contextName = containerCandidate.getQualifiedName('.'); String typeName = type.getQualifiedName('.'); return typeName.substring(contextName.length() + 1); } EObject container = containerCandidate.eContainer(); if (container instanceof JvmMember) { containerCandidate = (JvmMember) container; } else { return null; } } return null; }
private String getConcreteSyntax(String name, JvmDeclaredType importedType, TypeUsage usage) { JvmDeclaredType usedType = usage.getUsedType(); if (usedType == null) { String typeName = usage.getUsedTypeName(); String suffix = getSuffix(usage); String fullTypeName = typeName + suffix; return nameValueConverter.toString(fullTypeName); } else { if (usedType != importedType) { List<String> segments = Lists.newLinkedList(); while (usedType != importedType) { segments.add(0, usedType.getSimpleName()); usedType = usedType.getDeclaringType(); } name = name + '.' + Joiner.on('.').join(segments); } else { String suffix = getSuffix(usage); name = name + suffix; } return nameValueConverter.toString(name); } }
protected void registerSimpleNamesOfInnerClasses(JvmDeclaredType thisType, LinkedHashSet<JvmType> handled) { if (!handled.add(thisType)) return; List<JvmDeclaredType> nested = EcoreUtil2.typeSelect(thisType.getMembers(), JvmDeclaredType.class); for (JvmDeclaredType jvmDeclaredType : nested) { getThisTypeSimpleNames().add(jvmDeclaredType.getSimpleName()); getThisTypeQualifiedNames().add(jvmDeclaredType.getQualifiedName(getInnerTypeSeparator())); thisCollidesWithJavaLang |= CodeGenUtil2.isJavaLangType(jvmDeclaredType.getSimpleName()); } for (JvmTypeReference superType: thisType.getSuperTypes()) { if (superType.getType() instanceof JvmDeclaredType) { registerSimpleNamesOfInnerClasses((JvmDeclaredType) superType.getType(), handled); } } }
private void initializeLocalTypes(JvmFeature feature, XExpression expression) { if (expression != null) { TreeIterator<EObject> iterator = EcoreUtil2.getAllNonDerivedContents(expression, true); String nameStub = "__" + feature.getDeclaringType().getSimpleName(); while(iterator.hasNext()) { EObject next = iterator.next(); if (next.eClass() == XtendPackage.Literals.ANONYMOUS_CLASS) { inferLocalClass((AnonymousClass) next, nameStub, feature); iterator.prune(); } } } }
public IScope createTypeScope(EObject context, EReference reference) { if (context.eClass() == TypesPackage.Literals.JVM_INNER_TYPE_REFERENCE) { JvmInnerTypeReference casted = (JvmInnerTypeReference) context; JvmParameterizedTypeReference outerType = casted.getOuter(); JvmType outerRawType = outerType.getType(); if (outerRawType instanceof JvmDeclaredType) { Iterable<JvmDeclaredType> nestedTypes = ((JvmDeclaredType) outerRawType).getAllNestedTypes(); List<IEObjectDescription> descriptions = Lists.newArrayList(); for(JvmDeclaredType nestedType: nestedTypes) { descriptions.add(EObjectDescription.create(nestedType.getSimpleName(), nestedType)); } return new SimpleScope(descriptions); } return IScope.NULLSCOPE; } else { final IScope delegateScope = getDelegate().getScope(context, reference); return delegateScope; } }
/** Initialize the local class to the given expression. * * @param context the generation context. * @param feature the feature which contains the expression. * @param expression the expression which contains the local class. */ protected void initializeLocalTypes(GenerationContext context, JvmFeature feature, XExpression expression) { if (expression != null) { int localTypeIndex = context.getLocalTypeIndex(); final TreeIterator<EObject> iterator = EcoreUtil2.getAllNonDerivedContents(expression, true); final String nameStub = "__" + feature.getDeclaringType().getSimpleName() + "_"; //$NON-NLS-1$ //$NON-NLS-2$ while (iterator.hasNext()) { final EObject next = iterator.next(); if (next.eClass() == XtendPackage.Literals.ANONYMOUS_CLASS) { inferLocalClass((AnonymousClass) next, nameStub + localTypeIndex, feature); iterator.prune(); ++localTypeIndex; } } context.setLocalTypeIndex(localTypeIndex); } }
@Override public boolean validate(IAcceptor<? super AbstractDiagnostic> result) { JvmDeclaredType declaringType = getConstructor().getDeclaringType(); if (declaringType.isAbstract()) { String message = "Cannot instantiate the abstract type " + declaringType.getSimpleName(); AbstractDiagnostic diagnostic = new EObjectDiagnosticImpl( Severity.ERROR, IssueCodes.ABSTRACT_CLASS_INSTANTIATION, message, getExpression(), getDefaultValidationFeature(), -1, null); result.accept(diagnostic); return false; } return super.validate(result); }