Search in sources :

Example 1 with Position

use of nl.ramsolutions.sw.magik.analysis.Position in project magik-tools by StevenLooman.

the class MagikCheck method addIssue.

/**
 * Add a new issue.
 * @param startLine Start line of issue.
 * @param startColumn Start column of issue.
 * @param endLine End line of issue.
 * @param endColumn End column of issue.
 * @param message Message of issue.
 */
public void addIssue(final int startLine, final int startColumn, final int endLine, final int endColumn, final String message) {
    final URI uri = this.getMagikFile().getUri();
    final Position startPosition = new Position(startLine, startColumn);
    final Position endPosition = new Position(endLine, endColumn);
    final Range range = new Range(startPosition, endPosition);
    final Location location = new Location(uri, range);
    this.addIssue(location, message);
}
Also used : Position(nl.ramsolutions.sw.magik.analysis.Position) Range(nl.ramsolutions.sw.magik.analysis.Range) URI(java.net.URI) Location(nl.ramsolutions.sw.magik.analysis.Location)

Example 2 with Position

use of nl.ramsolutions.sw.magik.analysis.Position in project magik-tools by StevenLooman.

the class LineLengthCheck method walkPreMagik.

@Override
protected void walkPreMagik(final AstNode node) {
    final MagikFile magikFile = this.getMagikFile();
    String[] lines = magikFile.getSourceLines();
    if (lines == null) {
        lines = new String[] {};
    }
    int lineNo = 1;
    for (final String line : lines) {
        final AtomicInteger columnNo = new AtomicInteger(0);
        final AtomicInteger issueColumnNo = new AtomicInteger(0);
        line.chars().forEachOrdered(chr -> {
            final int cur;
            if (chr == '\t') {
                cur = columnNo.addAndGet(TAB_WIDTH);
            } else {
                cur = columnNo.incrementAndGet();
            }
            if (cur <= this.maxLineLength + 1) {
                issueColumnNo.incrementAndGet();
            }
        });
        if (columnNo.get() > this.maxLineLength) {
            final URI uri = this.getMagikFile().getUri();
            final Position startPosition = new Position(lineNo, issueColumnNo.get() - 1);
            final Position endPosition = new Position(lineNo, line.length());
            final Range range = new Range(startPosition, endPosition);
            final Location location = new Location(uri, range);
            final String message = String.format(MESSAGE, line.length(), this.maxLineLength);
            this.addIssue(location, message);
        }
        ++lineNo;
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Position(nl.ramsolutions.sw.magik.analysis.Position) MagikFile(nl.ramsolutions.sw.magik.MagikFile) Range(nl.ramsolutions.sw.magik.analysis.Range) URI(java.net.URI) Location(nl.ramsolutions.sw.magik.analysis.Location)

Example 3 with Position

use of nl.ramsolutions.sw.magik.analysis.Position in project magik-tools by StevenLooman.

the class ImplementationProviderTest method testProvideImplementation.

@Test
void testProvideImplementation() {
    final ITypeKeeper typeKeeper = new TypeKeeper();
    final MagikType integerType = (MagikType) typeKeeper.getType(GlobalReference.of("sw:integer"));
    integerType.addMethod(EnumSet.noneOf(Method.Modifier.class), EMPTY_LOCATION, "implementation()", Collections.emptyList(), null, ExpressionResult.UNDEFINED);
    final URI uri = URI.create("tests://unittest");
    final String code = "" + "_method object.b\n" + "    1.implementation()\n" + "_endmethod";
    final MagikTypedFile magikFile = new MagikTypedFile(uri, code, typeKeeper);
    final org.eclipse.lsp4j.Position position = new org.eclipse.lsp4j.Position(1, 10);
    final ImplementationProvider provider = new ImplementationProvider();
    final List<org.eclipse.lsp4j.Location> implementations = provider.provideImplementations(magikFile, position);
    assertThat(implementations).containsOnly(Lsp4jConversion.locationToLsp4j(EMPTY_LOCATION));
}
Also used : Position(nl.ramsolutions.sw.magik.analysis.Position) TypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.TypeKeeper) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) URI(java.net.URI) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) MagikType(nl.ramsolutions.sw.magik.analysis.typing.types.MagikType) ImplementationProvider(nl.ramsolutions.sw.magik.languageserver.implementation.ImplementationProvider) MagikTypedFile(nl.ramsolutions.sw.magik.MagikTypedFile) Location(nl.ramsolutions.sw.magik.analysis.Location) Test(org.junit.jupiter.api.Test)

