This repository has been archived by the owner on Jun 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 130
Refactoring PHP generation to use the MVVM pattern #317
Merged
garrettjonesgoogle
merged 9 commits into
googleapis:master
from
garrettjonesgoogle:master
Jul 28, 2016
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8c579b2
Refactoring PHP generation to use the MVVM pattern
garrettjonesgoogle 046b5c3
InitCodeGenerator: using Name for suggestedName
garrettjonesgoogle a0fc1d8
breaking apart long method
garrettjonesgoogle 01e30eb
PR feedback
garrettjonesgoogle 6196a6d
Renaming ViewNamer to NameFormatterMixin
garrettjonesgoogle 0bc4f9d
Decomposing type naming functionality further
garrettjonesgoogle 376ae35
Addressing PR comments
garrettjonesgoogle 60005b2
blank line fixes
garrettjonesgoogle 68c5b2e
Renaming to NameFormatterDelegator
garrettjonesgoogle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
src/main/java/com/google/api/codegen/gapic/ViewModelGapicProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* Copyright 2016 Google Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.google.api.codegen.gapic; | ||
|
||
import com.google.api.codegen.ApiConfig; | ||
import com.google.api.codegen.rendering.CommonSnippetSetRunner; | ||
import com.google.api.codegen.transformer.ModelToViewTransformer; | ||
import com.google.api.codegen.viewmodel.ViewModel; | ||
import com.google.api.tools.framework.model.Interface; | ||
import com.google.api.tools.framework.model.Model; | ||
import com.google.api.tools.framework.model.stages.Merged; | ||
import com.google.api.tools.framework.snippet.Doc; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.TreeMap; | ||
|
||
public class ViewModelGapicProvider implements GapicProvider<Interface> { | ||
private final Model model; | ||
private final ApiConfig apiConfig; | ||
private final CommonSnippetSetRunner snippetSetRunner; | ||
private final ModelToViewTransformer modelToViewTransformer; | ||
|
||
private ViewModelGapicProvider( | ||
Model model, | ||
ApiConfig apiConfig, | ||
CommonSnippetSetRunner snippetSetRunner, | ||
ModelToViewTransformer modelToViewTransformer) { | ||
this.model = model; | ||
this.apiConfig = apiConfig; | ||
this.snippetSetRunner = snippetSetRunner; | ||
this.modelToViewTransformer = modelToViewTransformer; | ||
} | ||
|
||
@Override | ||
public List<String> getSnippetFileNames() { | ||
return modelToViewTransformer.getTemplateFileNames(); | ||
} | ||
|
||
@Override | ||
public Map<String, Doc> generate() { | ||
return generate(null); | ||
} | ||
|
||
@Override | ||
public Map<String, Doc> generate(String snippetFileName) { | ||
// Establish required stage for generation. | ||
model.establishStage(Merged.KEY); | ||
if (model.getDiagCollector().getErrorCount() > 0) { | ||
return null; | ||
} | ||
|
||
List<ViewModel> surfaceDocs = modelToViewTransformer.transform(model, apiConfig); | ||
if (model.getDiagCollector().getErrorCount() > 0) { | ||
return null; | ||
} | ||
|
||
Map<String, Doc> docs = new TreeMap<>(); | ||
for (ViewModel surfaceDoc : surfaceDocs) { | ||
if (snippetFileName != null && !surfaceDoc.templateFileName().equals(snippetFileName)) { | ||
continue; | ||
} | ||
Doc doc = snippetSetRunner.generate(surfaceDoc); | ||
if (doc == null) { | ||
continue; | ||
} | ||
docs.put(surfaceDoc.outputPath(), doc); | ||
} | ||
|
||
return docs; | ||
} | ||
|
||
public static Builder newBuilder() { | ||
return new Builder(); | ||
} | ||
|
||
public static class Builder { | ||
private Model model; | ||
private ApiConfig apiConfig; | ||
private CommonSnippetSetRunner snippetSetRunner; | ||
private ModelToViewTransformer modelToViewTransformer; | ||
|
||
private Builder() {} | ||
|
||
public Builder setModel(Model model) { | ||
this.model = model; | ||
return this; | ||
} | ||
|
||
public Builder setApiConfig(ApiConfig apiConfig) { | ||
this.apiConfig = apiConfig; | ||
return this; | ||
} | ||
|
||
public Builder setSnippetSetRunner(CommonSnippetSetRunner snippetSetRunner) { | ||
this.snippetSetRunner = snippetSetRunner; | ||
return this; | ||
} | ||
|
||
public Builder setModelToViewTransformer(ModelToViewTransformer modelToViewTransformer) { | ||
this.modelToViewTransformer = modelToViewTransformer; | ||
return this; | ||
} | ||
|
||
public ViewModelGapicProvider build() { | ||
return new ViewModelGapicProvider(model, apiConfig, snippetSetRunner, modelToViewTransformer); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.