Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
b2fc3d2
feat: SampleComposer, Sample, Region Tag
eaball35 Feb 15, 2022
a1e3e11
feat: update SampleCodeComposers to output Samples with Region Tags
eaball35 Feb 15, 2022
4348268
feat: update current inline samples
eaball35 Feb 15, 2022
fdd879a
test: unit goldens
eaball35 Feb 15, 2022
f919e8a
test: integration goldens - update inline samples
eaball35 Feb 15, 2022
c1b56d5
feat: write samples to files
eaball35 Feb 15, 2022
81a2e4b
test: integration goldens - write samples to files
eaball35 Feb 15, 2022
b1279e6
chore: update sample formatter name
eaball35 Feb 15, 2022
1742843
test: integration goldens - update sample path to lowercase
eaball35 Feb 15, 2022
ffafbb2
Merge branch 'main' into samplegen-pt3
eaball35 Feb 23, 2022
b06b544
refactor: write with sample code writer
eaball35 Mar 5, 2022
670024a
refactor: update to write with ClassDefinition
eaball35 Mar 5, 2022
71b98ef
refactor: testing
eaball35 Mar 5, 2022
ebbb4e0
refactor (tests): unit goldens
eaball35 Mar 5, 2022
e6b6b28
refactor (tests): integration goldens
eaball35 Mar 5, 2022
d44185f
formatting
eaball35 Mar 5, 2022
223853f
refactor: writing
eaball35 Mar 5, 2022
b37dda7
Merge branch 'main' into samplegen-pt3
eaball35 Mar 7, 2022
e2e2f91
refactor: include sync/async region tag attribut
eaball35 Mar 7, 2022
5f022fb
refactor: include sync/async region tag attribute goldens
eaball35 Mar 7, 2022
077e07c
Merge branch 'main' into samplegen-pt1
eaball35 Mar 7, 2022
a8a4211
refactor: include sync/async region tag attribute
eaball35 Mar 7, 2022
7cc67e5
refactor: breakup ServiceClientSampleCodeComposer and renaming for si…
eaball35 Mar 8, 2022
72f5dbe
refactor: update sample naming, nit fixes
eaball35 Mar 15, 2022
dec4d62
refactor: integration goldens - sample naming
eaball35 Mar 15, 2022
77a4d7d
refactor: unit goldens - update sample naming, nit fixes
eaball35 Mar 15, 2022
5c2dcad
Merge branch 'main' into samplegen-pt3
eaball35 Mar 15, 2022
ebad623
Merge branch 'main' into samplegen-pt3
eaball35 Mar 15, 2022
77ca5d0
Merge branch 'samplegen-pt3' of https://github.com/googleapis/gapic-g…
eaball35 Mar 15, 2022
59a59d6
refactor: naming updates
eaball35 Mar 15, 2022
525f7c7
refactor: update naming - tests
eaball35 Mar 15, 2022
b3ebd74
Merge branch 'main' into samplegen-pt1
eaball35 Mar 15, 2022
7a09263
refactor: breakout/rename sample classes
eaball35 Mar 15, 2022
de80349
feat: update inline samples
eaball35 Mar 15, 2022
51dd0d5
test: integration goldens - update inline sample comment
eaball35 Mar 15, 2022
530edd4
test: update tests
eaball35 Mar 15, 2022
ac0c79a
test: update goldens - include inline comment
eaball35 Mar 15, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.google.api.generator.engine.ast;

