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);
}
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;
}
}
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));
}
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);
}
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);
}
Aggregations