Example 4 with Position

use of nl.ramsolutions.sw.magik.analysis.Position in project magik-tools by StevenLooman.

the class ReferencesProviderTest method testProvideMethodReferenceFromMethodDefintion.

@Test
void testProvideMethodReferenceFromMethodDefintion() {
    final ITypeKeeper typeKeeper = new TypeKeeper();
    final MagikType integerType = (MagikType) typeKeeper.getType(GlobalReference.of("sw:integer"));
    final Method referingMethod = integerType.addMethod(EnumSet.noneOf(Method.Modifier.class), EMPTY_LOCATION, "refering", Collections.emptyList(), null, ExpressionResult.UNDEFINED);
    referingMethod.addCalledMethod("refering");
    final String code = "" + "_method integer.refering\n" + "    _self.refering\n" + "_endmethod\n";
    // On refering
    final org.eclipse.lsp4j.Position position = new org.eclipse.lsp4j.Position(0, 20);
    final List<org.eclipse.lsp4j.Location> references = this.getReferences(code, position, typeKeeper);
    assertThat(references).hasSize(1);
}
Also used : Position(nl.ramsolutions.sw.magik.analysis.Position) TypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.TypeKeeper) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) Method(nl.ramsolutions.sw.magik.analysis.typing.types.Method) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) MagikType(nl.ramsolutions.sw.magik.analysis.typing.types.MagikType) Location(nl.ramsolutions.sw.magik.analysis.Location) Test(org.junit.jupiter.api.Test)

Example 5 with Position

use of nl.ramsolutions.sw.magik.analysis.Position in project magik-tools by StevenLooman.

the class ReferencesProviderTest method testProvideTypeReferenceFromAtom.

@Test
void testProvideTypeReferenceFromAtom() {
    final ITypeKeeper typeKeeper = new TypeKeeper();
    final MagikType integerType = (MagikType) typeKeeper.getType(GlobalReference.of("sw:integer"));
    final Method referingMethod = integerType.addMethod(EnumSet.noneOf(Method.Modifier.class), EMPTY_LOCATION, "refering", Collections.emptyList(), null, ExpressionResult.UNDEFINED);
    referingMethod.addUsedType("sw:integer");
    final String code = "" + "_method integer.refering\n" + "    integer\n" + "_endmethod\n";
    // On integer.
    final org.eclipse.lsp4j.Position position = new org.eclipse.lsp4j.Position(1, 4);
    final List<org.eclipse.lsp4j.Location> references = this.getReferences(code, position, typeKeeper);
    assertThat(references).hasSize(1);
}
Also used : Position(nl.ramsolutions.sw.magik.analysis.Position) TypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.TypeKeeper) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) Method(nl.ramsolutions.sw.magik.analysis.typing.types.Method) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) MagikType(nl.ramsolutions.sw.magik.analysis.typing.types.MagikType) Location(nl.ramsolutions.sw.magik.analysis.Location) Test(org.junit.jupiter.api.Test)

Aggregations

Position (nl.ramsolutions.sw.magik.analysis.Position)8 Location (nl.ramsolutions.sw.magik.analysis.Location)7 ITypeKeeper (nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper)5 TypeKeeper (nl.ramsolutions.sw.magik.analysis.typing.TypeKeeper)5 MagikType (nl.ramsolutions.sw.magik.analysis.typing.types.MagikType)5 Test (org.junit.jupiter.api.Test)5 Method (nl.ramsolutions.sw.magik.analysis.typing.types.Method)4 URI (java.net.URI)3 Range (nl.ramsolutions.sw.magik.analysis.Range)2 AstNode (com.sonar.sslr.api.AstNode)1 Path (java.nio.file.Path)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 MagikFile (nl.ramsolutions.sw.magik.MagikFile)1 MagikTypedFile (nl.ramsolutions.sw.magik.MagikTypedFile)1 ImplementationProvider (nl.ramsolutions.sw.magik.languageserver.implementation.ImplementationProvider)1 MagikParser (nl.ramsolutions.sw.magik.parser.MagikParser)1