use of nl.ramsolutions.sw.magik.analysis.helpers.PackageNodeHelper in project magik-tools by StevenLooman.
the class NewDocTypeExistsTypeCheck method walkPostProcedureInvocation.
@Override
protected void walkPostProcedureInvocation(final AstNode node) {
if (!DefSlottedExemplarParser.isDefSlottedExemplar(node)) {
return;
}
final ITypeKeeper typeKeeper = this.getTypeKeeper();
final TypeParser typeParser = new TypeParser(typeKeeper);
// Get slot defintions.
final AstNode statementNode = node.getFirstAncestor(MagikGrammar.STATEMENT);
final NewDocParser newDocParser = new NewDocParser(statementNode);
final Map<AstNode, String> slotTypeNodes = newDocParser.getSlotTypeNodes();
final PackageNodeHelper helper = new PackageNodeHelper(node);
final String currentPakkage = helper.getCurrentPackage();
// Test slot types.
slotTypeNodes.entrySet().stream().filter(entry -> {
final AbstractType type = typeParser.parseTypeString(entry.getValue(), currentPakkage);
return type == UndefinedType.INSTANCE;
}).forEach(entry -> {
final AstNode typeNode = entry.getKey();
final String typeName = entry.getValue();
final String message = String.format(MESSAGE, typeName);
this.addIssue(typeNode, message);
});
}
use of nl.ramsolutions.sw.magik.analysis.helpers.PackageNodeHelper in project magik-tools by StevenLooman.
the class MethodReturnMatchesDocTypedCheck method extractMethodDocResult.
private ExpressionResult extractMethodDocResult(final AstNode node) {
final PackageNodeHelper packageHelper = new PackageNodeHelper(node);
final String currentPakkage = packageHelper.getCurrentPackage();
final NewDocParser docParser = new NewDocParser(node);
final ITypeKeeper typeKeeper = this.getTypeKeeper();
final TypeParser typeParser = new TypeParser(typeKeeper);
final List<AbstractType> docReturnTypes = docParser.getReturnTypes().stream().map(typeStr -> typeParser.parseTypeString(typeStr, currentPakkage)).collect(Collectors.toList());
return new ExpressionResult(docReturnTypes);
}
use of nl.ramsolutions.sw.magik.analysis.helpers.PackageNodeHelper in project magik-tools by StevenLooman.
the class NewDocTypeExistsTypeCheck method checkMethodProcedureDefinition.
private void checkMethodProcedureDefinition(final AstNode node) {
final NewDocParser newDocParser = new NewDocParser(node);
final PackageNodeHelper packageNodeHelper = new PackageNodeHelper(node);
final String pakkage = packageNodeHelper.getCurrentPackage();
this.checkDefinitionParameters(newDocParser, pakkage);
this.checkDefinitionLoops(newDocParser, pakkage);
this.checkDefinitionReturns(newDocParser, pakkage);
}
use of nl.ramsolutions.sw.magik.analysis.helpers.PackageNodeHelper in project magik-tools by StevenLooman.
the class LocalTypeReasoner method walkPostParameter.
@Override
protected void walkPostParameter(final AstNode node) {
final AstNode identifierNode = node.getFirstChild(MagikGrammar.IDENTIFIER);
final String identifier = identifierNode.getTokenValue();
// Parse method/proc docs and extract parameter type.
final AstNode definitionNode = node.getFirstAncestor(MagikGrammar.METHOD_DEFINITION, MagikGrammar.PROCEDURE_DEFINITION);
final NewDocParser docParser = new NewDocParser(definitionNode);
final Map<String, String> parameterTypes = docParser.getParameterTypes();
final String parameterTypeStr = parameterTypes.get(identifier);
final ExpressionResult result;
final ParameterNodeHelper helper = new ParameterNodeHelper(node);
if (helper.isGatherParameter()) {
final AbstractType simpleVectorType = this.typeKeeper.getType(SW_SIMPLE_VECTOR);
result = new ExpressionResult(simpleVectorType);
} else if (parameterTypeStr != null && !parameterTypeStr.isBlank()) {
final PackageNodeHelper packageHelper = new PackageNodeHelper(node);
final String pakkage = packageHelper.getCurrentPackage();
final AbstractType type = this.typeParser.parseTypeString(parameterTypeStr, pakkage);
if (helper.isOptionalParameter()) {
final AbstractType unsetType = this.typeKeeper.getType(SW_UNSET);
final AbstractType optionalType = new CombinedType(type, unsetType);
result = new ExpressionResult(optionalType);
} else {
result = new ExpressionResult(type);
}
} else {
result = ExpressionResult.UNDEFINED;
}
this.setNodeType(node, result);
final Scope scope = this.globalScope.getScopeForNode(node);
Objects.requireNonNull(scope);
final ScopeEntry scopeEntry = scope.getScopeEntry(identifier);
this.currentScopeEntryNodes.put(scopeEntry, node);
}
use of nl.ramsolutions.sw.magik.analysis.helpers.PackageNodeHelper in project magik-tools by StevenLooman.
the class MagikIndexer method fillType.
private void fillType(final MagikType magikType, final MagikFile magikFile, final AstNode node, final String packageName, final Map<String, String> slots, final List<String> parents, @Nullable final AbstractType defaultParentType) {
// Set location.
final URI uri = magikFile.getUri();
final Location location = new Location(uri, node);
magikType.setLocation(location);
// Set slots.
magikType.clearSlots();
slots.entrySet().forEach(entry -> {
final String slotName = entry.getKey();
final String slotTypeName = entry.getValue();
final AbstractType slotType = this.typeParser.parseTypeString(slotTypeName, packageName);
final Slot slot = magikType.addSlot(null, slotName);
slot.setType(slotType);
});
// Parents.
magikType.clearParents();
final PackageNodeHelper packageHelper = new PackageNodeHelper(node);
final String pakkageName = packageHelper.getCurrentPackage();
parents.stream().forEach(parent -> {
final GlobalReference parentGlobalRef = parent.indexOf(':') != -1 ? GlobalReference.of(parent) : GlobalReference.of(pakkageName, parent);
final AbstractType parentType = this.typeKeeper.getType(parentGlobalRef);
if (parentType == UndefinedType.INSTANCE) {
LOGGER.warn("Parent type not found: {} from package: {}", parent, pakkageName);
} else {
magikType.addParent(parentType);
}
});
// Default parent types ()
boolean parentNonIntrinsicType = magikType.getParents().stream().anyMatch(parentType -> parentType instanceof SlottedType || parentType instanceof IndexedType);
if (defaultParentType != null && !parentNonIntrinsicType) {
magikType.addParent(defaultParentType);
}
// Type doc.
final String typeDoc = MagikCommentExtractor.extractDocComments(node).map(Token::getValue).map(// Strip '##'
line -> line.substring(2)).collect(Collectors.joining("\n"));
magikType.setDoc(typeDoc);
}
Aggregations