use of com.oracle.truffle.api.instrumentation.SourceSectionFilter.SourcePredicate in project graal by oracle.
the class SourcePredicateBuilder method uriOrTruffleName.
/**
* A special method to filter for either the URI of a {@link Source} or via the name. Some
* languages create sources in a way that no URI is set, only the {@link Source}'s name which is
* the path of the source.
*
* @param uri
*/
public SourcePredicateBuilder uriOrTruffleName(URI uri) {
SourcePredicate predicate = src -> src.getURI().equals(uri) || ("truffle".equals(src.getURI().getScheme()) && src.getName() != null && src.getName().equals(uri.getPath()));
this.predicates.add(predicate);
return this;
}
use of com.oracle.truffle.api.instrumentation.SourceSectionFilter.SourcePredicate in project graal by oracle.
the class SourcePredicateBuilder method language.
public SourcePredicateBuilder language(LanguageInfo languageInfo) {
SourcePredicate predicate = src -> languageInfo.getId().equals(src.getLanguage()) || (src.getMimeType() != null && languageInfo.getMimeTypes().contains(src.getMimeType()));
this.predicates.add(predicate);
return this;
}
use of com.oracle.truffle.api.instrumentation.SourceSectionFilter.SourcePredicate in project graal by oracle.
the class SourcePredicateBuilder method excludeInternal.
public SourcePredicateBuilder excludeInternal(OptionValues options) {
boolean includeInternal = options.get(LSPInstrument.Internal);
if (!includeInternal) {
SourcePredicate predicate = src -> !src.isInternal();
this.predicates.add(predicate);
}
return this;
}
use of com.oracle.truffle.api.instrumentation.SourceSectionFilter.SourcePredicate in project graal by oracle.
the class CoverageRequestHandler method runCoverageAnalysisWithEnteredContext.
public Boolean runCoverageAnalysisWithEnteredContext(final URI uri) throws DiagnosticsNotification {
final TextDocumentSurrogate surrogateOfOpenedFile = surrogateMap.get(uri);
if (surrogateOfOpenedFile == null) {
return Boolean.FALSE;
}
TextDocumentSurrogate surrogateOfTestFile = sourceCodeEvaluator.createSurrogateForTestFile(surrogateOfOpenedFile, null);
final URI runScriptUri = surrogateOfTestFile.getUri();
clearRelatedCoverageData(runScriptUri);
try {
final CallTarget callTarget = sourceCodeEvaluator.parse(surrogateOfTestFile);
LanguageInfo languageInfo = surrogateOfTestFile.getLanguageInfo();
SourcePredicate predicate = SourcePredicateBuilder.newBuilder().language(languageInfo).excludeInternal(env.getOptions()).build();
SourceSectionFilter eventFilter = SourceSectionFilter.newBuilder().sourceIs(predicate).build();
EventBinding<ExecutionEventNodeFactory> eventFactoryBinding = env.getInstrumenter().attachExecutionEventFactory(eventFilter, new ExecutionEventNodeFactory() {
private final long creatorThreadId = Thread.currentThread().getId();
@Override
public ExecutionEventNode create(final EventContext eventContext) {
final SourceSection section = eventContext.getInstrumentedSourceSection();
if (section != null && section.isAvailable()) {
final Node instrumentedNode = eventContext.getInstrumentedNode();
Function<URI, TextDocumentSurrogate> func = (sourceUri) -> {
return surrogateMap.getOrCreateSurrogate(sourceUri, () -> instrumentedNode.getRootNode().getLanguageInfo());
};
return new CoverageEventNode(section, instrumentedNode, runScriptUri, func, creatorThreadId);
} else {
return null;
}
}
});
try {
callTarget.call();
} finally {
eventFactoryBinding.dispose();
}
surrogateOfOpenedFile.setCoverageAnalysisDone(true);
return Boolean.TRUE;
} catch (DiagnosticsNotification e) {
throw e;
} catch (Exception e) {
InteropLibrary interopLib = InteropLibrary.getUncached();
if (interopLib.isException(e)) {
SourceSection sourceSection;
try {
sourceSection = interopLib.hasSourceLocation(e) ? interopLib.getSourceLocation(e) : null;
} catch (UnsupportedMessageException um) {
throw CompilerDirectives.shouldNotReachHere(um);
}
URI uriOfErronousSource = sourceSection != null ? sourceSection.getSource().getURI() : null;
if (uriOfErronousSource == null) {
uriOfErronousSource = uri;
}
throw DiagnosticsNotification.create(uriOfErronousSource, Diagnostic.create(SourceUtils.getRangeFrom(e, interopLib), e.getMessage(), DiagnosticSeverity.Error, null, "Coverage analysis", null));
}
throw e;
}
}
Aggregations