本文整理汇总了Java中org.metaborg.core.context.IContext类的典型用法代码示例。如果您正苦于以下问题:Java IContext类的具体用法?Java IContext怎么用?Java IContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IContext类属于org.metaborg.core.context包,在下文中一共展示了IContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doAnnotate
import org.metaborg.core.context.IContext; //导入依赖的package包/类
@Nullable
@Override
public ISpoofaxAnalyzeUnit doAnnotate(final MetaborgSourceAnnotationInfo info) {
this.logger.debug("Requesting analysis result for file: {}", info.resource());
@Nullable ISpoofaxAnalyzeUnit analysisResult = null;
try {
final IContext context = info.context();
final ISpoofaxInputUnit input =
unitSerivce.inputUnit(info.resource(), info.text(), context.language(), null);
analysisResult = this.analysisResultProcessor.request(input, context).toBlocking().single();
} catch(final RuntimeException ex) {
// FIXME: Dedicated exception!
if(ex.getCause() instanceof AnalysisException
&& ex.getCause().getMessage().equals("No analysis results.")) {
this.logger.info("No analysis results for file: {}", info.resource());
} else {
this.logger.error("Runtime exception while annotating file: {}", ex, info.resource());
}
}
this.logger.info("Requested analysis result for file: {}", info.resource());
return analysisResult;
}
示例2: invoke
import org.metaborg.core.context.IContext; //导入依赖的package包/类
@Override
public IStrategoTerm invoke(Context context, IStrategoTerm current) {
if (!(current instanceof IStrategoString)) {
return null;
}
final IContext mbContext = (IContext) context.contextObject();
final Injector injector = mbContext.injector();
final IResourceService resources = injector.getInstance(IResourceService.class);
final FileObject fileObj = resources.resolve(Tools.asJavaString(current));
try {
fileObj.setExecutable(true, false);
} catch (FileSystemException e1) {
return null;
}
return current;
}
示例3: analyzeAll
import org.metaborg.core.context.IContext; //导入依赖的package包/类
@Override public ISpoofaxAnalyzeResults analyzeAll(Iterable<ISpoofaxParseUnit> inputs, IContext context,
IProgress progress, ICancel cancel) throws AnalysisException, InterruptedException {
cancel.throwIfCancelled();
final ILanguageImpl langImpl = context.language();
final ITermFactory termFactory = termFactoryService.getGeneric();
final FacetContribution<AnalysisFacet> facetContribution = langImpl.facetContribution(AnalysisFacet.class);
if(facetContribution == null) {
logger.debug("No analysis required for {}", langImpl);
return new SpoofaxAnalyzeResults(context);
}
final AnalysisFacet facet = facetContribution.facet;
cancel.throwIfCancelled();
final HybridInterpreter runtime;
try {
runtime = runtimeService.runtime(facetContribution.contributor, context, false);
} catch(MetaborgException e) {
throw new AnalysisException(context, "Failed to get Stratego runtime", e);
}
cancel.throwIfCancelled();
return analyzeAll(inputs, context, runtime, facet.strategyName, termFactory);
}
示例4: call
import org.metaborg.core.context.IContext; //导入依赖的package包/类
@Override protected IStrategoTerm call(IStrategoTerm current, Strategy[] svars, IStrategoTerm[] tvars,
ITermFactory factory, IContext context) throws MetaborgException, IOException {
if(!Tools.isTermString(tvars[0])) {
return null;
}
final IProject project = projectService.get(context.location());
if(project == null) {
return factory.makeList();
}
// GTODO: require language identifier instead of language name
final String languageName = Tools.asJavaString(tvars[0]);
final Iterable<FileObject> includeLocations = languagePathService.includePaths(project, languageName);
final List<IStrategoTerm> terms = Lists.newArrayList();
for(FileObject includeLocation : includeLocations) {
terms.add(factory.makeString(includeLocation.getName().getURI()));
}
return factory.makeList(terms);
}
示例5: call
import org.metaborg.core.context.IContext; //导入依赖的package包/类
@Override protected IStrategoTerm call(IStrategoTerm current, Strategy[] svars, IStrategoTerm[] tvars,
ITermFactory factory, IContext context) {
if(!Tools.isTermString(tvars[0])) {
return null;
}
final IProject project = projectService.get(context.location());
if(project == null) {
return factory.makeList();
}
// GTODO: require language identifier instead of language name
final String languageName = Tools.asJavaString(tvars[0]);
final Iterable<FileObject> sourceLocations = languagePathService.sourcePaths(project, languageName);
final List<IStrategoTerm> terms = Lists.newArrayList();
for(FileObject sourceLocation : sourceLocations) {
terms.add(factory.makeString(sourceLocation.getName().getURI()));
}
return factory.makeList(terms);
}
示例6: collectInformation
import org.metaborg.core.context.IContext; //导入依赖的package包/类
@Override public @Nullable
MetaborgSourceAnnotationInfo collectInformation(final PsiFile file, final Editor editor,
final boolean hasErrors) {
this.logger.debug("Collecting annotation information for file: {}", file);
final MetaborgSourceAnnotationInfo info;
@Nullable final IProject project = this.projectService.get(file);
if(project == null) {
this.logger.warn("Cannot annotate source code; cannot get language specification for resource {}. "
+ "Is the file excluded?", MoreObjects.firstNonNull(file.getVirtualFile(), "<unknown>"));
return null;
}
try {
@Nullable final FileObject resource = this.resourceService.resolve(file);
@Nullable final ILanguageImpl language = this.identifierService.identify(resource, project);
if(language == null) {
this.logger.warn("Skipping annotation. Could not identify the language of resource: {}", resource);
return null;
}
final IContext context = this.contextService.get(resource, project, language);
final String text = editor.getDocument().getImmutableCharSequence().toString();
info = new MetaborgSourceAnnotationInfo(resource, text, context);
} catch(final ContextException e) {
throw LoggerUtils2.exception(this.logger, UnhandledException.class, "Unexpected unhandled exception.", e);
}
this.logger.info("Collected annotation information for file: {}", file);
return info;
}
示例7: call
import org.metaborg.core.context.IContext; //导入依赖的package包/类
@Override protected IStrategoTerm call(IStrategoTerm current, Strategy[] svars, IStrategoTerm[] tvars,
ITermFactory factory, IContext context) throws MetaborgException {
final FileObject location = context.location();
final IProject project = projectService.get(location);
if(project == null) {
return null;
}
if(languageSpecServiceProvider == null) {
// Indicates that meta-Spoofax is not available (ISpoofaxLanguageSpecService cannot be injected), but this
// should never happen because this primitive is inside meta-Spoofax. Check for null just in case.
logger.error("Language specification service is not available; static injection failed");
return null;
}
final ISpoofaxLanguageSpecService languageSpecService = languageSpecServiceProvider.get();
if(!languageSpecService.available(project)) {
return null;
}
final ISpoofaxLanguageSpec languageSpec;
try {
languageSpec = languageSpecService.get(project);
} catch(ConfigException e) {
throw new MetaborgException("Unable to get language specification name for " + location, e);
}
if(languageSpec == null) {
return null;
}
return factory.makeString(languageSpec.config().prettyPrintLanguage());
}
示例8: result
import org.metaborg.core.context.IContext; //导入依赖的package包/类
private ISpoofaxAnalyzeUnit result(String error, ISpoofaxParseUnit input, IContext context, Throwable e,
long duration) {
final FileObject source = input.source();
final IMessage message = MessageFactory.newAnalysisErrorAtTop(source, error, e);
return unitService.analyzeUnit(input,
new AnalyzeContrib(false, false, true, null, Iterables2.singleton(message), duration), context);
}
示例9: call
import org.metaborg.core.context.IContext; //导入依赖的package包/类
@Override protected IStrategoTerm call(IStrategoTerm current, Strategy[] svars, IStrategoTerm[] tvars,
ITermFactory factory, IContext context) throws MetaborgException {
final IProject project = context.project();
if(project == null) {
return null;
}
if(languageSpecServiceProvider == null) {
// Indicates that meta-Spoofax is not available (ISpoofaxLanguageSpecService cannot be injected), but this
// should never happen because this primitive is inside meta-Spoofax. Check for null just in case.
logger.error("Language specification service is not available; static injection failed");
return null;
}
final ISpoofaxLanguageSpecService languageSpecService = languageSpecServiceProvider.get();
if(!languageSpecService.available(project)) {
return null;
}
final ISpoofaxLanguageSpec languageSpec;
try {
languageSpec = languageSpecService.get(project);
} catch(ConfigException e) {
throw new MetaborgException("Unable to get language specification configuration for " + project, e);
}
if(languageSpec == null) {
return null;
}
final IStrategoString nameTerm = factory.makeString(languageSpec.config().name());
final LanguageIdentifier id = languageSpec.config().identifier();
final IStrategoString groupIdTerm = factory.makeString(id.groupId);
final IStrategoString idTerm = factory.makeString(id.id);
final IStrategoString versionTerm = factory.makeString(id.version.toString());
final IStrategoString locationTerm = factory.makeString(languageSpec.location().getName().getURI());
return factory.makeTuple(nameTerm, groupIdTerm, idTerm, versionTerm, locationTerm);
}
示例10: analyze
import org.metaborg.core.context.IContext; //导入依赖的package包/类
@Override public ISpoofaxAnalyzeResult analyze(ISpoofaxParseUnit input, IContext context, IProgress progress,
ICancel cancel) throws AnalysisException, InterruptedException {
cancel.throwIfCancelled();
if(!input.valid()) {
final String message = logger.format("Parse input for {} is invalid, cannot analyze", input.source());
throw new AnalysisException(context, message);
}
final ILanguageImpl language = context.language();
final ITermFactory termFactory = termFactoryService.getGeneric();
final FacetContribution<AnalysisFacet> facetContribution = language.facetContribution(AnalysisFacet.class);
if(facetContribution == null) {
logger.debug("No analysis required for {}", language);
final ISpoofaxAnalyzeUnit emptyUnit = unitService.emptyAnalyzeUnit(input, context);
return new SpoofaxAnalyzeResult(emptyUnit, context);
}
final AnalysisFacet facet = facetContribution.facet;
cancel.throwIfCancelled();
final HybridInterpreter runtime;
try {
runtime = runtimeService.runtime(facetContribution.contributor, context, true);
} catch(MetaborgException e) {
throw new AnalysisException(context, "Failed to get Stratego runtime", e);
}
cancel.throwIfCancelled();
final ISpoofaxAnalyzeUnit result = analyze(input, context, runtime, facet.strategyName, termFactory);
return new SpoofaxAnalyzeResult(result, context);
}
示例11: transform
import org.metaborg.core.context.IContext; //导入依赖的package包/类
@Override public Collection<TP> transform(P input, IContext context, ITransformGoal goal, ITransformConfig config)
throws TransformException {
if(!input.valid()) {
throw new TransformException("Cannot transform parse unit " + input + ", it is not valid");
}
final Iterable<TransformActionContrib> actions = actionService.actionContributions(context.language(), goal);
final Collection<TP> results = Lists.newArrayList();
for(TransformActionContrib action : actions) {
checkAnalyzed(action);
final TP result = transformer.transform(input, context, action, config);
results.add(result);
}
return results;
}
示例12: transformAllParsed
import org.metaborg.core.context.IContext; //导入依赖的package包/类
@Override public Collection<TP> transformAllParsed(Iterable<P> inputs, IContext context, ITransformGoal goal,
ITransformConfig config) throws TransformException {
final Iterable<TransformActionContrib> actions = actionService.actionContributions(context.language(), goal);
final Collection<TP> results = Lists.newArrayList();
for(TransformActionContrib action : actions) {
checkAnalyzed(action);
final Collection<TP> result = transformer.transformAllParsed(inputs, context, action, config);
results.addAll(result);
}
return results;
}
示例13: transformAllAnalyzed
import org.metaborg.core.context.IContext; //导入依赖的package包/类
@Override public Collection<TA> transformAllAnalyzed(Iterable<A> inputs, IContext context, ITransformGoal goal,
ITransformConfig config) throws TransformException {
final Iterable<TransformActionContrib> actions = actionService.actionContributions(context.language(), goal);
final Collection<TA> results = Lists.newArrayList();
for(TransformActionContrib action : actions) {
final Collection<TA> result = transformer.transformAllAnalyzed(inputs, context, action, config);
results.addAll(result);
}
return results;
}
示例14: analyze
import org.metaborg.core.context.IContext; //导入依赖的package包/类
@Override public IAnalyzeResult<A, AU> analyze(P input, IContext context, IProgress progress, ICancel cancel)
throws AnalysisException, InterruptedException {
final ILanguageImpl langImpl = context.language();
final AnalyzerFacet<P, A, AU> facet = facet(langImpl);
if(facet == null) {
final String message = logger.format("Cannot get an analyzer for {}", langImpl);
throw new AnalysisException(context, message);
}
final IAnalyzer<P, A, AU> analyzer = facet.analyzer;
return analyzer.analyze(input, context, progress, cancel);
}
示例15: analyzeAll
import org.metaborg.core.context.IContext; //导入依赖的package包/类
@Override public IAnalyzeResults<A, AU> analyzeAll(Iterable<P> inputs, IContext context, IProgress progress,
ICancel cancel) throws AnalysisException, InterruptedException {
final ILanguageImpl langImpl = context.language();
final AnalyzerFacet<P, A, AU> facet = facet(langImpl);
if(facet == null) {
final String message = logger.format("Cannot get an analyzer for {}", langImpl);
throw new AnalysisException(context, message);
}
final IAnalyzer<P, A, AU> analyzer = facet.analyzer;
return analyzer.analyzeAll(inputs, context, progress, cancel);
}