import com.google.api.generator.gapic.model.RegionTag;
import com.google.auto.value.AutoValue;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
Expand All @@ -26,6 +27,9 @@
public abstract class ClassDefinition implements AstNode {
// Optional.
public abstract ImmutableList<CommentStatement> fileHeader();
// Required for samples classes.
@Nullable
public abstract RegionTag regionTag();
// Required.
public abstract ScopeNode scope();
// Required.
Expand Down Expand Up @@ -92,6 +96,8 @@ public Builder setFileHeader(CommentStatement... headerComments) {

public abstract Builder setFileHeader(List<CommentStatement> fileHeader);

public abstract Builder setRegionTag(RegionTag regionTag);

public Builder setHeaderCommentStatements(CommentStatement... comments) {
return setHeaderCommentStatements(Arrays.asList(comments));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
import com.google.api.generator.engine.ast.VaporReference;
import com.google.api.generator.engine.ast.VariableExpr;
import com.google.api.generator.engine.ast.WhileStatement;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -357,13 +356,7 @@ public void visit(TryCatchStatement tryCatchStatement) {
if (tryCatchStatement.tryResourceExpr() != null) {
tryCatchStatement.tryResourceExpr().accept(this);
}

statements(tryCatchStatement.tryBody());

Preconditions.checkState(
!tryCatchStatement.isSampleCode() && !tryCatchStatement.catchVariableExprs().isEmpty(),
"Import generation should not be invoked on sample code, but was found when visiting a"
+ " try-catch block");
for (int i = 0; i < tryCatchStatement.catchVariableExprs().size(); i++) {
tryCatchStatement.catchVariableExprs().get(i).accept(this);
statements(tryCatchStatement.catchBlocks().get(i));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import com.google.api.generator.engine.ast.Variable;
import com.google.api.generator.engine.ast.VariableExpr;
import com.google.api.generator.engine.ast.WhileStatement;
import com.google.api.generator.gapic.model.RegionTag;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -910,6 +911,15 @@ public void visit(ClassDefinition classDefinition) {
newline();
}

String regionTagReplace = "REPLACE_REGION_TAG";
if (classDefinition.regionTag() != null) {
statements(
Arrays.asList(
classDefinition
.regionTag()
.generateTag(RegionTag.RegionTagRegion.START, regionTagReplace)));
}

// This must go first, so that we can check for type collisions.
classDefinition.accept(importWriterVisitor);
if (!classDefinition.isNested()) {
Expand Down Expand Up @@ -974,10 +984,27 @@ public void visit(ClassDefinition classDefinition) {
classes(classDefinition.nestedClasses());

rightBrace();
if (classDefinition.regionTag() != null) {
statements(
Arrays.asList(
classDefinition
.regionTag()
.generateTag(RegionTag.RegionTagRegion.END, regionTagReplace)));
}

// We should have valid Java by now, so format it.
if (!classDefinition.isNested()) {
buffer.replace(0, buffer.length(), JavaFormatter.format(buffer.toString()));
String formattedClazz = JavaFormatter.format(buffer.toString());

// fixing region tag after formatting
// formatter splits long region tags on multiple lines and moves the end tag up - doesn't meet
// tag requirements
if (classDefinition.regionTag() != null) {
formattedClazz =
formattedClazz.replaceAll(regionTagReplace, classDefinition.regionTag().generate());
formattedClazz = formattedClazz.replaceAll("} // \\[END", "}\n// \\[END");
}
buffer.replace(0, buffer.length(), formattedClazz);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
import com.google.api.generator.engine.ast.PackageInfoDefinition;
import com.google.api.generator.engine.ast.TypeNode;
import com.google.api.generator.engine.ast.VaporReference;
import com.google.api.generator.gapic.composer.samplecode.ServiceClientSampleCodeComposer;
import com.google.api.generator.gapic.composer.samplecode.SampleCodeWriter;
import com.google.api.generator.gapic.composer.samplecode.ServiceClientHeaderSampleComposer;
import com.google.api.generator.gapic.composer.utils.ClassNames;
import com.google.api.generator.gapic.model.GapicContext;
import com.google.api.generator.gapic.model.GapicPackageInfo;
import com.google.api.generator.gapic.model.Sample;
import com.google.api.generator.gapic.model.Service;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
Expand Down Expand Up @@ -119,10 +121,11 @@ private static CommentStatement createPackageInfoJavadoc(GapicContext context) {
.setPakkage(service.pakkage())
.setName(ClassNames.getServiceClientClassName(service))
.build());
String packageInfoSampleCode =
ServiceClientSampleCodeComposer.composeClassHeaderMethodSampleCode(
Sample packageInfoSampleCode =
ServiceClientHeaderSampleComposer.composeClassHeaderSample(
service, clientType, context.resourceNames(), context.messages());
javaDocCommentBuilder.addSampleCode(packageInfoSampleCode);
javaDocCommentBuilder.addSampleCode(
SampleCodeWriter.writeInlineSample(packageInfoSampleCode.body()));
}

return CommentStatement.withComment(javaDocCommentBuilder.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
import com.google.api.generator.engine.ast.BlockComment;
import com.google.api.generator.engine.ast.CommentStatement;
import com.google.api.generator.engine.ast.LineComment;
import com.google.api.generator.engine.ast.Statement;
import java.util.Arrays;
import java.util.List;

public class CommentComposer {
private static final String APACHE_LICENSE_STRING =
Expand Down Expand Up @@ -52,4 +55,13 @@ public class CommentComposer {
public static final CommentStatement AUTO_GENERATED_METHOD_COMMENT =
CommentStatement.withComment(
LineComment.withComment(AUTO_GENERATED_METHOD_DISCLAIMER_STRING));

public static final List<Statement> AUTO_GENERATED_SAMPLE_COMMENT =
Arrays.asList(
CommentStatement.withComment(
LineComment.withComment(
"This snippet has been automatically generated for illustrative purposes only.")),
CommentStatement.withComment(
LineComment.withComment(
"It may require modifications to work in your environment.")));
}
Loading