protected URI getSourceURI(AnnotationNode node) { URI uri = sourceUnit.getSource().getURI(); if (uri != null) { if (!(uri.isAbsolute() || memberHasValue(node, "allowRelative", true))) { // FIXME: What should we use as the base URI? // It is unlikely we get to this point with a relative URI since making a URL // from will make it absolute I think. But lets handle the simple case of // using file paths and turning that into an absolute file URI. // So we will use the current working directory as the base. URI baseURI = new File(".").toURI(); uri = uri.resolve(baseURI); } } return uri; } }
@Override public void call(final SourceUnit source, final GeneratorContext context, final ClassNode classNode) throws CompilationFailedException { String fileName = source.getName(); ReaderSource reader = source.getSource(); if (reader instanceof FileReaderSource) { FileReaderSource file = (FileReaderSource) reader; fileName = file.getFile().getName(); } if (acceptSource(source) && acceptClass(classNode) && accept(fileName)) { delegate.call(source, context, classNode); } }
@Override protected GroovyCodeVisitor getTransformer(ASTNode[] nodes, SourceUnit sourceUnit) { // todo : are there other import types that can be specified? return new AstBuilderInvocationTrap( sourceUnit.getAST().getImports(), sourceUnit.getAST().getStarImports(), sourceUnit.getSource(), sourceUnit ); }
private String convertInnerClassToSource(final ClassNode type) throws Exception { String source = GeneralUtils.convertASTToSource(sourceUnit.getSource(), type); // we need to remove the leading "{" and trailing "}" source = source.substring(source.indexOf('{') + 1, source.lastIndexOf('}') - 1); return source; } }
private void assertSingleSourceFileUri(File file, Iterator<SourceUnit> sourceUnits) { List<SourceUnit> sourceUnitUris = Lists.newArrayList(); Iterators.addAll(sourceUnitUris, sourceUnits); assertEquals(Lists.newArrayList(file.toPath().toUri()), sourceUnitUris.stream() .map(sourceUnit -> sourceUnit.getSource().getURI()).collect(Collectors.toList())); }
public void visit(ASTNode[] astNodes, SourceUnit source) { if (!(astNodes[0] instanceof AnnotationNode) || !(astNodes[1] instanceof AnnotatedNode)) { throw new RuntimeException("Internal error: wrong types: " + astNodes[0].getClass() + " / " + astNodes[1].getClass()); } AnnotatedNode parent = (AnnotatedNode) astNodes[1]; AnnotationNode annotationNode = (AnnotationNode) astNodes[0]; if (!MY_TYPE.equals(annotationNode.getClassNode()) || !(parent instanceof ClassNode)) { return; } String mainClass = MainClassFinder.searchMainClass(source.getSource().getURI()); ClassNode applicationClassNode = null; if(mainClass != null) { applicationClassNode = ClassHelper.make(mainClass); } ClassNode classNode = (ClassNode) parent; ListExpression values = getListOfClasses(annotationNode); weaveTestMixins(classNode, values, applicationClassNode); }
sourceUnit.getAST().getClasses().forEach(clazz -> { classes.put(clazz.getName(), GroovyLocations.createClassDefinitionLocation( workspaceUriSupplier.get(sourceUnit.getSource().getURI()), clazz)); }); }); URI sourceUri = workspaceUriSupplier.get(sourceUnit.getSource().getURI()); SymbolInformation symbol = getVariableSymbolInformation(scriptClass.getName(), sourceUri, variable); newIndexer.addSymbol(sourceUnit.getSource().getURI(), symbol); if (classes.containsKey(variable.getType().getName())) { newIndexer.addReference(classes.get(variable.getType().getName()),
@Macro public static Expression macro(MacroContext macroContext, PropertyExpression phaseExpression, ConstantExpression asIsConstantExpression, ClosureExpression closureExpression) { if (closureExpression.getParameters() != null && closureExpression.getParameters().length > 0) { macroContext.getSourceUnit().addError(new SyntaxException("Macro closure arguments are not allowed" + '\n', closureExpression)); return macroContext.getCall(); } final String source; try { source = ClosureUtils.convertClosureToSource(macroContext.getSourceUnit().getSource(), closureExpression); } catch (Exception e) { throw new RuntimeException(e); } BlockStatement closureBlock = (BlockStatement) closureExpression.getCode(); Boolean asIs = (Boolean) asIsConstantExpression.getValue(); return callX( propX(classX(ClassHelper.makeWithoutCaching(MacroBuilder.class, false)), "INSTANCE"), "macro", args( phaseExpression != null ? phaseExpression : constX(null), asIsConstantExpression, constX(source), buildSubstitutions(macroContext.getSourceUnit(), closureExpression), classX(ClassHelper.makeWithoutCaching(MacroBuilder.getMacroValue(closureBlock, asIs).getClass(), false)) ) ); }
sourceUnit.getAST().getImports(), sourceUnit.getAST().getStarImports(), sourceUnit.getSource(), sourceUnit );