repo_name
stringlengths
7
104
file_path
stringlengths
13
198
context
stringlengths
67
7.15k
import_statement
stringlengths
16
4.43k
code
stringlengths
40
6.98k
prompt
stringlengths
227
8.27k
next_line
stringlengths
8
795
adelf/idea-php-dotenv-plugin
src/main/java/ru/adelf/idea/dotenv/inspections/SpaceInsideNonQuotedInspection.java
// Path: src/main/java/ru/adelf/idea/dotenv/DotEnvFactory.java // public class DotEnvFactory { // public static PsiElement createFromText(@NotNull Project project, @NotNull IElementType type, @NotNull String text) { // final Ref<PsiElement> ret = new Ref<>(); // PsiFile dummyFile = createDummyFile(project, text); // dummyFile.accept(new PsiRecursiveElementWalkingVisitor() { // public void visitElement(@NotNull PsiElement element) { // ASTNode node = element.getNode(); // if (node != null && node.getElementType() == type) { // ret.set(element); // stopWalking(); // } else { // super.visitElement(element); // } // } // }); // // assert !ret.isNull() : "cannot create element from text:\n" + dummyFile.getText(); // // return ret.get(); // } // // @NotNull // private static PsiFile createDummyFile(Project project, String fileText) { // return PsiFileFactory.getInstance(project).createFileFromText("DUMMY__.env", DotEnvFileType.INSTANCE, fileText, System.currentTimeMillis(), false); // } // } // // Path: src/main/java/ru/adelf/idea/dotenv/psi/DotEnvFile.java // public class DotEnvFile extends PsiFileBase { // public DotEnvFile(@NotNull FileViewProvider viewProvider) { // super(viewProvider, DotEnvLanguage.INSTANCE); // } // // @NotNull // @Override // public FileType getFileType() { // return DotEnvFileType.INSTANCE; // } // // @Override // public String toString() { // return ".env file"; // } // // @Override // public Icon getIcon(int flags) { // return super.getIcon(flags); // } // } // // Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvTypes.java // public interface DotEnvTypes { // // IElementType KEY = new DotEnvElementType("KEY"); // IElementType PROPERTY = new DotEnvElementType("PROPERTY"); // IElementType VALUE = new DotEnvElementType("VALUE"); // // IElementType COMMENT = new DotEnvTokenType("COMMENT"); // IElementType CRLF = new DotEnvTokenType("CRLF"); // IElementType EXPORT = new DotEnvTokenType("EXPORT"); // IElementType KEY_CHARS = new DotEnvTokenType("KEY_CHARS"); // IElementType QUOTE = new DotEnvTokenType("QUOTE"); // IElementType SEPARATOR = new DotEnvTokenType("SEPARATOR"); // IElementType VALUE_CHARS = new DotEnvTokenType("VALUE_CHARS"); // // class Factory { // public static PsiElement createElement(ASTNode node) { // IElementType type = node.getElementType(); // if (type == KEY) { // return new DotEnvKeyImpl(node); // } // else if (type == PROPERTY) { // return new DotEnvPropertyImpl(node); // } // else if (type == VALUE) { // return new DotEnvValueImpl(node); // } // throw new AssertionError("Unknown element type: " + type); // } // } // } // // Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvValue.java // public interface DotEnvValue extends PsiElement { // // }
import com.intellij.codeInspection.*; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import ru.adelf.idea.dotenv.DotEnvFactory; import ru.adelf.idea.dotenv.psi.DotEnvFile; import ru.adelf.idea.dotenv.psi.DotEnvTypes; import ru.adelf.idea.dotenv.psi.DotEnvValue; import java.util.function.Supplier; import java.util.stream.Stream;
package ru.adelf.idea.dotenv.inspections; public class SpaceInsideNonQuotedInspection extends LocalInspectionTool { // Change the display name within the plugin.xml // This needs to be here as otherwise the tests will throw errors. @NotNull @Override public String getDisplayName() { return "Space inside non-quoted value"; } private AddQuotesQuickFix addQuotesQuickFix = new AddQuotesQuickFix(); @Override public boolean runForWholeFile() { return true; } @Nullable @Override public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) { if (!(file instanceof DotEnvFile)) { return null; } return analyzeFile(file, manager, isOnTheFly).getResultsArray(); } @NotNull private ProblemsHolder analyzeFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) { ProblemsHolder problemsHolder = new ProblemsHolder(manager, file, isOnTheFly); PsiTreeUtil.findChildrenOfType(file, DotEnvValue.class).forEach(dotEnvValue -> { // first child VALUE_CHARS -> non quoted value // first child QUOTE -> quoted value
// Path: src/main/java/ru/adelf/idea/dotenv/DotEnvFactory.java // public class DotEnvFactory { // public static PsiElement createFromText(@NotNull Project project, @NotNull IElementType type, @NotNull String text) { // final Ref<PsiElement> ret = new Ref<>(); // PsiFile dummyFile = createDummyFile(project, text); // dummyFile.accept(new PsiRecursiveElementWalkingVisitor() { // public void visitElement(@NotNull PsiElement element) { // ASTNode node = element.getNode(); // if (node != null && node.getElementType() == type) { // ret.set(element); // stopWalking(); // } else { // super.visitElement(element); // } // } // }); // // assert !ret.isNull() : "cannot create element from text:\n" + dummyFile.getText(); // // return ret.get(); // } // // @NotNull // private static PsiFile createDummyFile(Project project, String fileText) { // return PsiFileFactory.getInstance(project).createFileFromText("DUMMY__.env", DotEnvFileType.INSTANCE, fileText, System.currentTimeMillis(), false); // } // } // // Path: src/main/java/ru/adelf/idea/dotenv/psi/DotEnvFile.java // public class DotEnvFile extends PsiFileBase { // public DotEnvFile(@NotNull FileViewProvider viewProvider) { // super(viewProvider, DotEnvLanguage.INSTANCE); // } // // @NotNull // @Override // public FileType getFileType() { // return DotEnvFileType.INSTANCE; // } // // @Override // public String toString() { // return ".env file"; // } // // @Override // public Icon getIcon(int flags) { // return super.getIcon(flags); // } // } // // Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvTypes.java // public interface DotEnvTypes { // // IElementType KEY = new DotEnvElementType("KEY"); // IElementType PROPERTY = new DotEnvElementType("PROPERTY"); // IElementType VALUE = new DotEnvElementType("VALUE"); // // IElementType COMMENT = new DotEnvTokenType("COMMENT"); // IElementType CRLF = new DotEnvTokenType("CRLF"); // IElementType EXPORT = new DotEnvTokenType("EXPORT"); // IElementType KEY_CHARS = new DotEnvTokenType("KEY_CHARS"); // IElementType QUOTE = new DotEnvTokenType("QUOTE"); // IElementType SEPARATOR = new DotEnvTokenType("SEPARATOR"); // IElementType VALUE_CHARS = new DotEnvTokenType("VALUE_CHARS"); // // class Factory { // public static PsiElement createElement(ASTNode node) { // IElementType type = node.getElementType(); // if (type == KEY) { // return new DotEnvKeyImpl(node); // } // else if (type == PROPERTY) { // return new DotEnvPropertyImpl(node); // } // else if (type == VALUE) { // return new DotEnvValueImpl(node); // } // throw new AssertionError("Unknown element type: " + type); // } // } // } // // Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvValue.java // public interface DotEnvValue extends PsiElement { // // } // Path: src/main/java/ru/adelf/idea/dotenv/inspections/SpaceInsideNonQuotedInspection.java import com.intellij.codeInspection.*; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import ru.adelf.idea.dotenv.DotEnvFactory; import ru.adelf.idea.dotenv.psi.DotEnvFile; import ru.adelf.idea.dotenv.psi.DotEnvTypes; import ru.adelf.idea.dotenv.psi.DotEnvValue; import java.util.function.Supplier; import java.util.stream.Stream; package ru.adelf.idea.dotenv.inspections; public class SpaceInsideNonQuotedInspection extends LocalInspectionTool { // Change the display name within the plugin.xml // This needs to be here as otherwise the tests will throw errors. @NotNull @Override public String getDisplayName() { return "Space inside non-quoted value"; } private AddQuotesQuickFix addQuotesQuickFix = new AddQuotesQuickFix(); @Override public boolean runForWholeFile() { return true; } @Nullable @Override public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) { if (!(file instanceof DotEnvFile)) { return null; } return analyzeFile(file, manager, isOnTheFly).getResultsArray(); } @NotNull private ProblemsHolder analyzeFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) { ProblemsHolder problemsHolder = new ProblemsHolder(manager, file, isOnTheFly); PsiTreeUtil.findChildrenOfType(file, DotEnvValue.class).forEach(dotEnvValue -> { // first child VALUE_CHARS -> non quoted value // first child QUOTE -> quoted value
if(dotEnvValue.getFirstChild().getNode().getElementType() == DotEnvTypes.VALUE_CHARS) {
adelf/idea-php-dotenv-plugin
src/main/java/ru/adelf/idea/dotenv/inspections/SpaceInsideNonQuotedInspection.java
// Path: src/main/java/ru/adelf/idea/dotenv/DotEnvFactory.java // public class DotEnvFactory { // public static PsiElement createFromText(@NotNull Project project, @NotNull IElementType type, @NotNull String text) { // final Ref<PsiElement> ret = new Ref<>(); // PsiFile dummyFile = createDummyFile(project, text); // dummyFile.accept(new PsiRecursiveElementWalkingVisitor() { // public void visitElement(@NotNull PsiElement element) { // ASTNode node = element.getNode(); // if (node != null && node.getElementType() == type) { // ret.set(element); // stopWalking(); // } else { // super.visitElement(element); // } // } // }); // // assert !ret.isNull() : "cannot create element from text:\n" + dummyFile.getText(); // // return ret.get(); // } // // @NotNull // private static PsiFile createDummyFile(Project project, String fileText) { // return PsiFileFactory.getInstance(project).createFileFromText("DUMMY__.env", DotEnvFileType.INSTANCE, fileText, System.currentTimeMillis(), false); // } // } // // Path: src/main/java/ru/adelf/idea/dotenv/psi/DotEnvFile.java // public class DotEnvFile extends PsiFileBase { // public DotEnvFile(@NotNull FileViewProvider viewProvider) { // super(viewProvider, DotEnvLanguage.INSTANCE); // } // // @NotNull // @Override // public FileType getFileType() { // return DotEnvFileType.INSTANCE; // } // // @Override // public String toString() { // return ".env file"; // } // // @Override // public Icon getIcon(int flags) { // return super.getIcon(flags); // } // } // // Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvTypes.java // public interface DotEnvTypes { // // IElementType KEY = new DotEnvElementType("KEY"); // IElementType PROPERTY = new DotEnvElementType("PROPERTY"); // IElementType VALUE = new DotEnvElementType("VALUE"); // // IElementType COMMENT = new DotEnvTokenType("COMMENT"); // IElementType CRLF = new DotEnvTokenType("CRLF"); // IElementType EXPORT = new DotEnvTokenType("EXPORT"); // IElementType KEY_CHARS = new DotEnvTokenType("KEY_CHARS"); // IElementType QUOTE = new DotEnvTokenType("QUOTE"); // IElementType SEPARATOR = new DotEnvTokenType("SEPARATOR"); // IElementType VALUE_CHARS = new DotEnvTokenType("VALUE_CHARS"); // // class Factory { // public static PsiElement createElement(ASTNode node) { // IElementType type = node.getElementType(); // if (type == KEY) { // return new DotEnvKeyImpl(node); // } // else if (type == PROPERTY) { // return new DotEnvPropertyImpl(node); // } // else if (type == VALUE) { // return new DotEnvValueImpl(node); // } // throw new AssertionError("Unknown element type: " + type); // } // } // } // // Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvValue.java // public interface DotEnvValue extends PsiElement { // // }
import com.intellij.codeInspection.*; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import ru.adelf.idea.dotenv.DotEnvFactory; import ru.adelf.idea.dotenv.psi.DotEnvFile; import ru.adelf.idea.dotenv.psi.DotEnvTypes; import ru.adelf.idea.dotenv.psi.DotEnvValue; import java.util.function.Supplier; import java.util.stream.Stream;
@Override public String getName() { return "Add quotes"; } /** * Adds quotes to DotEnvValue element * * @param project The project that contains the file being edited. * @param descriptor A problem found by this inspection. */ public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { // counting each quote type " AND '. The quickfix will use the most common quote type. String quote; Supplier<Stream<DotEnvValue>> supplier = () -> PsiTreeUtil.findChildrenOfType(descriptor.getPsiElement().getContainingFile(), DotEnvValue.class) .stream() .filter(dotEnvValue -> dotEnvValue.getFirstChild().getNode().getElementType() == DotEnvTypes.QUOTE); long total = supplier.get().count(); long doubleQuoted = supplier.get().filter(dotEnvValue -> dotEnvValue.getFirstChild().getText().contains("\"")).count(); long singleQuoted = total - doubleQuoted; if (doubleQuoted > singleQuoted) { quote = "\""; } else { quote = "'"; } try { DotEnvValue valueElement = (DotEnvValue) descriptor.getPsiElement();
// Path: src/main/java/ru/adelf/idea/dotenv/DotEnvFactory.java // public class DotEnvFactory { // public static PsiElement createFromText(@NotNull Project project, @NotNull IElementType type, @NotNull String text) { // final Ref<PsiElement> ret = new Ref<>(); // PsiFile dummyFile = createDummyFile(project, text); // dummyFile.accept(new PsiRecursiveElementWalkingVisitor() { // public void visitElement(@NotNull PsiElement element) { // ASTNode node = element.getNode(); // if (node != null && node.getElementType() == type) { // ret.set(element); // stopWalking(); // } else { // super.visitElement(element); // } // } // }); // // assert !ret.isNull() : "cannot create element from text:\n" + dummyFile.getText(); // // return ret.get(); // } // // @NotNull // private static PsiFile createDummyFile(Project project, String fileText) { // return PsiFileFactory.getInstance(project).createFileFromText("DUMMY__.env", DotEnvFileType.INSTANCE, fileText, System.currentTimeMillis(), false); // } // } // // Path: src/main/java/ru/adelf/idea/dotenv/psi/DotEnvFile.java // public class DotEnvFile extends PsiFileBase { // public DotEnvFile(@NotNull FileViewProvider viewProvider) { // super(viewProvider, DotEnvLanguage.INSTANCE); // } // // @NotNull // @Override // public FileType getFileType() { // return DotEnvFileType.INSTANCE; // } // // @Override // public String toString() { // return ".env file"; // } // // @Override // public Icon getIcon(int flags) { // return super.getIcon(flags); // } // } // // Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvTypes.java // public interface DotEnvTypes { // // IElementType KEY = new DotEnvElementType("KEY"); // IElementType PROPERTY = new DotEnvElementType("PROPERTY"); // IElementType VALUE = new DotEnvElementType("VALUE"); // // IElementType COMMENT = new DotEnvTokenType("COMMENT"); // IElementType CRLF = new DotEnvTokenType("CRLF"); // IElementType EXPORT = new DotEnvTokenType("EXPORT"); // IElementType KEY_CHARS = new DotEnvTokenType("KEY_CHARS"); // IElementType QUOTE = new DotEnvTokenType("QUOTE"); // IElementType SEPARATOR = new DotEnvTokenType("SEPARATOR"); // IElementType VALUE_CHARS = new DotEnvTokenType("VALUE_CHARS"); // // class Factory { // public static PsiElement createElement(ASTNode node) { // IElementType type = node.getElementType(); // if (type == KEY) { // return new DotEnvKeyImpl(node); // } // else if (type == PROPERTY) { // return new DotEnvPropertyImpl(node); // } // else if (type == VALUE) { // return new DotEnvValueImpl(node); // } // throw new AssertionError("Unknown element type: " + type); // } // } // } // // Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvValue.java // public interface DotEnvValue extends PsiElement { // // } // Path: src/main/java/ru/adelf/idea/dotenv/inspections/SpaceInsideNonQuotedInspection.java import com.intellij.codeInspection.*; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import ru.adelf.idea.dotenv.DotEnvFactory; import ru.adelf.idea.dotenv.psi.DotEnvFile; import ru.adelf.idea.dotenv.psi.DotEnvTypes; import ru.adelf.idea.dotenv.psi.DotEnvValue; import java.util.function.Supplier; import java.util.stream.Stream; @Override public String getName() { return "Add quotes"; } /** * Adds quotes to DotEnvValue element * * @param project The project that contains the file being edited. * @param descriptor A problem found by this inspection. */ public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { // counting each quote type " AND '. The quickfix will use the most common quote type. String quote; Supplier<Stream<DotEnvValue>> supplier = () -> PsiTreeUtil.findChildrenOfType(descriptor.getPsiElement().getContainingFile(), DotEnvValue.class) .stream() .filter(dotEnvValue -> dotEnvValue.getFirstChild().getNode().getElementType() == DotEnvTypes.QUOTE); long total = supplier.get().count(); long doubleQuoted = supplier.get().filter(dotEnvValue -> dotEnvValue.getFirstChild().getText().contains("\"")).count(); long singleQuoted = total - doubleQuoted; if (doubleQuoted > singleQuoted) { quote = "\""; } else { quote = "'"; } try { DotEnvValue valueElement = (DotEnvValue) descriptor.getPsiElement();
PsiElement newValueElement = DotEnvFactory.createFromText(project, DotEnvTypes.VALUE, "DUMMY=" + quote + valueElement.getText() + quote);
adelf/idea-php-dotenv-plugin
src/main/java/ru/adelf/idea/dotenv/api/EnvironmentVariablesUsagesProvider.java
// Path: src/main/java/ru/adelf/idea/dotenv/models/KeyUsagePsiElement.java // public class KeyUsagePsiElement { // // private final String key; // private final PsiElement element; // // public KeyUsagePsiElement(String key, PsiElement element) { // this.key = key; // this.element = element; // } // // public String getKey() { // return key; // } // // public PsiElement getElement() { // return element; // } // }
import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; import org.jetbrains.annotations.NotNull; import ru.adelf.idea.dotenv.models.KeyUsagePsiElement; import java.util.Collection;
package ru.adelf.idea.dotenv.api; public interface EnvironmentVariablesUsagesProvider { boolean acceptFile(VirtualFile file); @NotNull
// Path: src/main/java/ru/adelf/idea/dotenv/models/KeyUsagePsiElement.java // public class KeyUsagePsiElement { // // private final String key; // private final PsiElement element; // // public KeyUsagePsiElement(String key, PsiElement element) { // this.key = key; // this.element = element; // } // // public String getKey() { // return key; // } // // public PsiElement getElement() { // return element; // } // } // Path: src/main/java/ru/adelf/idea/dotenv/api/EnvironmentVariablesUsagesProvider.java import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; import org.jetbrains.annotations.NotNull; import ru.adelf.idea.dotenv.models.KeyUsagePsiElement; import java.util.Collection; package ru.adelf.idea.dotenv.api; public interface EnvironmentVariablesUsagesProvider { boolean acceptFile(VirtualFile file); @NotNull
Collection<KeyUsagePsiElement> getUsages(PsiFile psiFile);
adelf/idea-php-dotenv-plugin
src/main/java/ru/adelf/idea/dotenv/extension/DotEnvReferencesSearcher.java
// Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvProperty.java // public interface DotEnvProperty extends DotEnvNamedElement { // // @NotNull // DotEnvKey getKey(); // // @Nullable // DotEnvValue getValue(); // // String getKeyText(); // // String getValueText(); // // String getName(); // // PsiElement setName(@NotNull String newName); // // PsiElement getNameIdentifier(); // // }
import com.intellij.openapi.application.QueryExecutorBase; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiReference; import com.intellij.psi.search.SearchRequestCollector; import com.intellij.psi.search.SearchScope; import com.intellij.psi.search.UsageSearchContext; import com.intellij.psi.search.searches.ReferencesSearch; import com.intellij.util.Processor; import org.jetbrains.annotations.NotNull; import ru.adelf.idea.dotenv.psi.DotEnvProperty;
package ru.adelf.idea.dotenv.extension; public class DotEnvReferencesSearcher extends QueryExecutorBase<PsiReference, ReferencesSearch.SearchParameters> { public DotEnvReferencesSearcher() { super(true); } @Override public void processQuery(@NotNull ReferencesSearch.SearchParameters queryParameters, @NotNull Processor<? super PsiReference> consumer) { PsiElement refElement = queryParameters.getElementToSearch();
// Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvProperty.java // public interface DotEnvProperty extends DotEnvNamedElement { // // @NotNull // DotEnvKey getKey(); // // @Nullable // DotEnvValue getValue(); // // String getKeyText(); // // String getValueText(); // // String getName(); // // PsiElement setName(@NotNull String newName); // // PsiElement getNameIdentifier(); // // } // Path: src/main/java/ru/adelf/idea/dotenv/extension/DotEnvReferencesSearcher.java import com.intellij.openapi.application.QueryExecutorBase; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiReference; import com.intellij.psi.search.SearchRequestCollector; import com.intellij.psi.search.SearchScope; import com.intellij.psi.search.UsageSearchContext; import com.intellij.psi.search.searches.ReferencesSearch; import com.intellij.util.Processor; import org.jetbrains.annotations.NotNull; import ru.adelf.idea.dotenv.psi.DotEnvProperty; package ru.adelf.idea.dotenv.extension; public class DotEnvReferencesSearcher extends QueryExecutorBase<PsiReference, ReferencesSearch.SearchParameters> { public DotEnvReferencesSearcher() { super(true); } @Override public void processQuery(@NotNull ReferencesSearch.SearchParameters queryParameters, @NotNull Processor<? super PsiReference> consumer) { PsiElement refElement = queryParameters.getElementToSearch();
if (!(refElement instanceof DotEnvProperty)) return;
adelf/idea-php-dotenv-plugin
src/test/java/ru/adelf/idea/dotenv/tests/completions/CompletionValuesTest.java
// Path: src/main/java/ru/adelf/idea/dotenv/api/EnvironmentVariablesApi.java // public class EnvironmentVariablesApi { // // @NotNull // public static Map<String, String> getAllKeyValues(Project project) { // FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance(); // Map<String, String> keyValues = new HashMap<>(); // Map<String, String> secondaryKeyValues = new HashMap<>(); // Map<VirtualFile, FileAcceptResult> resultsCache = new HashMap<>(); // // GlobalSearchScope scope = GlobalSearchScope.allScope(project); // // fileBasedIndex.processAllKeys(DotEnvKeyValuesIndex.KEY, key -> { // for (VirtualFile virtualFile : fileBasedIndex.getContainingFiles(DotEnvKeyValuesIndex.KEY, key, scope)) { // // FileAcceptResult fileAcceptResult; // // if (resultsCache.containsKey(virtualFile)) { // fileAcceptResult = resultsCache.get(virtualFile); // } else { // fileAcceptResult = getFileAcceptResult(virtualFile); // resultsCache.put(virtualFile, fileAcceptResult); // } // // if (!fileAcceptResult.isAccepted()) { // continue; // } // // fileBasedIndex.processValues(DotEnvKeyValuesIndex.KEY, key, virtualFile, ((file, val) -> { // if (fileAcceptResult.isPrimary()) { // keyValues.putIfAbsent(key, val); // } else { // secondaryKeyValues.putIfAbsent(key, val); // } // // return true; // }), scope); // } // // return true; // }, project); // // secondaryKeyValues.putAll(keyValues); // // return secondaryKeyValues; // } // // /** // * @param project project // * @param key environment variable key // * @return All key declarations, in .env files, Dockerfile, docker-compose.yml, etc // */ // @NotNull // public static PsiElement[] getKeyDeclarations(Project project, String key) { // List<PsiElement> targets = new ArrayList<>(); // List<PsiElement> secondaryTargets = new ArrayList<>(); // // FileBasedIndex.getInstance().getFilesWithKey(DotEnvKeyValuesIndex.KEY, new HashSet<>(Collections.singletonList(key)), virtualFile -> { // PsiFile psiFileTarget = PsiManager.getInstance(project).findFile(virtualFile); // if (psiFileTarget == null) { // return true; // } // // for (EnvironmentVariablesProvider provider : EnvironmentVariablesProviderUtil.PROVIDERS) { // FileAcceptResult fileAcceptResult = provider.acceptFile(virtualFile); // if (!fileAcceptResult.isAccepted()) { // continue; // } // // (fileAcceptResult.isPrimary() ? targets : secondaryTargets).addAll(EnvironmentVariablesUtil.getElementsByKey(key, provider.getElements(psiFileTarget))); // } // // return true; // }, GlobalSearchScope.allScope(project)); // // return (targets.size() > 0 ? targets : secondaryTargets).toArray(PsiElement.EMPTY_ARRAY); // } // // /** // * @param project project // * @param key environment variable key // * @return All key usages, like getenv('KEY') // */ // @NotNull // public static PsiElement[] getKeyUsages(Project project, String key) { // List<PsiElement> targets = new ArrayList<>(); // // PsiSearchHelper searchHelper = PsiSearchHelper.getInstance(project); // // Processor<PsiFile> psiFileProcessor = psiFile -> { // for (EnvironmentVariablesUsagesProvider provider : EnvironmentVariablesProviderUtil.USAGES_PROVIDERS) { // targets.addAll(EnvironmentVariablesUtil.getUsagesElementsByKey(key, provider.getUsages(psiFile))); // } // // return true; // }; // // searchHelper.processAllFilesWithWord(key, GlobalSearchScope.allScope(project), psiFileProcessor, true); // searchHelper.processAllFilesWithWordInLiterals(key, GlobalSearchScope.allScope(project), psiFileProcessor); // searchHelper.processAllFilesWithWordInText(key, GlobalSearchScope.allScope(project), psiFileProcessor, true); // // return targets.toArray(PsiElement.EMPTY_ARRAY); // } // // private static FileAcceptResult getFileAcceptResult(VirtualFile virtualFile) { // for (EnvironmentVariablesProvider provider : EnvironmentVariablesProviderUtil.PROVIDERS) { // FileAcceptResult fileAcceptResult = provider.acceptFile(virtualFile); // if (!fileAcceptResult.isAccepted()) { // continue; // } // // return fileAcceptResult; // } // // return FileAcceptResult.NOT_ACCEPTED; // } // }
import org.junit.Test; import ru.adelf.idea.dotenv.api.EnvironmentVariablesApi;
package ru.adelf.idea.dotenv.tests.completions; public class CompletionValuesTest extends BaseCompletionsTest { @Test public void testEnvFunction() {
// Path: src/main/java/ru/adelf/idea/dotenv/api/EnvironmentVariablesApi.java // public class EnvironmentVariablesApi { // // @NotNull // public static Map<String, String> getAllKeyValues(Project project) { // FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance(); // Map<String, String> keyValues = new HashMap<>(); // Map<String, String> secondaryKeyValues = new HashMap<>(); // Map<VirtualFile, FileAcceptResult> resultsCache = new HashMap<>(); // // GlobalSearchScope scope = GlobalSearchScope.allScope(project); // // fileBasedIndex.processAllKeys(DotEnvKeyValuesIndex.KEY, key -> { // for (VirtualFile virtualFile : fileBasedIndex.getContainingFiles(DotEnvKeyValuesIndex.KEY, key, scope)) { // // FileAcceptResult fileAcceptResult; // // if (resultsCache.containsKey(virtualFile)) { // fileAcceptResult = resultsCache.get(virtualFile); // } else { // fileAcceptResult = getFileAcceptResult(virtualFile); // resultsCache.put(virtualFile, fileAcceptResult); // } // // if (!fileAcceptResult.isAccepted()) { // continue; // } // // fileBasedIndex.processValues(DotEnvKeyValuesIndex.KEY, key, virtualFile, ((file, val) -> { // if (fileAcceptResult.isPrimary()) { // keyValues.putIfAbsent(key, val); // } else { // secondaryKeyValues.putIfAbsent(key, val); // } // // return true; // }), scope); // } // // return true; // }, project); // // secondaryKeyValues.putAll(keyValues); // // return secondaryKeyValues; // } // // /** // * @param project project // * @param key environment variable key // * @return All key declarations, in .env files, Dockerfile, docker-compose.yml, etc // */ // @NotNull // public static PsiElement[] getKeyDeclarations(Project project, String key) { // List<PsiElement> targets = new ArrayList<>(); // List<PsiElement> secondaryTargets = new ArrayList<>(); // // FileBasedIndex.getInstance().getFilesWithKey(DotEnvKeyValuesIndex.KEY, new HashSet<>(Collections.singletonList(key)), virtualFile -> { // PsiFile psiFileTarget = PsiManager.getInstance(project).findFile(virtualFile); // if (psiFileTarget == null) { // return true; // } // // for (EnvironmentVariablesProvider provider : EnvironmentVariablesProviderUtil.PROVIDERS) { // FileAcceptResult fileAcceptResult = provider.acceptFile(virtualFile); // if (!fileAcceptResult.isAccepted()) { // continue; // } // // (fileAcceptResult.isPrimary() ? targets : secondaryTargets).addAll(EnvironmentVariablesUtil.getElementsByKey(key, provider.getElements(psiFileTarget))); // } // // return true; // }, GlobalSearchScope.allScope(project)); // // return (targets.size() > 0 ? targets : secondaryTargets).toArray(PsiElement.EMPTY_ARRAY); // } // // /** // * @param project project // * @param key environment variable key // * @return All key usages, like getenv('KEY') // */ // @NotNull // public static PsiElement[] getKeyUsages(Project project, String key) { // List<PsiElement> targets = new ArrayList<>(); // // PsiSearchHelper searchHelper = PsiSearchHelper.getInstance(project); // // Processor<PsiFile> psiFileProcessor = psiFile -> { // for (EnvironmentVariablesUsagesProvider provider : EnvironmentVariablesProviderUtil.USAGES_PROVIDERS) { // targets.addAll(EnvironmentVariablesUtil.getUsagesElementsByKey(key, provider.getUsages(psiFile))); // } // // return true; // }; // // searchHelper.processAllFilesWithWord(key, GlobalSearchScope.allScope(project), psiFileProcessor, true); // searchHelper.processAllFilesWithWordInLiterals(key, GlobalSearchScope.allScope(project), psiFileProcessor); // searchHelper.processAllFilesWithWordInText(key, GlobalSearchScope.allScope(project), psiFileProcessor, true); // // return targets.toArray(PsiElement.EMPTY_ARRAY); // } // // private static FileAcceptResult getFileAcceptResult(VirtualFile virtualFile) { // for (EnvironmentVariablesProvider provider : EnvironmentVariablesProviderUtil.PROVIDERS) { // FileAcceptResult fileAcceptResult = provider.acceptFile(virtualFile); // if (!fileAcceptResult.isAccepted()) { // continue; // } // // return fileAcceptResult; // } // // return FileAcceptResult.NOT_ACCEPTED; // } // } // Path: src/test/java/ru/adelf/idea/dotenv/tests/completions/CompletionValuesTest.java import org.junit.Test; import ru.adelf.idea.dotenv.api.EnvironmentVariablesApi; package ru.adelf.idea.dotenv.tests.completions; public class CompletionValuesTest extends BaseCompletionsTest { @Test public void testEnvFunction() {
var keyValues = EnvironmentVariablesApi.getAllKeyValues(getProject());
adelf/idea-php-dotenv-plugin
src/main/gen/ru/adelf/idea/dotenv/grammars/_DotEnvLexer.java
// Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvTypes.java // public interface DotEnvTypes { // // IElementType KEY = new DotEnvElementType("KEY"); // IElementType PROPERTY = new DotEnvElementType("PROPERTY"); // IElementType VALUE = new DotEnvElementType("VALUE"); // // IElementType COMMENT = new DotEnvTokenType("COMMENT"); // IElementType CRLF = new DotEnvTokenType("CRLF"); // IElementType EXPORT = new DotEnvTokenType("EXPORT"); // IElementType KEY_CHARS = new DotEnvTokenType("KEY_CHARS"); // IElementType QUOTE = new DotEnvTokenType("QUOTE"); // IElementType SEPARATOR = new DotEnvTokenType("SEPARATOR"); // IElementType VALUE_CHARS = new DotEnvTokenType("VALUE_CHARS"); // // class Factory { // public static PsiElement createElement(ASTNode node) { // IElementType type = node.getElementType(); // if (type == KEY) { // return new DotEnvKeyImpl(node); // } // else if (type == PROPERTY) { // return new DotEnvPropertyImpl(node); // } // else if (type == VALUE) { // return new DotEnvValueImpl(node); // } // throw new AssertionError("Unknown element type: " + type); // } // } // }
import com.intellij.lexer.FlexLexer; import com.intellij.psi.TokenType; import com.intellij.psi.tree.IElementType; import ru.adelf.idea.dotenv.psi.DotEnvTypes;
} else { zzInput = Character.codePointAt(zzBufferL, zzCurrentPosL/*, zzEndReadL*/); zzCurrentPosL += Character.charCount(zzInput); } } int zzNext = zzTransL[ zzRowMapL[zzState] + ZZ_CMAP(zzInput) ]; if (zzNext == -1) break zzForAction; zzState = zzNext; zzAttributes = zzAttrL[zzState]; if ( (zzAttributes & 1) == 1 ) { zzAction = zzState; zzMarkedPosL = zzCurrentPosL; if ( (zzAttributes & 8) == 8 ) break zzForAction; } } } // store back cached position zzMarkedPos = zzMarkedPosL; if (zzInput == YYEOF && zzStartRead == zzCurrentPos) { zzAtEOF = true; return null; } else { switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) { case 1:
// Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvTypes.java // public interface DotEnvTypes { // // IElementType KEY = new DotEnvElementType("KEY"); // IElementType PROPERTY = new DotEnvElementType("PROPERTY"); // IElementType VALUE = new DotEnvElementType("VALUE"); // // IElementType COMMENT = new DotEnvTokenType("COMMENT"); // IElementType CRLF = new DotEnvTokenType("CRLF"); // IElementType EXPORT = new DotEnvTokenType("EXPORT"); // IElementType KEY_CHARS = new DotEnvTokenType("KEY_CHARS"); // IElementType QUOTE = new DotEnvTokenType("QUOTE"); // IElementType SEPARATOR = new DotEnvTokenType("SEPARATOR"); // IElementType VALUE_CHARS = new DotEnvTokenType("VALUE_CHARS"); // // class Factory { // public static PsiElement createElement(ASTNode node) { // IElementType type = node.getElementType(); // if (type == KEY) { // return new DotEnvKeyImpl(node); // } // else if (type == PROPERTY) { // return new DotEnvPropertyImpl(node); // } // else if (type == VALUE) { // return new DotEnvValueImpl(node); // } // throw new AssertionError("Unknown element type: " + type); // } // } // } // Path: src/main/gen/ru/adelf/idea/dotenv/grammars/_DotEnvLexer.java import com.intellij.lexer.FlexLexer; import com.intellij.psi.TokenType; import com.intellij.psi.tree.IElementType; import ru.adelf.idea.dotenv.psi.DotEnvTypes; } else { zzInput = Character.codePointAt(zzBufferL, zzCurrentPosL/*, zzEndReadL*/); zzCurrentPosL += Character.charCount(zzInput); } } int zzNext = zzTransL[ zzRowMapL[zzState] + ZZ_CMAP(zzInput) ]; if (zzNext == -1) break zzForAction; zzState = zzNext; zzAttributes = zzAttrL[zzState]; if ( (zzAttributes & 1) == 1 ) { zzAction = zzState; zzMarkedPosL = zzCurrentPosL; if ( (zzAttributes & 8) == 8 ) break zzForAction; } } } // store back cached position zzMarkedPos = zzMarkedPosL; if (zzInput == YYEOF && zzStartRead == zzCurrentPos) { zzAtEOF = true; return null; } else { switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) { case 1:
{ yybegin(YYINITIAL); return DotEnvTypes.KEY_CHARS;
adelf/idea-php-dotenv-plugin
src/main/java/ru/adelf/idea/dotenv/php/PhpEnvironmentVariablesUsagesProvider.java
// Path: src/main/java/ru/adelf/idea/dotenv/api/EnvironmentVariablesUsagesProvider.java // public interface EnvironmentVariablesUsagesProvider { // boolean acceptFile(VirtualFile file); // // @NotNull // Collection<KeyUsagePsiElement> getUsages(PsiFile psiFile); // } // // Path: src/main/java/ru/adelf/idea/dotenv/models/KeyUsagePsiElement.java // public class KeyUsagePsiElement { // // private final String key; // private final PsiElement element; // // public KeyUsagePsiElement(String key, PsiElement element) { // this.key = key; // this.element = element; // } // // public String getKey() { // return key; // } // // public PsiElement getElement() { // return element; // } // }
import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; import com.jetbrains.php.lang.PhpFileType; import com.jetbrains.php.lang.psi.PhpFile; import org.jetbrains.annotations.NotNull; import ru.adelf.idea.dotenv.api.EnvironmentVariablesUsagesProvider; import ru.adelf.idea.dotenv.models.KeyUsagePsiElement; import java.util.Collection; import java.util.Collections;
package ru.adelf.idea.dotenv.php; public class PhpEnvironmentVariablesUsagesProvider implements EnvironmentVariablesUsagesProvider { @Override public boolean acceptFile(VirtualFile file) { return file.getFileType().equals(PhpFileType.INSTANCE); } @NotNull @Override
// Path: src/main/java/ru/adelf/idea/dotenv/api/EnvironmentVariablesUsagesProvider.java // public interface EnvironmentVariablesUsagesProvider { // boolean acceptFile(VirtualFile file); // // @NotNull // Collection<KeyUsagePsiElement> getUsages(PsiFile psiFile); // } // // Path: src/main/java/ru/adelf/idea/dotenv/models/KeyUsagePsiElement.java // public class KeyUsagePsiElement { // // private final String key; // private final PsiElement element; // // public KeyUsagePsiElement(String key, PsiElement element) { // this.key = key; // this.element = element; // } // // public String getKey() { // return key; // } // // public PsiElement getElement() { // return element; // } // } // Path: src/main/java/ru/adelf/idea/dotenv/php/PhpEnvironmentVariablesUsagesProvider.java import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; import com.jetbrains.php.lang.PhpFileType; import com.jetbrains.php.lang.psi.PhpFile; import org.jetbrains.annotations.NotNull; import ru.adelf.idea.dotenv.api.EnvironmentVariablesUsagesProvider; import ru.adelf.idea.dotenv.models.KeyUsagePsiElement; import java.util.Collection; import java.util.Collections; package ru.adelf.idea.dotenv.php; public class PhpEnvironmentVariablesUsagesProvider implements EnvironmentVariablesUsagesProvider { @Override public boolean acceptFile(VirtualFile file) { return file.getFileType().equals(PhpFileType.INSTANCE); } @NotNull @Override
public Collection<KeyUsagePsiElement> getUsages(PsiFile psiFile) {
adelf/idea-php-dotenv-plugin
src/main/java/ru/adelf/idea/dotenv/util/EnvironmentVariablesUtil.java
// Path: src/main/java/ru/adelf/idea/dotenv/models/EnvironmentKeyValue.java // public class EnvironmentKeyValue { // // private final String key; // private final String value; // // public EnvironmentKeyValue(@NotNull String key, @NotNull String value) { // this.key = key; // this.value = value; // } // // @NotNull // public String getKey() { // return key; // } // // @NotNull // public String getValue() { // return value; // } // } // // Path: src/main/java/ru/adelf/idea/dotenv/models/KeyUsagePsiElement.java // public class KeyUsagePsiElement { // // private final String key; // private final PsiElement element; // // public KeyUsagePsiElement(String key, PsiElement element) { // this.key = key; // this.element = element; // } // // public String getKey() { // return key; // } // // public PsiElement getElement() { // return element; // } // } // // Path: src/main/java/ru/adelf/idea/dotenv/models/KeyValuePsiElement.java // public class KeyValuePsiElement { // // private final String key; // private final String value; // private final PsiElement element; // // public KeyValuePsiElement(String key, String value, PsiElement element) { // this.key = key; // this.value = value; // this.element = element; // } // // public String getKey() { // return key.trim(); // } // // public String getShortValue() { // if (value.indexOf('\n') != -1) { // return clearString(value.substring(0, value.indexOf('\n'))) + "..."; // } // // return value.trim(); // } // // private String clearString(String s) { // return StringUtil.trim(s.trim(), ch -> ch != '\\').trim(); // } // // public PsiElement getElement() { // return element; // } // }
import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import ru.adelf.idea.dotenv.models.EnvironmentKeyValue; import ru.adelf.idea.dotenv.models.KeyUsagePsiElement; import ru.adelf.idea.dotenv.models.KeyValuePsiElement; import java.util.Collection; import java.util.Set; import java.util.stream.Collectors;
package ru.adelf.idea.dotenv.util; public class EnvironmentVariablesUtil { @NotNull
// Path: src/main/java/ru/adelf/idea/dotenv/models/EnvironmentKeyValue.java // public class EnvironmentKeyValue { // // private final String key; // private final String value; // // public EnvironmentKeyValue(@NotNull String key, @NotNull String value) { // this.key = key; // this.value = value; // } // // @NotNull // public String getKey() { // return key; // } // // @NotNull // public String getValue() { // return value; // } // } // // Path: src/main/java/ru/adelf/idea/dotenv/models/KeyUsagePsiElement.java // public class KeyUsagePsiElement { // // private final String key; // private final PsiElement element; // // public KeyUsagePsiElement(String key, PsiElement element) { // this.key = key; // this.element = element; // } // // public String getKey() { // return key; // } // // public PsiElement getElement() { // return element; // } // } // // Path: src/main/java/ru/adelf/idea/dotenv/models/KeyValuePsiElement.java // public class KeyValuePsiElement { // // private final String key; // private final String value; // private final PsiElement element; // // public KeyValuePsiElement(String key, String value, PsiElement element) { // this.key = key; // this.value = value; // this.element = element; // } // // public String getKey() { // return key.trim(); // } // // public String getShortValue() { // if (value.indexOf('\n') != -1) { // return clearString(value.substring(0, value.indexOf('\n'))) + "..."; // } // // return value.trim(); // } // // private String clearString(String s) { // return StringUtil.trim(s.trim(), ch -> ch != '\\').trim(); // } // // public PsiElement getElement() { // return element; // } // } // Path: src/main/java/ru/adelf/idea/dotenv/util/EnvironmentVariablesUtil.java import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import ru.adelf.idea.dotenv.models.EnvironmentKeyValue; import ru.adelf.idea.dotenv.models.KeyUsagePsiElement; import ru.adelf.idea.dotenv.models.KeyValuePsiElement; import java.util.Collection; import java.util.Set; import java.util.stream.Collectors; package ru.adelf.idea.dotenv.util; public class EnvironmentVariablesUtil { @NotNull
public static EnvironmentKeyValue getKeyValueFromString(@NotNull String s) {
adelf/idea-php-dotenv-plugin
src/main/java/ru/adelf/idea/dotenv/util/EnvironmentVariablesUtil.java
// Path: src/main/java/ru/adelf/idea/dotenv/models/EnvironmentKeyValue.java // public class EnvironmentKeyValue { // // private final String key; // private final String value; // // public EnvironmentKeyValue(@NotNull String key, @NotNull String value) { // this.key = key; // this.value = value; // } // // @NotNull // public String getKey() { // return key; // } // // @NotNull // public String getValue() { // return value; // } // } // // Path: src/main/java/ru/adelf/idea/dotenv/models/KeyUsagePsiElement.java // public class KeyUsagePsiElement { // // private final String key; // private final PsiElement element; // // public KeyUsagePsiElement(String key, PsiElement element) { // this.key = key; // this.element = element; // } // // public String getKey() { // return key; // } // // public PsiElement getElement() { // return element; // } // } // // Path: src/main/java/ru/adelf/idea/dotenv/models/KeyValuePsiElement.java // public class KeyValuePsiElement { // // private final String key; // private final String value; // private final PsiElement element; // // public KeyValuePsiElement(String key, String value, PsiElement element) { // this.key = key; // this.value = value; // this.element = element; // } // // public String getKey() { // return key.trim(); // } // // public String getShortValue() { // if (value.indexOf('\n') != -1) { // return clearString(value.substring(0, value.indexOf('\n'))) + "..."; // } // // return value.trim(); // } // // private String clearString(String s) { // return StringUtil.trim(s.trim(), ch -> ch != '\\').trim(); // } // // public PsiElement getElement() { // return element; // } // }
import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import ru.adelf.idea.dotenv.models.EnvironmentKeyValue; import ru.adelf.idea.dotenv.models.KeyUsagePsiElement; import ru.adelf.idea.dotenv.models.KeyValuePsiElement; import java.util.Collection; import java.util.Set; import java.util.stream.Collectors;
package ru.adelf.idea.dotenv.util; public class EnvironmentVariablesUtil { @NotNull public static EnvironmentKeyValue getKeyValueFromString(@NotNull String s) { int pos = s.indexOf("="); if(pos == -1) { return new EnvironmentKeyValue(s.trim(), ""); } else { return new EnvironmentKeyValue(s.substring(0, pos).trim(), s.substring(pos + 1).trim()); } } @NotNull public static String getKeyFromString(@NotNull String s) { int pos = s.indexOf("="); if(pos == -1) { return s.trim(); } else { return s.substring(0, pos).trim(); } } @NotNull
// Path: src/main/java/ru/adelf/idea/dotenv/models/EnvironmentKeyValue.java // public class EnvironmentKeyValue { // // private final String key; // private final String value; // // public EnvironmentKeyValue(@NotNull String key, @NotNull String value) { // this.key = key; // this.value = value; // } // // @NotNull // public String getKey() { // return key; // } // // @NotNull // public String getValue() { // return value; // } // } // // Path: src/main/java/ru/adelf/idea/dotenv/models/KeyUsagePsiElement.java // public class KeyUsagePsiElement { // // private final String key; // private final PsiElement element; // // public KeyUsagePsiElement(String key, PsiElement element) { // this.key = key; // this.element = element; // } // // public String getKey() { // return key; // } // // public PsiElement getElement() { // return element; // } // } // // Path: src/main/java/ru/adelf/idea/dotenv/models/KeyValuePsiElement.java // public class KeyValuePsiElement { // // private final String key; // private final String value; // private final PsiElement element; // // public KeyValuePsiElement(String key, String value, PsiElement element) { // this.key = key; // this.value = value; // this.element = element; // } // // public String getKey() { // return key.trim(); // } // // public String getShortValue() { // if (value.indexOf('\n') != -1) { // return clearString(value.substring(0, value.indexOf('\n'))) + "..."; // } // // return value.trim(); // } // // private String clearString(String s) { // return StringUtil.trim(s.trim(), ch -> ch != '\\').trim(); // } // // public PsiElement getElement() { // return element; // } // } // Path: src/main/java/ru/adelf/idea/dotenv/util/EnvironmentVariablesUtil.java import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import ru.adelf.idea.dotenv.models.EnvironmentKeyValue; import ru.adelf.idea.dotenv.models.KeyUsagePsiElement; import ru.adelf.idea.dotenv.models.KeyValuePsiElement; import java.util.Collection; import java.util.Set; import java.util.stream.Collectors; package ru.adelf.idea.dotenv.util; public class EnvironmentVariablesUtil { @NotNull public static EnvironmentKeyValue getKeyValueFromString(@NotNull String s) { int pos = s.indexOf("="); if(pos == -1) { return new EnvironmentKeyValue(s.trim(), ""); } else { return new EnvironmentKeyValue(s.substring(0, pos).trim(), s.substring(pos + 1).trim()); } } @NotNull public static String getKeyFromString(@NotNull String s) { int pos = s.indexOf("="); if(pos == -1) { return s.trim(); } else { return s.substring(0, pos).trim(); } } @NotNull
public static Set<PsiElement> getElementsByKey(String key, Collection<KeyValuePsiElement> items) {
adelf/idea-php-dotenv-plugin
src/main/java/ru/adelf/idea/dotenv/util/EnvironmentVariablesUtil.java
// Path: src/main/java/ru/adelf/idea/dotenv/models/EnvironmentKeyValue.java // public class EnvironmentKeyValue { // // private final String key; // private final String value; // // public EnvironmentKeyValue(@NotNull String key, @NotNull String value) { // this.key = key; // this.value = value; // } // // @NotNull // public String getKey() { // return key; // } // // @NotNull // public String getValue() { // return value; // } // } // // Path: src/main/java/ru/adelf/idea/dotenv/models/KeyUsagePsiElement.java // public class KeyUsagePsiElement { // // private final String key; // private final PsiElement element; // // public KeyUsagePsiElement(String key, PsiElement element) { // this.key = key; // this.element = element; // } // // public String getKey() { // return key; // } // // public PsiElement getElement() { // return element; // } // } // // Path: src/main/java/ru/adelf/idea/dotenv/models/KeyValuePsiElement.java // public class KeyValuePsiElement { // // private final String key; // private final String value; // private final PsiElement element; // // public KeyValuePsiElement(String key, String value, PsiElement element) { // this.key = key; // this.value = value; // this.element = element; // } // // public String getKey() { // return key.trim(); // } // // public String getShortValue() { // if (value.indexOf('\n') != -1) { // return clearString(value.substring(0, value.indexOf('\n'))) + "..."; // } // // return value.trim(); // } // // private String clearString(String s) { // return StringUtil.trim(s.trim(), ch -> ch != '\\').trim(); // } // // public PsiElement getElement() { // return element; // } // }
import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import ru.adelf.idea.dotenv.models.EnvironmentKeyValue; import ru.adelf.idea.dotenv.models.KeyUsagePsiElement; import ru.adelf.idea.dotenv.models.KeyValuePsiElement; import java.util.Collection; import java.util.Set; import java.util.stream.Collectors;
package ru.adelf.idea.dotenv.util; public class EnvironmentVariablesUtil { @NotNull public static EnvironmentKeyValue getKeyValueFromString(@NotNull String s) { int pos = s.indexOf("="); if(pos == -1) { return new EnvironmentKeyValue(s.trim(), ""); } else { return new EnvironmentKeyValue(s.substring(0, pos).trim(), s.substring(pos + 1).trim()); } } @NotNull public static String getKeyFromString(@NotNull String s) { int pos = s.indexOf("="); if(pos == -1) { return s.trim(); } else { return s.substring(0, pos).trim(); } } @NotNull public static Set<PsiElement> getElementsByKey(String key, Collection<KeyValuePsiElement> items) { return items.stream().filter(item -> item.getKey().equals(key)).map(KeyValuePsiElement::getElement).collect(Collectors.toSet()); } @NotNull
// Path: src/main/java/ru/adelf/idea/dotenv/models/EnvironmentKeyValue.java // public class EnvironmentKeyValue { // // private final String key; // private final String value; // // public EnvironmentKeyValue(@NotNull String key, @NotNull String value) { // this.key = key; // this.value = value; // } // // @NotNull // public String getKey() { // return key; // } // // @NotNull // public String getValue() { // return value; // } // } // // Path: src/main/java/ru/adelf/idea/dotenv/models/KeyUsagePsiElement.java // public class KeyUsagePsiElement { // // private final String key; // private final PsiElement element; // // public KeyUsagePsiElement(String key, PsiElement element) { // this.key = key; // this.element = element; // } // // public String getKey() { // return key; // } // // public PsiElement getElement() { // return element; // } // } // // Path: src/main/java/ru/adelf/idea/dotenv/models/KeyValuePsiElement.java // public class KeyValuePsiElement { // // private final String key; // private final String value; // private final PsiElement element; // // public KeyValuePsiElement(String key, String value, PsiElement element) { // this.key = key; // this.value = value; // this.element = element; // } // // public String getKey() { // return key.trim(); // } // // public String getShortValue() { // if (value.indexOf('\n') != -1) { // return clearString(value.substring(0, value.indexOf('\n'))) + "..."; // } // // return value.trim(); // } // // private String clearString(String s) { // return StringUtil.trim(s.trim(), ch -> ch != '\\').trim(); // } // // public PsiElement getElement() { // return element; // } // } // Path: src/main/java/ru/adelf/idea/dotenv/util/EnvironmentVariablesUtil.java import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import ru.adelf.idea.dotenv.models.EnvironmentKeyValue; import ru.adelf.idea.dotenv.models.KeyUsagePsiElement; import ru.adelf.idea.dotenv.models.KeyValuePsiElement; import java.util.Collection; import java.util.Set; import java.util.stream.Collectors; package ru.adelf.idea.dotenv.util; public class EnvironmentVariablesUtil { @NotNull public static EnvironmentKeyValue getKeyValueFromString(@NotNull String s) { int pos = s.indexOf("="); if(pos == -1) { return new EnvironmentKeyValue(s.trim(), ""); } else { return new EnvironmentKeyValue(s.substring(0, pos).trim(), s.substring(pos + 1).trim()); } } @NotNull public static String getKeyFromString(@NotNull String s) { int pos = s.indexOf("="); if(pos == -1) { return s.trim(); } else { return s.substring(0, pos).trim(); } } @NotNull public static Set<PsiElement> getElementsByKey(String key, Collection<KeyValuePsiElement> items) { return items.stream().filter(item -> item.getKey().equals(key)).map(KeyValuePsiElement::getElement).collect(Collectors.toSet()); } @NotNull
public static Set<PsiElement> getUsagesElementsByKey(String key, Collection<KeyUsagePsiElement> items) {
adelf/idea-php-dotenv-plugin
src/main/java/ru/adelf/idea/dotenv/inspections/ExtraBlankLineInspection.java
// Path: src/main/java/ru/adelf/idea/dotenv/DotEnvFactory.java // public class DotEnvFactory { // public static PsiElement createFromText(@NotNull Project project, @NotNull IElementType type, @NotNull String text) { // final Ref<PsiElement> ret = new Ref<>(); // PsiFile dummyFile = createDummyFile(project, text); // dummyFile.accept(new PsiRecursiveElementWalkingVisitor() { // public void visitElement(@NotNull PsiElement element) { // ASTNode node = element.getNode(); // if (node != null && node.getElementType() == type) { // ret.set(element); // stopWalking(); // } else { // super.visitElement(element); // } // } // }); // // assert !ret.isNull() : "cannot create element from text:\n" + dummyFile.getText(); // // return ret.get(); // } // // @NotNull // private static PsiFile createDummyFile(Project project, String fileText) { // return PsiFileFactory.getInstance(project).createFileFromText("DUMMY__.env", DotEnvFileType.INSTANCE, fileText, System.currentTimeMillis(), false); // } // } // // Path: src/main/java/ru/adelf/idea/dotenv/psi/DotEnvFile.java // public class DotEnvFile extends PsiFileBase { // public DotEnvFile(@NotNull FileViewProvider viewProvider) { // super(viewProvider, DotEnvLanguage.INSTANCE); // } // // @NotNull // @Override // public FileType getFileType() { // return DotEnvFileType.INSTANCE; // } // // @Override // public String toString() { // return ".env file"; // } // // @Override // public Icon getIcon(int flags) { // return super.getIcon(flags); // } // } // // Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvTypes.java // public interface DotEnvTypes { // // IElementType KEY = new DotEnvElementType("KEY"); // IElementType PROPERTY = new DotEnvElementType("PROPERTY"); // IElementType VALUE = new DotEnvElementType("VALUE"); // // IElementType COMMENT = new DotEnvTokenType("COMMENT"); // IElementType CRLF = new DotEnvTokenType("CRLF"); // IElementType EXPORT = new DotEnvTokenType("EXPORT"); // IElementType KEY_CHARS = new DotEnvTokenType("KEY_CHARS"); // IElementType QUOTE = new DotEnvTokenType("QUOTE"); // IElementType SEPARATOR = new DotEnvTokenType("SEPARATOR"); // IElementType VALUE_CHARS = new DotEnvTokenType("VALUE_CHARS"); // // class Factory { // public static PsiElement createElement(ASTNode node) { // IElementType type = node.getElementType(); // if (type == KEY) { // return new DotEnvKeyImpl(node); // } // else if (type == PROPERTY) { // return new DotEnvPropertyImpl(node); // } // else if (type == VALUE) { // return new DotEnvValueImpl(node); // } // throw new AssertionError("Unknown element type: " + type); // } // } // }
import com.intellij.codeInspection.*; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.TokenType; import com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import ru.adelf.idea.dotenv.DotEnvFactory; import ru.adelf.idea.dotenv.psi.DotEnvFile; import ru.adelf.idea.dotenv.psi.DotEnvTypes; import java.util.regex.Matcher; import java.util.regex.Pattern;
package ru.adelf.idea.dotenv.inspections; public class ExtraBlankLineInspection extends LocalInspectionTool { // Change the display name within the plugin.xml // This needs to be here as otherwise the tests will throw errors. @NotNull @Override public String getDisplayName() { return "Extra blank line"; } @Override public boolean runForWholeFile() { return true; } @Nullable @Override public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
// Path: src/main/java/ru/adelf/idea/dotenv/DotEnvFactory.java // public class DotEnvFactory { // public static PsiElement createFromText(@NotNull Project project, @NotNull IElementType type, @NotNull String text) { // final Ref<PsiElement> ret = new Ref<>(); // PsiFile dummyFile = createDummyFile(project, text); // dummyFile.accept(new PsiRecursiveElementWalkingVisitor() { // public void visitElement(@NotNull PsiElement element) { // ASTNode node = element.getNode(); // if (node != null && node.getElementType() == type) { // ret.set(element); // stopWalking(); // } else { // super.visitElement(element); // } // } // }); // // assert !ret.isNull() : "cannot create element from text:\n" + dummyFile.getText(); // // return ret.get(); // } // // @NotNull // private static PsiFile createDummyFile(Project project, String fileText) { // return PsiFileFactory.getInstance(project).createFileFromText("DUMMY__.env", DotEnvFileType.INSTANCE, fileText, System.currentTimeMillis(), false); // } // } // // Path: src/main/java/ru/adelf/idea/dotenv/psi/DotEnvFile.java // public class DotEnvFile extends PsiFileBase { // public DotEnvFile(@NotNull FileViewProvider viewProvider) { // super(viewProvider, DotEnvLanguage.INSTANCE); // } // // @NotNull // @Override // public FileType getFileType() { // return DotEnvFileType.INSTANCE; // } // // @Override // public String toString() { // return ".env file"; // } // // @Override // public Icon getIcon(int flags) { // return super.getIcon(flags); // } // } // // Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvTypes.java // public interface DotEnvTypes { // // IElementType KEY = new DotEnvElementType("KEY"); // IElementType PROPERTY = new DotEnvElementType("PROPERTY"); // IElementType VALUE = new DotEnvElementType("VALUE"); // // IElementType COMMENT = new DotEnvTokenType("COMMENT"); // IElementType CRLF = new DotEnvTokenType("CRLF"); // IElementType EXPORT = new DotEnvTokenType("EXPORT"); // IElementType KEY_CHARS = new DotEnvTokenType("KEY_CHARS"); // IElementType QUOTE = new DotEnvTokenType("QUOTE"); // IElementType SEPARATOR = new DotEnvTokenType("SEPARATOR"); // IElementType VALUE_CHARS = new DotEnvTokenType("VALUE_CHARS"); // // class Factory { // public static PsiElement createElement(ASTNode node) { // IElementType type = node.getElementType(); // if (type == KEY) { // return new DotEnvKeyImpl(node); // } // else if (type == PROPERTY) { // return new DotEnvPropertyImpl(node); // } // else if (type == VALUE) { // return new DotEnvValueImpl(node); // } // throw new AssertionError("Unknown element type: " + type); // } // } // } // Path: src/main/java/ru/adelf/idea/dotenv/inspections/ExtraBlankLineInspection.java import com.intellij.codeInspection.*; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.TokenType; import com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import ru.adelf.idea.dotenv.DotEnvFactory; import ru.adelf.idea.dotenv.psi.DotEnvFile; import ru.adelf.idea.dotenv.psi.DotEnvTypes; import java.util.regex.Matcher; import java.util.regex.Pattern; package ru.adelf.idea.dotenv.inspections; public class ExtraBlankLineInspection extends LocalInspectionTool { // Change the display name within the plugin.xml // This needs to be here as otherwise the tests will throw errors. @NotNull @Override public String getDisplayName() { return "Extra blank line"; } @Override public boolean runForWholeFile() { return true; } @Nullable @Override public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
if (!(file instanceof DotEnvFile)) {
adelf/idea-php-dotenv-plugin
src/main/java/ru/adelf/idea/dotenv/inspections/ExtraBlankLineInspection.java
// Path: src/main/java/ru/adelf/idea/dotenv/DotEnvFactory.java // public class DotEnvFactory { // public static PsiElement createFromText(@NotNull Project project, @NotNull IElementType type, @NotNull String text) { // final Ref<PsiElement> ret = new Ref<>(); // PsiFile dummyFile = createDummyFile(project, text); // dummyFile.accept(new PsiRecursiveElementWalkingVisitor() { // public void visitElement(@NotNull PsiElement element) { // ASTNode node = element.getNode(); // if (node != null && node.getElementType() == type) { // ret.set(element); // stopWalking(); // } else { // super.visitElement(element); // } // } // }); // // assert !ret.isNull() : "cannot create element from text:\n" + dummyFile.getText(); // // return ret.get(); // } // // @NotNull // private static PsiFile createDummyFile(Project project, String fileText) { // return PsiFileFactory.getInstance(project).createFileFromText("DUMMY__.env", DotEnvFileType.INSTANCE, fileText, System.currentTimeMillis(), false); // } // } // // Path: src/main/java/ru/adelf/idea/dotenv/psi/DotEnvFile.java // public class DotEnvFile extends PsiFileBase { // public DotEnvFile(@NotNull FileViewProvider viewProvider) { // super(viewProvider, DotEnvLanguage.INSTANCE); // } // // @NotNull // @Override // public FileType getFileType() { // return DotEnvFileType.INSTANCE; // } // // @Override // public String toString() { // return ".env file"; // } // // @Override // public Icon getIcon(int flags) { // return super.getIcon(flags); // } // } // // Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvTypes.java // public interface DotEnvTypes { // // IElementType KEY = new DotEnvElementType("KEY"); // IElementType PROPERTY = new DotEnvElementType("PROPERTY"); // IElementType VALUE = new DotEnvElementType("VALUE"); // // IElementType COMMENT = new DotEnvTokenType("COMMENT"); // IElementType CRLF = new DotEnvTokenType("CRLF"); // IElementType EXPORT = new DotEnvTokenType("EXPORT"); // IElementType KEY_CHARS = new DotEnvTokenType("KEY_CHARS"); // IElementType QUOTE = new DotEnvTokenType("QUOTE"); // IElementType SEPARATOR = new DotEnvTokenType("SEPARATOR"); // IElementType VALUE_CHARS = new DotEnvTokenType("VALUE_CHARS"); // // class Factory { // public static PsiElement createElement(ASTNode node) { // IElementType type = node.getElementType(); // if (type == KEY) { // return new DotEnvKeyImpl(node); // } // else if (type == PROPERTY) { // return new DotEnvPropertyImpl(node); // } // else if (type == VALUE) { // return new DotEnvValueImpl(node); // } // throw new AssertionError("Unknown element type: " + type); // } // } // }
import com.intellij.codeInspection.*; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.TokenType; import com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import ru.adelf.idea.dotenv.DotEnvFactory; import ru.adelf.idea.dotenv.psi.DotEnvFile; import ru.adelf.idea.dotenv.psi.DotEnvTypes; import java.util.regex.Matcher; import java.util.regex.Pattern;
PsiTreeUtil.findChildrenOfType(file, PsiWhiteSpaceImpl.class).forEach(whiteSpace -> { Pattern pattern = Pattern.compile("\r\n|\r|\n"); Matcher matcher = pattern.matcher(whiteSpace.getText()); int count = 0; while (matcher.find()) count++; if (count > 2) { problemsHolder.registerProblem(whiteSpace, "Only one extra line allowed between properties", new RemoveExtraBlankLineQuickFix()); } }); return problemsHolder; } private static class RemoveExtraBlankLineQuickFix implements LocalQuickFix { @NotNull @Override public String getName() { return "Remove extra blank line"; } public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { try { PsiElement psiElement = descriptor.getPsiElement();
// Path: src/main/java/ru/adelf/idea/dotenv/DotEnvFactory.java // public class DotEnvFactory { // public static PsiElement createFromText(@NotNull Project project, @NotNull IElementType type, @NotNull String text) { // final Ref<PsiElement> ret = new Ref<>(); // PsiFile dummyFile = createDummyFile(project, text); // dummyFile.accept(new PsiRecursiveElementWalkingVisitor() { // public void visitElement(@NotNull PsiElement element) { // ASTNode node = element.getNode(); // if (node != null && node.getElementType() == type) { // ret.set(element); // stopWalking(); // } else { // super.visitElement(element); // } // } // }); // // assert !ret.isNull() : "cannot create element from text:\n" + dummyFile.getText(); // // return ret.get(); // } // // @NotNull // private static PsiFile createDummyFile(Project project, String fileText) { // return PsiFileFactory.getInstance(project).createFileFromText("DUMMY__.env", DotEnvFileType.INSTANCE, fileText, System.currentTimeMillis(), false); // } // } // // Path: src/main/java/ru/adelf/idea/dotenv/psi/DotEnvFile.java // public class DotEnvFile extends PsiFileBase { // public DotEnvFile(@NotNull FileViewProvider viewProvider) { // super(viewProvider, DotEnvLanguage.INSTANCE); // } // // @NotNull // @Override // public FileType getFileType() { // return DotEnvFileType.INSTANCE; // } // // @Override // public String toString() { // return ".env file"; // } // // @Override // public Icon getIcon(int flags) { // return super.getIcon(flags); // } // } // // Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvTypes.java // public interface DotEnvTypes { // // IElementType KEY = new DotEnvElementType("KEY"); // IElementType PROPERTY = new DotEnvElementType("PROPERTY"); // IElementType VALUE = new DotEnvElementType("VALUE"); // // IElementType COMMENT = new DotEnvTokenType("COMMENT"); // IElementType CRLF = new DotEnvTokenType("CRLF"); // IElementType EXPORT = new DotEnvTokenType("EXPORT"); // IElementType KEY_CHARS = new DotEnvTokenType("KEY_CHARS"); // IElementType QUOTE = new DotEnvTokenType("QUOTE"); // IElementType SEPARATOR = new DotEnvTokenType("SEPARATOR"); // IElementType VALUE_CHARS = new DotEnvTokenType("VALUE_CHARS"); // // class Factory { // public static PsiElement createElement(ASTNode node) { // IElementType type = node.getElementType(); // if (type == KEY) { // return new DotEnvKeyImpl(node); // } // else if (type == PROPERTY) { // return new DotEnvPropertyImpl(node); // } // else if (type == VALUE) { // return new DotEnvValueImpl(node); // } // throw new AssertionError("Unknown element type: " + type); // } // } // } // Path: src/main/java/ru/adelf/idea/dotenv/inspections/ExtraBlankLineInspection.java import com.intellij.codeInspection.*; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.TokenType; import com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import ru.adelf.idea.dotenv.DotEnvFactory; import ru.adelf.idea.dotenv.psi.DotEnvFile; import ru.adelf.idea.dotenv.psi.DotEnvTypes; import java.util.regex.Matcher; import java.util.regex.Pattern; PsiTreeUtil.findChildrenOfType(file, PsiWhiteSpaceImpl.class).forEach(whiteSpace -> { Pattern pattern = Pattern.compile("\r\n|\r|\n"); Matcher matcher = pattern.matcher(whiteSpace.getText()); int count = 0; while (matcher.find()) count++; if (count > 2) { problemsHolder.registerProblem(whiteSpace, "Only one extra line allowed between properties", new RemoveExtraBlankLineQuickFix()); } }); return problemsHolder; } private static class RemoveExtraBlankLineQuickFix implements LocalQuickFix { @NotNull @Override public String getName() { return "Remove extra blank line"; } public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { try { PsiElement psiElement = descriptor.getPsiElement();
PsiElement newPsiElement = DotEnvFactory.createFromText(project, TokenType.WHITE_SPACE, "\n\n");
adelf/idea-php-dotenv-plugin
src/main/java/ru/adelf/idea/dotenv/psi/DotEnvElementFactory.java
// Path: src/main/java/ru/adelf/idea/dotenv/DotEnvFileType.java // public class DotEnvFileType extends LanguageFileType { // public static final DotEnvFileType INSTANCE = new DotEnvFileType(); // // private DotEnvFileType() { // super(DotEnvLanguage.INSTANCE); // } // // @NotNull // @Override // public String getName() { // return ".env file"; // } // // @NotNull // @Override // public String getDescription() { // return ".env file"; // } // // @NotNull // @Override // public String getDefaultExtension() { // return "env"; // } // // @Nullable // @Override // public Icon getIcon() { // return AllIcons.FileTypes.Text; // } // }
import com.intellij.openapi.project.Project; import com.intellij.psi.PsiFileFactory; import ru.adelf.idea.dotenv.DotEnvFileType;
package ru.adelf.idea.dotenv.psi; class DotEnvElementFactory { static DotEnvProperty createProperty(Project project, String name) { final DotEnvFile file = createFile(project, name); return (DotEnvProperty) file.getFirstChild(); } private static DotEnvFile createFile(Project project, String text) { String name = "dummy.env"; return (DotEnvFile) PsiFileFactory.getInstance(project).
// Path: src/main/java/ru/adelf/idea/dotenv/DotEnvFileType.java // public class DotEnvFileType extends LanguageFileType { // public static final DotEnvFileType INSTANCE = new DotEnvFileType(); // // private DotEnvFileType() { // super(DotEnvLanguage.INSTANCE); // } // // @NotNull // @Override // public String getName() { // return ".env file"; // } // // @NotNull // @Override // public String getDescription() { // return ".env file"; // } // // @NotNull // @Override // public String getDefaultExtension() { // return "env"; // } // // @Nullable // @Override // public Icon getIcon() { // return AllIcons.FileTypes.Text; // } // } // Path: src/main/java/ru/adelf/idea/dotenv/psi/DotEnvElementFactory.java import com.intellij.openapi.project.Project; import com.intellij.psi.PsiFileFactory; import ru.adelf.idea.dotenv.DotEnvFileType; package ru.adelf.idea.dotenv.psi; class DotEnvElementFactory { static DotEnvProperty createProperty(Project project, String name) { final DotEnvFile file = createFile(project, name); return (DotEnvProperty) file.getFirstChild(); } private static DotEnvFile createFile(Project project, String text) { String name = "dummy.env"; return (DotEnvFile) PsiFileFactory.getInstance(project).
createFileFromText(name, DotEnvFileType.INSTANCE, text);
adelf/idea-php-dotenv-plugin
src/main/java/ru/adelf/idea/dotenv/inspections/LowercaseKeyInspection.java
// Path: src/main/java/ru/adelf/idea/dotenv/DotEnvFactory.java // public class DotEnvFactory { // public static PsiElement createFromText(@NotNull Project project, @NotNull IElementType type, @NotNull String text) { // final Ref<PsiElement> ret = new Ref<>(); // PsiFile dummyFile = createDummyFile(project, text); // dummyFile.accept(new PsiRecursiveElementWalkingVisitor() { // public void visitElement(@NotNull PsiElement element) { // ASTNode node = element.getNode(); // if (node != null && node.getElementType() == type) { // ret.set(element); // stopWalking(); // } else { // super.visitElement(element); // } // } // }); // // assert !ret.isNull() : "cannot create element from text:\n" + dummyFile.getText(); // // return ret.get(); // } // // @NotNull // private static PsiFile createDummyFile(Project project, String fileText) { // return PsiFileFactory.getInstance(project).createFileFromText("DUMMY__.env", DotEnvFileType.INSTANCE, fileText, System.currentTimeMillis(), false); // } // } // // Path: src/main/java/ru/adelf/idea/dotenv/psi/DotEnvFile.java // public class DotEnvFile extends PsiFileBase { // public DotEnvFile(@NotNull FileViewProvider viewProvider) { // super(viewProvider, DotEnvLanguage.INSTANCE); // } // // @NotNull // @Override // public FileType getFileType() { // return DotEnvFileType.INSTANCE; // } // // @Override // public String toString() { // return ".env file"; // } // // @Override // public Icon getIcon(int flags) { // return super.getIcon(flags); // } // } // // Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvKey.java // public interface DotEnvKey extends PsiElement { // // } // // Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvTypes.java // public interface DotEnvTypes { // // IElementType KEY = new DotEnvElementType("KEY"); // IElementType PROPERTY = new DotEnvElementType("PROPERTY"); // IElementType VALUE = new DotEnvElementType("VALUE"); // // IElementType COMMENT = new DotEnvTokenType("COMMENT"); // IElementType CRLF = new DotEnvTokenType("CRLF"); // IElementType EXPORT = new DotEnvTokenType("EXPORT"); // IElementType KEY_CHARS = new DotEnvTokenType("KEY_CHARS"); // IElementType QUOTE = new DotEnvTokenType("QUOTE"); // IElementType SEPARATOR = new DotEnvTokenType("SEPARATOR"); // IElementType VALUE_CHARS = new DotEnvTokenType("VALUE_CHARS"); // // class Factory { // public static PsiElement createElement(ASTNode node) { // IElementType type = node.getElementType(); // if (type == KEY) { // return new DotEnvKeyImpl(node); // } // else if (type == PROPERTY) { // return new DotEnvPropertyImpl(node); // } // else if (type == VALUE) { // return new DotEnvValueImpl(node); // } // throw new AssertionError("Unknown element type: " + type); // } // } // }
import com.intellij.codeInspection.*; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import ru.adelf.idea.dotenv.DotEnvFactory; import ru.adelf.idea.dotenv.psi.DotEnvFile; import ru.adelf.idea.dotenv.psi.DotEnvKey; import ru.adelf.idea.dotenv.psi.DotEnvTypes;
package ru.adelf.idea.dotenv.inspections; public class LowercaseKeyInspection extends LocalInspectionTool { // Change the display name within the plugin.xml // This needs to be here as otherwise the tests will throw errors. @NotNull @Override public String getDisplayName() { return "Key uses lowercase chars"; } @Nullable @Override public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
// Path: src/main/java/ru/adelf/idea/dotenv/DotEnvFactory.java // public class DotEnvFactory { // public static PsiElement createFromText(@NotNull Project project, @NotNull IElementType type, @NotNull String text) { // final Ref<PsiElement> ret = new Ref<>(); // PsiFile dummyFile = createDummyFile(project, text); // dummyFile.accept(new PsiRecursiveElementWalkingVisitor() { // public void visitElement(@NotNull PsiElement element) { // ASTNode node = element.getNode(); // if (node != null && node.getElementType() == type) { // ret.set(element); // stopWalking(); // } else { // super.visitElement(element); // } // } // }); // // assert !ret.isNull() : "cannot create element from text:\n" + dummyFile.getText(); // // return ret.get(); // } // // @NotNull // private static PsiFile createDummyFile(Project project, String fileText) { // return PsiFileFactory.getInstance(project).createFileFromText("DUMMY__.env", DotEnvFileType.INSTANCE, fileText, System.currentTimeMillis(), false); // } // } // // Path: src/main/java/ru/adelf/idea/dotenv/psi/DotEnvFile.java // public class DotEnvFile extends PsiFileBase { // public DotEnvFile(@NotNull FileViewProvider viewProvider) { // super(viewProvider, DotEnvLanguage.INSTANCE); // } // // @NotNull // @Override // public FileType getFileType() { // return DotEnvFileType.INSTANCE; // } // // @Override // public String toString() { // return ".env file"; // } // // @Override // public Icon getIcon(int flags) { // return super.getIcon(flags); // } // } // // Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvKey.java // public interface DotEnvKey extends PsiElement { // // } // // Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvTypes.java // public interface DotEnvTypes { // // IElementType KEY = new DotEnvElementType("KEY"); // IElementType PROPERTY = new DotEnvElementType("PROPERTY"); // IElementType VALUE = new DotEnvElementType("VALUE"); // // IElementType COMMENT = new DotEnvTokenType("COMMENT"); // IElementType CRLF = new DotEnvTokenType("CRLF"); // IElementType EXPORT = new DotEnvTokenType("EXPORT"); // IElementType KEY_CHARS = new DotEnvTokenType("KEY_CHARS"); // IElementType QUOTE = new DotEnvTokenType("QUOTE"); // IElementType SEPARATOR = new DotEnvTokenType("SEPARATOR"); // IElementType VALUE_CHARS = new DotEnvTokenType("VALUE_CHARS"); // // class Factory { // public static PsiElement createElement(ASTNode node) { // IElementType type = node.getElementType(); // if (type == KEY) { // return new DotEnvKeyImpl(node); // } // else if (type == PROPERTY) { // return new DotEnvPropertyImpl(node); // } // else if (type == VALUE) { // return new DotEnvValueImpl(node); // } // throw new AssertionError("Unknown element type: " + type); // } // } // } // Path: src/main/java/ru/adelf/idea/dotenv/inspections/LowercaseKeyInspection.java import com.intellij.codeInspection.*; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import ru.adelf.idea.dotenv.DotEnvFactory; import ru.adelf.idea.dotenv.psi.DotEnvFile; import ru.adelf.idea.dotenv.psi.DotEnvKey; import ru.adelf.idea.dotenv.psi.DotEnvTypes; package ru.adelf.idea.dotenv.inspections; public class LowercaseKeyInspection extends LocalInspectionTool { // Change the display name within the plugin.xml // This needs to be here as otherwise the tests will throw errors. @NotNull @Override public String getDisplayName() { return "Key uses lowercase chars"; } @Nullable @Override public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
if (!(file instanceof DotEnvFile)) {
adelf/idea-php-dotenv-plugin
src/main/java/ru/adelf/idea/dotenv/inspections/LowercaseKeyInspection.java
// Path: src/main/java/ru/adelf/idea/dotenv/DotEnvFactory.java // public class DotEnvFactory { // public static PsiElement createFromText(@NotNull Project project, @NotNull IElementType type, @NotNull String text) { // final Ref<PsiElement> ret = new Ref<>(); // PsiFile dummyFile = createDummyFile(project, text); // dummyFile.accept(new PsiRecursiveElementWalkingVisitor() { // public void visitElement(@NotNull PsiElement element) { // ASTNode node = element.getNode(); // if (node != null && node.getElementType() == type) { // ret.set(element); // stopWalking(); // } else { // super.visitElement(element); // } // } // }); // // assert !ret.isNull() : "cannot create element from text:\n" + dummyFile.getText(); // // return ret.get(); // } // // @NotNull // private static PsiFile createDummyFile(Project project, String fileText) { // return PsiFileFactory.getInstance(project).createFileFromText("DUMMY__.env", DotEnvFileType.INSTANCE, fileText, System.currentTimeMillis(), false); // } // } // // Path: src/main/java/ru/adelf/idea/dotenv/psi/DotEnvFile.java // public class DotEnvFile extends PsiFileBase { // public DotEnvFile(@NotNull FileViewProvider viewProvider) { // super(viewProvider, DotEnvLanguage.INSTANCE); // } // // @NotNull // @Override // public FileType getFileType() { // return DotEnvFileType.INSTANCE; // } // // @Override // public String toString() { // return ".env file"; // } // // @Override // public Icon getIcon(int flags) { // return super.getIcon(flags); // } // } // // Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvKey.java // public interface DotEnvKey extends PsiElement { // // } // // Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvTypes.java // public interface DotEnvTypes { // // IElementType KEY = new DotEnvElementType("KEY"); // IElementType PROPERTY = new DotEnvElementType("PROPERTY"); // IElementType VALUE = new DotEnvElementType("VALUE"); // // IElementType COMMENT = new DotEnvTokenType("COMMENT"); // IElementType CRLF = new DotEnvTokenType("CRLF"); // IElementType EXPORT = new DotEnvTokenType("EXPORT"); // IElementType KEY_CHARS = new DotEnvTokenType("KEY_CHARS"); // IElementType QUOTE = new DotEnvTokenType("QUOTE"); // IElementType SEPARATOR = new DotEnvTokenType("SEPARATOR"); // IElementType VALUE_CHARS = new DotEnvTokenType("VALUE_CHARS"); // // class Factory { // public static PsiElement createElement(ASTNode node) { // IElementType type = node.getElementType(); // if (type == KEY) { // return new DotEnvKeyImpl(node); // } // else if (type == PROPERTY) { // return new DotEnvPropertyImpl(node); // } // else if (type == VALUE) { // return new DotEnvValueImpl(node); // } // throw new AssertionError("Unknown element type: " + type); // } // } // }
import com.intellij.codeInspection.*; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import ru.adelf.idea.dotenv.DotEnvFactory; import ru.adelf.idea.dotenv.psi.DotEnvFile; import ru.adelf.idea.dotenv.psi.DotEnvKey; import ru.adelf.idea.dotenv.psi.DotEnvTypes;
package ru.adelf.idea.dotenv.inspections; public class LowercaseKeyInspection extends LocalInspectionTool { // Change the display name within the plugin.xml // This needs to be here as otherwise the tests will throw errors. @NotNull @Override public String getDisplayName() { return "Key uses lowercase chars"; } @Nullable @Override public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) { if (!(file instanceof DotEnvFile)) { return null; } return analyzeFile(file, manager, isOnTheFly).getResultsArray(); } @NotNull private ProblemsHolder analyzeFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) { ProblemsHolder problemsHolder = new ProblemsHolder(manager, file, isOnTheFly);
// Path: src/main/java/ru/adelf/idea/dotenv/DotEnvFactory.java // public class DotEnvFactory { // public static PsiElement createFromText(@NotNull Project project, @NotNull IElementType type, @NotNull String text) { // final Ref<PsiElement> ret = new Ref<>(); // PsiFile dummyFile = createDummyFile(project, text); // dummyFile.accept(new PsiRecursiveElementWalkingVisitor() { // public void visitElement(@NotNull PsiElement element) { // ASTNode node = element.getNode(); // if (node != null && node.getElementType() == type) { // ret.set(element); // stopWalking(); // } else { // super.visitElement(element); // } // } // }); // // assert !ret.isNull() : "cannot create element from text:\n" + dummyFile.getText(); // // return ret.get(); // } // // @NotNull // private static PsiFile createDummyFile(Project project, String fileText) { // return PsiFileFactory.getInstance(project).createFileFromText("DUMMY__.env", DotEnvFileType.INSTANCE, fileText, System.currentTimeMillis(), false); // } // } // // Path: src/main/java/ru/adelf/idea/dotenv/psi/DotEnvFile.java // public class DotEnvFile extends PsiFileBase { // public DotEnvFile(@NotNull FileViewProvider viewProvider) { // super(viewProvider, DotEnvLanguage.INSTANCE); // } // // @NotNull // @Override // public FileType getFileType() { // return DotEnvFileType.INSTANCE; // } // // @Override // public String toString() { // return ".env file"; // } // // @Override // public Icon getIcon(int flags) { // return super.getIcon(flags); // } // } // // Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvKey.java // public interface DotEnvKey extends PsiElement { // // } // // Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvTypes.java // public interface DotEnvTypes { // // IElementType KEY = new DotEnvElementType("KEY"); // IElementType PROPERTY = new DotEnvElementType("PROPERTY"); // IElementType VALUE = new DotEnvElementType("VALUE"); // // IElementType COMMENT = new DotEnvTokenType("COMMENT"); // IElementType CRLF = new DotEnvTokenType("CRLF"); // IElementType EXPORT = new DotEnvTokenType("EXPORT"); // IElementType KEY_CHARS = new DotEnvTokenType("KEY_CHARS"); // IElementType QUOTE = new DotEnvTokenType("QUOTE"); // IElementType SEPARATOR = new DotEnvTokenType("SEPARATOR"); // IElementType VALUE_CHARS = new DotEnvTokenType("VALUE_CHARS"); // // class Factory { // public static PsiElement createElement(ASTNode node) { // IElementType type = node.getElementType(); // if (type == KEY) { // return new DotEnvKeyImpl(node); // } // else if (type == PROPERTY) { // return new DotEnvPropertyImpl(node); // } // else if (type == VALUE) { // return new DotEnvValueImpl(node); // } // throw new AssertionError("Unknown element type: " + type); // } // } // } // Path: src/main/java/ru/adelf/idea/dotenv/inspections/LowercaseKeyInspection.java import com.intellij.codeInspection.*; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import ru.adelf.idea.dotenv.DotEnvFactory; import ru.adelf.idea.dotenv.psi.DotEnvFile; import ru.adelf.idea.dotenv.psi.DotEnvKey; import ru.adelf.idea.dotenv.psi.DotEnvTypes; package ru.adelf.idea.dotenv.inspections; public class LowercaseKeyInspection extends LocalInspectionTool { // Change the display name within the plugin.xml // This needs to be here as otherwise the tests will throw errors. @NotNull @Override public String getDisplayName() { return "Key uses lowercase chars"; } @Nullable @Override public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) { if (!(file instanceof DotEnvFile)) { return null; } return analyzeFile(file, manager, isOnTheFly).getResultsArray(); } @NotNull private ProblemsHolder analyzeFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) { ProblemsHolder problemsHolder = new ProblemsHolder(manager, file, isOnTheFly);
PsiTreeUtil.findChildrenOfType(file, DotEnvKey.class).forEach(dotEnvKey -> {
adelf/idea-php-dotenv-plugin
src/main/java/ru/adelf/idea/dotenv/inspections/LowercaseKeyInspection.java
// Path: src/main/java/ru/adelf/idea/dotenv/DotEnvFactory.java // public class DotEnvFactory { // public static PsiElement createFromText(@NotNull Project project, @NotNull IElementType type, @NotNull String text) { // final Ref<PsiElement> ret = new Ref<>(); // PsiFile dummyFile = createDummyFile(project, text); // dummyFile.accept(new PsiRecursiveElementWalkingVisitor() { // public void visitElement(@NotNull PsiElement element) { // ASTNode node = element.getNode(); // if (node != null && node.getElementType() == type) { // ret.set(element); // stopWalking(); // } else { // super.visitElement(element); // } // } // }); // // assert !ret.isNull() : "cannot create element from text:\n" + dummyFile.getText(); // // return ret.get(); // } // // @NotNull // private static PsiFile createDummyFile(Project project, String fileText) { // return PsiFileFactory.getInstance(project).createFileFromText("DUMMY__.env", DotEnvFileType.INSTANCE, fileText, System.currentTimeMillis(), false); // } // } // // Path: src/main/java/ru/adelf/idea/dotenv/psi/DotEnvFile.java // public class DotEnvFile extends PsiFileBase { // public DotEnvFile(@NotNull FileViewProvider viewProvider) { // super(viewProvider, DotEnvLanguage.INSTANCE); // } // // @NotNull // @Override // public FileType getFileType() { // return DotEnvFileType.INSTANCE; // } // // @Override // public String toString() { // return ".env file"; // } // // @Override // public Icon getIcon(int flags) { // return super.getIcon(flags); // } // } // // Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvKey.java // public interface DotEnvKey extends PsiElement { // // } // // Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvTypes.java // public interface DotEnvTypes { // // IElementType KEY = new DotEnvElementType("KEY"); // IElementType PROPERTY = new DotEnvElementType("PROPERTY"); // IElementType VALUE = new DotEnvElementType("VALUE"); // // IElementType COMMENT = new DotEnvTokenType("COMMENT"); // IElementType CRLF = new DotEnvTokenType("CRLF"); // IElementType EXPORT = new DotEnvTokenType("EXPORT"); // IElementType KEY_CHARS = new DotEnvTokenType("KEY_CHARS"); // IElementType QUOTE = new DotEnvTokenType("QUOTE"); // IElementType SEPARATOR = new DotEnvTokenType("SEPARATOR"); // IElementType VALUE_CHARS = new DotEnvTokenType("VALUE_CHARS"); // // class Factory { // public static PsiElement createElement(ASTNode node) { // IElementType type = node.getElementType(); // if (type == KEY) { // return new DotEnvKeyImpl(node); // } // else if (type == PROPERTY) { // return new DotEnvPropertyImpl(node); // } // else if (type == VALUE) { // return new DotEnvValueImpl(node); // } // throw new AssertionError("Unknown element type: " + type); // } // } // }
import com.intellij.codeInspection.*; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import ru.adelf.idea.dotenv.DotEnvFactory; import ru.adelf.idea.dotenv.psi.DotEnvFile; import ru.adelf.idea.dotenv.psi.DotEnvKey; import ru.adelf.idea.dotenv.psi.DotEnvTypes;
} @NotNull private ProblemsHolder analyzeFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) { ProblemsHolder problemsHolder = new ProblemsHolder(manager, file, isOnTheFly); PsiTreeUtil.findChildrenOfType(file, DotEnvKey.class).forEach(dotEnvKey -> { if (dotEnvKey.getText().matches(".*[a-z].*")) { problemsHolder.registerProblem(dotEnvKey, "Key uses lowercase chars. Only keys with uppercase chars are allowed."/*, new ForceUppercaseQuickFix()*/ ); } }); return problemsHolder; } private static class ForceUppercaseQuickFix implements LocalQuickFix { @NotNull @Override public String getName() { return "Change to uppercase"; } public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { try { PsiElement psiElement = descriptor.getPsiElement();
// Path: src/main/java/ru/adelf/idea/dotenv/DotEnvFactory.java // public class DotEnvFactory { // public static PsiElement createFromText(@NotNull Project project, @NotNull IElementType type, @NotNull String text) { // final Ref<PsiElement> ret = new Ref<>(); // PsiFile dummyFile = createDummyFile(project, text); // dummyFile.accept(new PsiRecursiveElementWalkingVisitor() { // public void visitElement(@NotNull PsiElement element) { // ASTNode node = element.getNode(); // if (node != null && node.getElementType() == type) { // ret.set(element); // stopWalking(); // } else { // super.visitElement(element); // } // } // }); // // assert !ret.isNull() : "cannot create element from text:\n" + dummyFile.getText(); // // return ret.get(); // } // // @NotNull // private static PsiFile createDummyFile(Project project, String fileText) { // return PsiFileFactory.getInstance(project).createFileFromText("DUMMY__.env", DotEnvFileType.INSTANCE, fileText, System.currentTimeMillis(), false); // } // } // // Path: src/main/java/ru/adelf/idea/dotenv/psi/DotEnvFile.java // public class DotEnvFile extends PsiFileBase { // public DotEnvFile(@NotNull FileViewProvider viewProvider) { // super(viewProvider, DotEnvLanguage.INSTANCE); // } // // @NotNull // @Override // public FileType getFileType() { // return DotEnvFileType.INSTANCE; // } // // @Override // public String toString() { // return ".env file"; // } // // @Override // public Icon getIcon(int flags) { // return super.getIcon(flags); // } // } // // Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvKey.java // public interface DotEnvKey extends PsiElement { // // } // // Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvTypes.java // public interface DotEnvTypes { // // IElementType KEY = new DotEnvElementType("KEY"); // IElementType PROPERTY = new DotEnvElementType("PROPERTY"); // IElementType VALUE = new DotEnvElementType("VALUE"); // // IElementType COMMENT = new DotEnvTokenType("COMMENT"); // IElementType CRLF = new DotEnvTokenType("CRLF"); // IElementType EXPORT = new DotEnvTokenType("EXPORT"); // IElementType KEY_CHARS = new DotEnvTokenType("KEY_CHARS"); // IElementType QUOTE = new DotEnvTokenType("QUOTE"); // IElementType SEPARATOR = new DotEnvTokenType("SEPARATOR"); // IElementType VALUE_CHARS = new DotEnvTokenType("VALUE_CHARS"); // // class Factory { // public static PsiElement createElement(ASTNode node) { // IElementType type = node.getElementType(); // if (type == KEY) { // return new DotEnvKeyImpl(node); // } // else if (type == PROPERTY) { // return new DotEnvPropertyImpl(node); // } // else if (type == VALUE) { // return new DotEnvValueImpl(node); // } // throw new AssertionError("Unknown element type: " + type); // } // } // } // Path: src/main/java/ru/adelf/idea/dotenv/inspections/LowercaseKeyInspection.java import com.intellij.codeInspection.*; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import ru.adelf.idea.dotenv.DotEnvFactory; import ru.adelf.idea.dotenv.psi.DotEnvFile; import ru.adelf.idea.dotenv.psi.DotEnvKey; import ru.adelf.idea.dotenv.psi.DotEnvTypes; } @NotNull private ProblemsHolder analyzeFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) { ProblemsHolder problemsHolder = new ProblemsHolder(manager, file, isOnTheFly); PsiTreeUtil.findChildrenOfType(file, DotEnvKey.class).forEach(dotEnvKey -> { if (dotEnvKey.getText().matches(".*[a-z].*")) { problemsHolder.registerProblem(dotEnvKey, "Key uses lowercase chars. Only keys with uppercase chars are allowed."/*, new ForceUppercaseQuickFix()*/ ); } }); return problemsHolder; } private static class ForceUppercaseQuickFix implements LocalQuickFix { @NotNull @Override public String getName() { return "Change to uppercase"; } public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { try { PsiElement psiElement = descriptor.getPsiElement();
PsiElement newPsiElement = DotEnvFactory.createFromText(project, DotEnvTypes.KEY,
adelf/idea-php-dotenv-plugin
src/main/java/ru/adelf/idea/dotenv/inspections/LowercaseKeyInspection.java
// Path: src/main/java/ru/adelf/idea/dotenv/DotEnvFactory.java // public class DotEnvFactory { // public static PsiElement createFromText(@NotNull Project project, @NotNull IElementType type, @NotNull String text) { // final Ref<PsiElement> ret = new Ref<>(); // PsiFile dummyFile = createDummyFile(project, text); // dummyFile.accept(new PsiRecursiveElementWalkingVisitor() { // public void visitElement(@NotNull PsiElement element) { // ASTNode node = element.getNode(); // if (node != null && node.getElementType() == type) { // ret.set(element); // stopWalking(); // } else { // super.visitElement(element); // } // } // }); // // assert !ret.isNull() : "cannot create element from text:\n" + dummyFile.getText(); // // return ret.get(); // } // // @NotNull // private static PsiFile createDummyFile(Project project, String fileText) { // return PsiFileFactory.getInstance(project).createFileFromText("DUMMY__.env", DotEnvFileType.INSTANCE, fileText, System.currentTimeMillis(), false); // } // } // // Path: src/main/java/ru/adelf/idea/dotenv/psi/DotEnvFile.java // public class DotEnvFile extends PsiFileBase { // public DotEnvFile(@NotNull FileViewProvider viewProvider) { // super(viewProvider, DotEnvLanguage.INSTANCE); // } // // @NotNull // @Override // public FileType getFileType() { // return DotEnvFileType.INSTANCE; // } // // @Override // public String toString() { // return ".env file"; // } // // @Override // public Icon getIcon(int flags) { // return super.getIcon(flags); // } // } // // Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvKey.java // public interface DotEnvKey extends PsiElement { // // } // // Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvTypes.java // public interface DotEnvTypes { // // IElementType KEY = new DotEnvElementType("KEY"); // IElementType PROPERTY = new DotEnvElementType("PROPERTY"); // IElementType VALUE = new DotEnvElementType("VALUE"); // // IElementType COMMENT = new DotEnvTokenType("COMMENT"); // IElementType CRLF = new DotEnvTokenType("CRLF"); // IElementType EXPORT = new DotEnvTokenType("EXPORT"); // IElementType KEY_CHARS = new DotEnvTokenType("KEY_CHARS"); // IElementType QUOTE = new DotEnvTokenType("QUOTE"); // IElementType SEPARATOR = new DotEnvTokenType("SEPARATOR"); // IElementType VALUE_CHARS = new DotEnvTokenType("VALUE_CHARS"); // // class Factory { // public static PsiElement createElement(ASTNode node) { // IElementType type = node.getElementType(); // if (type == KEY) { // return new DotEnvKeyImpl(node); // } // else if (type == PROPERTY) { // return new DotEnvPropertyImpl(node); // } // else if (type == VALUE) { // return new DotEnvValueImpl(node); // } // throw new AssertionError("Unknown element type: " + type); // } // } // }
import com.intellij.codeInspection.*; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import ru.adelf.idea.dotenv.DotEnvFactory; import ru.adelf.idea.dotenv.psi.DotEnvFile; import ru.adelf.idea.dotenv.psi.DotEnvKey; import ru.adelf.idea.dotenv.psi.DotEnvTypes;
} @NotNull private ProblemsHolder analyzeFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) { ProblemsHolder problemsHolder = new ProblemsHolder(manager, file, isOnTheFly); PsiTreeUtil.findChildrenOfType(file, DotEnvKey.class).forEach(dotEnvKey -> { if (dotEnvKey.getText().matches(".*[a-z].*")) { problemsHolder.registerProblem(dotEnvKey, "Key uses lowercase chars. Only keys with uppercase chars are allowed."/*, new ForceUppercaseQuickFix()*/ ); } }); return problemsHolder; } private static class ForceUppercaseQuickFix implements LocalQuickFix { @NotNull @Override public String getName() { return "Change to uppercase"; } public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { try { PsiElement psiElement = descriptor.getPsiElement();
// Path: src/main/java/ru/adelf/idea/dotenv/DotEnvFactory.java // public class DotEnvFactory { // public static PsiElement createFromText(@NotNull Project project, @NotNull IElementType type, @NotNull String text) { // final Ref<PsiElement> ret = new Ref<>(); // PsiFile dummyFile = createDummyFile(project, text); // dummyFile.accept(new PsiRecursiveElementWalkingVisitor() { // public void visitElement(@NotNull PsiElement element) { // ASTNode node = element.getNode(); // if (node != null && node.getElementType() == type) { // ret.set(element); // stopWalking(); // } else { // super.visitElement(element); // } // } // }); // // assert !ret.isNull() : "cannot create element from text:\n" + dummyFile.getText(); // // return ret.get(); // } // // @NotNull // private static PsiFile createDummyFile(Project project, String fileText) { // return PsiFileFactory.getInstance(project).createFileFromText("DUMMY__.env", DotEnvFileType.INSTANCE, fileText, System.currentTimeMillis(), false); // } // } // // Path: src/main/java/ru/adelf/idea/dotenv/psi/DotEnvFile.java // public class DotEnvFile extends PsiFileBase { // public DotEnvFile(@NotNull FileViewProvider viewProvider) { // super(viewProvider, DotEnvLanguage.INSTANCE); // } // // @NotNull // @Override // public FileType getFileType() { // return DotEnvFileType.INSTANCE; // } // // @Override // public String toString() { // return ".env file"; // } // // @Override // public Icon getIcon(int flags) { // return super.getIcon(flags); // } // } // // Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvKey.java // public interface DotEnvKey extends PsiElement { // // } // // Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvTypes.java // public interface DotEnvTypes { // // IElementType KEY = new DotEnvElementType("KEY"); // IElementType PROPERTY = new DotEnvElementType("PROPERTY"); // IElementType VALUE = new DotEnvElementType("VALUE"); // // IElementType COMMENT = new DotEnvTokenType("COMMENT"); // IElementType CRLF = new DotEnvTokenType("CRLF"); // IElementType EXPORT = new DotEnvTokenType("EXPORT"); // IElementType KEY_CHARS = new DotEnvTokenType("KEY_CHARS"); // IElementType QUOTE = new DotEnvTokenType("QUOTE"); // IElementType SEPARATOR = new DotEnvTokenType("SEPARATOR"); // IElementType VALUE_CHARS = new DotEnvTokenType("VALUE_CHARS"); // // class Factory { // public static PsiElement createElement(ASTNode node) { // IElementType type = node.getElementType(); // if (type == KEY) { // return new DotEnvKeyImpl(node); // } // else if (type == PROPERTY) { // return new DotEnvPropertyImpl(node); // } // else if (type == VALUE) { // return new DotEnvValueImpl(node); // } // throw new AssertionError("Unknown element type: " + type); // } // } // } // Path: src/main/java/ru/adelf/idea/dotenv/inspections/LowercaseKeyInspection.java import com.intellij.codeInspection.*; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import ru.adelf.idea.dotenv.DotEnvFactory; import ru.adelf.idea.dotenv.psi.DotEnvFile; import ru.adelf.idea.dotenv.psi.DotEnvKey; import ru.adelf.idea.dotenv.psi.DotEnvTypes; } @NotNull private ProblemsHolder analyzeFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) { ProblemsHolder problemsHolder = new ProblemsHolder(manager, file, isOnTheFly); PsiTreeUtil.findChildrenOfType(file, DotEnvKey.class).forEach(dotEnvKey -> { if (dotEnvKey.getText().matches(".*[a-z].*")) { problemsHolder.registerProblem(dotEnvKey, "Key uses lowercase chars. Only keys with uppercase chars are allowed."/*, new ForceUppercaseQuickFix()*/ ); } }); return problemsHolder; } private static class ForceUppercaseQuickFix implements LocalQuickFix { @NotNull @Override public String getName() { return "Change to uppercase"; } public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { try { PsiElement psiElement = descriptor.getPsiElement();
PsiElement newPsiElement = DotEnvFactory.createFromText(project, DotEnvTypes.KEY,
adelf/idea-php-dotenv-plugin
src/main/java/ru/adelf/idea/dotenv/docker/DockerComposeYamlPsiElementsVisitor.java
// Path: src/main/java/ru/adelf/idea/dotenv/models/EnvironmentKeyValue.java // public class EnvironmentKeyValue { // // private final String key; // private final String value; // // public EnvironmentKeyValue(@NotNull String key, @NotNull String value) { // this.key = key; // this.value = value; // } // // @NotNull // public String getKey() { // return key; // } // // @NotNull // public String getValue() { // return value; // } // } // // Path: src/main/java/ru/adelf/idea/dotenv/models/KeyValuePsiElement.java // public class KeyValuePsiElement { // // private final String key; // private final String value; // private final PsiElement element; // // public KeyValuePsiElement(String key, String value, PsiElement element) { // this.key = key; // this.value = value; // this.element = element; // } // // public String getKey() { // return key.trim(); // } // // public String getShortValue() { // if (value.indexOf('\n') != -1) { // return clearString(value.substring(0, value.indexOf('\n'))) + "..."; // } // // return value.trim(); // } // // private String clearString(String s) { // return StringUtil.trim(s.trim(), ch -> ch != '\\').trim(); // } // // public PsiElement getElement() { // return element; // } // } // // Path: src/main/java/ru/adelf/idea/dotenv/util/EnvironmentVariablesUtil.java // public class EnvironmentVariablesUtil { // @NotNull // public static EnvironmentKeyValue getKeyValueFromString(@NotNull String s) { // int pos = s.indexOf("="); // // if(pos == -1) { // return new EnvironmentKeyValue(s.trim(), ""); // } else { // return new EnvironmentKeyValue(s.substring(0, pos).trim(), s.substring(pos + 1).trim()); // } // } // // @NotNull // public static String getKeyFromString(@NotNull String s) { // int pos = s.indexOf("="); // // if(pos == -1) { // return s.trim(); // } else { // return s.substring(0, pos).trim(); // } // } // // @NotNull // public static Set<PsiElement> getElementsByKey(String key, Collection<KeyValuePsiElement> items) { // return items.stream().filter(item -> item.getKey().equals(key)).map(KeyValuePsiElement::getElement).collect(Collectors.toSet()); // } // // @NotNull // public static Set<PsiElement> getUsagesElementsByKey(String key, Collection<KeyUsagePsiElement> items) { // return items.stream().filter(item -> item.getKey().equals(key)).map(KeyUsagePsiElement::getElement).collect(Collectors.toSet()); // } // }
import com.intellij.psi.PsiElement; import com.intellij.psi.PsiRecursiveElementVisitor; import org.apache.commons.lang.StringUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.yaml.psi.*; import ru.adelf.idea.dotenv.models.EnvironmentKeyValue; import ru.adelf.idea.dotenv.models.KeyValuePsiElement; import ru.adelf.idea.dotenv.util.EnvironmentVariablesUtil; import java.util.Collection; import java.util.Collections; import java.util.HashSet;
package ru.adelf.idea.dotenv.docker; class DockerComposeYamlPsiElementsVisitor extends PsiRecursiveElementVisitor { private final Collection<KeyValuePsiElement> collectedItems = new HashSet<>(); @Override public void visitElement(@NotNull PsiElement element) { if (element instanceof YAMLKeyValue) { this.visitKeyValue((YAMLKeyValue) element); } super.visitElement(element); } Collection<KeyValuePsiElement> getCollectedItems() { return collectedItems; } private void visitKeyValue(YAMLKeyValue yamlKeyValue) { if ("environment".equals(yamlKeyValue.getKeyText())) { for (YAMLSequenceItem yamlSequenceItem : getSequenceItems(yamlKeyValue)) { YAMLValue el = yamlSequenceItem.getValue(); if (el instanceof YAMLScalar) {
// Path: src/main/java/ru/adelf/idea/dotenv/models/EnvironmentKeyValue.java // public class EnvironmentKeyValue { // // private final String key; // private final String value; // // public EnvironmentKeyValue(@NotNull String key, @NotNull String value) { // this.key = key; // this.value = value; // } // // @NotNull // public String getKey() { // return key; // } // // @NotNull // public String getValue() { // return value; // } // } // // Path: src/main/java/ru/adelf/idea/dotenv/models/KeyValuePsiElement.java // public class KeyValuePsiElement { // // private final String key; // private final String value; // private final PsiElement element; // // public KeyValuePsiElement(String key, String value, PsiElement element) { // this.key = key; // this.value = value; // this.element = element; // } // // public String getKey() { // return key.trim(); // } // // public String getShortValue() { // if (value.indexOf('\n') != -1) { // return clearString(value.substring(0, value.indexOf('\n'))) + "..."; // } // // return value.trim(); // } // // private String clearString(String s) { // return StringUtil.trim(s.trim(), ch -> ch != '\\').trim(); // } // // public PsiElement getElement() { // return element; // } // } // // Path: src/main/java/ru/adelf/idea/dotenv/util/EnvironmentVariablesUtil.java // public class EnvironmentVariablesUtil { // @NotNull // public static EnvironmentKeyValue getKeyValueFromString(@NotNull String s) { // int pos = s.indexOf("="); // // if(pos == -1) { // return new EnvironmentKeyValue(s.trim(), ""); // } else { // return new EnvironmentKeyValue(s.substring(0, pos).trim(), s.substring(pos + 1).trim()); // } // } // // @NotNull // public static String getKeyFromString(@NotNull String s) { // int pos = s.indexOf("="); // // if(pos == -1) { // return s.trim(); // } else { // return s.substring(0, pos).trim(); // } // } // // @NotNull // public static Set<PsiElement> getElementsByKey(String key, Collection<KeyValuePsiElement> items) { // return items.stream().filter(item -> item.getKey().equals(key)).map(KeyValuePsiElement::getElement).collect(Collectors.toSet()); // } // // @NotNull // public static Set<PsiElement> getUsagesElementsByKey(String key, Collection<KeyUsagePsiElement> items) { // return items.stream().filter(item -> item.getKey().equals(key)).map(KeyUsagePsiElement::getElement).collect(Collectors.toSet()); // } // } // Path: src/main/java/ru/adelf/idea/dotenv/docker/DockerComposeYamlPsiElementsVisitor.java import com.intellij.psi.PsiElement; import com.intellij.psi.PsiRecursiveElementVisitor; import org.apache.commons.lang.StringUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.yaml.psi.*; import ru.adelf.idea.dotenv.models.EnvironmentKeyValue; import ru.adelf.idea.dotenv.models.KeyValuePsiElement; import ru.adelf.idea.dotenv.util.EnvironmentVariablesUtil; import java.util.Collection; import java.util.Collections; import java.util.HashSet; package ru.adelf.idea.dotenv.docker; class DockerComposeYamlPsiElementsVisitor extends PsiRecursiveElementVisitor { private final Collection<KeyValuePsiElement> collectedItems = new HashSet<>(); @Override public void visitElement(@NotNull PsiElement element) { if (element instanceof YAMLKeyValue) { this.visitKeyValue((YAMLKeyValue) element); } super.visitElement(element); } Collection<KeyValuePsiElement> getCollectedItems() { return collectedItems; } private void visitKeyValue(YAMLKeyValue yamlKeyValue) { if ("environment".equals(yamlKeyValue.getKeyText())) { for (YAMLSequenceItem yamlSequenceItem : getSequenceItems(yamlKeyValue)) { YAMLValue el = yamlSequenceItem.getValue(); if (el instanceof YAMLScalar) {
EnvironmentKeyValue keyValue = EnvironmentVariablesUtil.getKeyValueFromString(((YAMLScalar) el).getTextValue());
adelf/idea-php-dotenv-plugin
src/main/java/ru/adelf/idea/dotenv/docker/DockerComposeYamlPsiElementsVisitor.java
// Path: src/main/java/ru/adelf/idea/dotenv/models/EnvironmentKeyValue.java // public class EnvironmentKeyValue { // // private final String key; // private final String value; // // public EnvironmentKeyValue(@NotNull String key, @NotNull String value) { // this.key = key; // this.value = value; // } // // @NotNull // public String getKey() { // return key; // } // // @NotNull // public String getValue() { // return value; // } // } // // Path: src/main/java/ru/adelf/idea/dotenv/models/KeyValuePsiElement.java // public class KeyValuePsiElement { // // private final String key; // private final String value; // private final PsiElement element; // // public KeyValuePsiElement(String key, String value, PsiElement element) { // this.key = key; // this.value = value; // this.element = element; // } // // public String getKey() { // return key.trim(); // } // // public String getShortValue() { // if (value.indexOf('\n') != -1) { // return clearString(value.substring(0, value.indexOf('\n'))) + "..."; // } // // return value.trim(); // } // // private String clearString(String s) { // return StringUtil.trim(s.trim(), ch -> ch != '\\').trim(); // } // // public PsiElement getElement() { // return element; // } // } // // Path: src/main/java/ru/adelf/idea/dotenv/util/EnvironmentVariablesUtil.java // public class EnvironmentVariablesUtil { // @NotNull // public static EnvironmentKeyValue getKeyValueFromString(@NotNull String s) { // int pos = s.indexOf("="); // // if(pos == -1) { // return new EnvironmentKeyValue(s.trim(), ""); // } else { // return new EnvironmentKeyValue(s.substring(0, pos).trim(), s.substring(pos + 1).trim()); // } // } // // @NotNull // public static String getKeyFromString(@NotNull String s) { // int pos = s.indexOf("="); // // if(pos == -1) { // return s.trim(); // } else { // return s.substring(0, pos).trim(); // } // } // // @NotNull // public static Set<PsiElement> getElementsByKey(String key, Collection<KeyValuePsiElement> items) { // return items.stream().filter(item -> item.getKey().equals(key)).map(KeyValuePsiElement::getElement).collect(Collectors.toSet()); // } // // @NotNull // public static Set<PsiElement> getUsagesElementsByKey(String key, Collection<KeyUsagePsiElement> items) { // return items.stream().filter(item -> item.getKey().equals(key)).map(KeyUsagePsiElement::getElement).collect(Collectors.toSet()); // } // }
import com.intellij.psi.PsiElement; import com.intellij.psi.PsiRecursiveElementVisitor; import org.apache.commons.lang.StringUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.yaml.psi.*; import ru.adelf.idea.dotenv.models.EnvironmentKeyValue; import ru.adelf.idea.dotenv.models.KeyValuePsiElement; import ru.adelf.idea.dotenv.util.EnvironmentVariablesUtil; import java.util.Collection; import java.util.Collections; import java.util.HashSet;
package ru.adelf.idea.dotenv.docker; class DockerComposeYamlPsiElementsVisitor extends PsiRecursiveElementVisitor { private final Collection<KeyValuePsiElement> collectedItems = new HashSet<>(); @Override public void visitElement(@NotNull PsiElement element) { if (element instanceof YAMLKeyValue) { this.visitKeyValue((YAMLKeyValue) element); } super.visitElement(element); } Collection<KeyValuePsiElement> getCollectedItems() { return collectedItems; } private void visitKeyValue(YAMLKeyValue yamlKeyValue) { if ("environment".equals(yamlKeyValue.getKeyText())) { for (YAMLSequenceItem yamlSequenceItem : getSequenceItems(yamlKeyValue)) { YAMLValue el = yamlSequenceItem.getValue(); if (el instanceof YAMLScalar) {
// Path: src/main/java/ru/adelf/idea/dotenv/models/EnvironmentKeyValue.java // public class EnvironmentKeyValue { // // private final String key; // private final String value; // // public EnvironmentKeyValue(@NotNull String key, @NotNull String value) { // this.key = key; // this.value = value; // } // // @NotNull // public String getKey() { // return key; // } // // @NotNull // public String getValue() { // return value; // } // } // // Path: src/main/java/ru/adelf/idea/dotenv/models/KeyValuePsiElement.java // public class KeyValuePsiElement { // // private final String key; // private final String value; // private final PsiElement element; // // public KeyValuePsiElement(String key, String value, PsiElement element) { // this.key = key; // this.value = value; // this.element = element; // } // // public String getKey() { // return key.trim(); // } // // public String getShortValue() { // if (value.indexOf('\n') != -1) { // return clearString(value.substring(0, value.indexOf('\n'))) + "..."; // } // // return value.trim(); // } // // private String clearString(String s) { // return StringUtil.trim(s.trim(), ch -> ch != '\\').trim(); // } // // public PsiElement getElement() { // return element; // } // } // // Path: src/main/java/ru/adelf/idea/dotenv/util/EnvironmentVariablesUtil.java // public class EnvironmentVariablesUtil { // @NotNull // public static EnvironmentKeyValue getKeyValueFromString(@NotNull String s) { // int pos = s.indexOf("="); // // if(pos == -1) { // return new EnvironmentKeyValue(s.trim(), ""); // } else { // return new EnvironmentKeyValue(s.substring(0, pos).trim(), s.substring(pos + 1).trim()); // } // } // // @NotNull // public static String getKeyFromString(@NotNull String s) { // int pos = s.indexOf("="); // // if(pos == -1) { // return s.trim(); // } else { // return s.substring(0, pos).trim(); // } // } // // @NotNull // public static Set<PsiElement> getElementsByKey(String key, Collection<KeyValuePsiElement> items) { // return items.stream().filter(item -> item.getKey().equals(key)).map(KeyValuePsiElement::getElement).collect(Collectors.toSet()); // } // // @NotNull // public static Set<PsiElement> getUsagesElementsByKey(String key, Collection<KeyUsagePsiElement> items) { // return items.stream().filter(item -> item.getKey().equals(key)).map(KeyUsagePsiElement::getElement).collect(Collectors.toSet()); // } // } // Path: src/main/java/ru/adelf/idea/dotenv/docker/DockerComposeYamlPsiElementsVisitor.java import com.intellij.psi.PsiElement; import com.intellij.psi.PsiRecursiveElementVisitor; import org.apache.commons.lang.StringUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.yaml.psi.*; import ru.adelf.idea.dotenv.models.EnvironmentKeyValue; import ru.adelf.idea.dotenv.models.KeyValuePsiElement; import ru.adelf.idea.dotenv.util.EnvironmentVariablesUtil; import java.util.Collection; import java.util.Collections; import java.util.HashSet; package ru.adelf.idea.dotenv.docker; class DockerComposeYamlPsiElementsVisitor extends PsiRecursiveElementVisitor { private final Collection<KeyValuePsiElement> collectedItems = new HashSet<>(); @Override public void visitElement(@NotNull PsiElement element) { if (element instanceof YAMLKeyValue) { this.visitKeyValue((YAMLKeyValue) element); } super.visitElement(element); } Collection<KeyValuePsiElement> getCollectedItems() { return collectedItems; } private void visitKeyValue(YAMLKeyValue yamlKeyValue) { if ("environment".equals(yamlKeyValue.getKeyText())) { for (YAMLSequenceItem yamlSequenceItem : getSequenceItems(yamlKeyValue)) { YAMLValue el = yamlSequenceItem.getValue(); if (el instanceof YAMLScalar) {
EnvironmentKeyValue keyValue = EnvironmentVariablesUtil.getKeyValueFromString(((YAMLScalar) el).getTextValue());
adelf/idea-php-dotenv-plugin
src/main/java/ru/adelf/idea/dotenv/extension/DotEnvRefactoringSupportProvider.java
// Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvProperty.java // public interface DotEnvProperty extends DotEnvNamedElement { // // @NotNull // DotEnvKey getKey(); // // @Nullable // DotEnvValue getValue(); // // String getKeyText(); // // String getValueText(); // // String getName(); // // PsiElement setName(@NotNull String newName); // // PsiElement getNameIdentifier(); // // }
import com.intellij.lang.refactoring.RefactoringSupportProvider; import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import ru.adelf.idea.dotenv.psi.DotEnvProperty;
package ru.adelf.idea.dotenv.extension; public class DotEnvRefactoringSupportProvider extends RefactoringSupportProvider { @Override public boolean isMemberInplaceRenameAvailable(@NotNull PsiElement element, PsiElement context) {
// Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvProperty.java // public interface DotEnvProperty extends DotEnvNamedElement { // // @NotNull // DotEnvKey getKey(); // // @Nullable // DotEnvValue getValue(); // // String getKeyText(); // // String getValueText(); // // String getName(); // // PsiElement setName(@NotNull String newName); // // PsiElement getNameIdentifier(); // // } // Path: src/main/java/ru/adelf/idea/dotenv/extension/DotEnvRefactoringSupportProvider.java import com.intellij.lang.refactoring.RefactoringSupportProvider; import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import ru.adelf.idea.dotenv.psi.DotEnvProperty; package ru.adelf.idea.dotenv.extension; public class DotEnvRefactoringSupportProvider extends RefactoringSupportProvider { @Override public boolean isMemberInplaceRenameAvailable(@NotNull PsiElement element, PsiElement context) {
return element instanceof DotEnvProperty;
adelf/idea-php-dotenv-plugin
src/main/java/ru/adelf/idea/dotenv/java/JavaEnvironmentVariablesUsagesProvider.java
// Path: src/main/java/ru/adelf/idea/dotenv/api/EnvironmentVariablesUsagesProvider.java // public interface EnvironmentVariablesUsagesProvider { // boolean acceptFile(VirtualFile file); // // @NotNull // Collection<KeyUsagePsiElement> getUsages(PsiFile psiFile); // } // // Path: src/main/java/ru/adelf/idea/dotenv/models/KeyUsagePsiElement.java // public class KeyUsagePsiElement { // // private final String key; // private final PsiElement element; // // public KeyUsagePsiElement(String key, PsiElement element) { // this.key = key; // this.element = element; // } // // public String getKey() { // return key; // } // // public PsiElement getElement() { // return element; // } // }
import com.intellij.ide.highlighter.JavaFileType; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiJavaFile; import org.jetbrains.annotations.NotNull; import ru.adelf.idea.dotenv.api.EnvironmentVariablesUsagesProvider; import ru.adelf.idea.dotenv.models.KeyUsagePsiElement; import java.util.Collection; import java.util.Collections;
package ru.adelf.idea.dotenv.java; public class JavaEnvironmentVariablesUsagesProvider implements EnvironmentVariablesUsagesProvider { @Override public boolean acceptFile(VirtualFile file) { return file.getFileType().equals(JavaFileType.INSTANCE); } @NotNull @Override
// Path: src/main/java/ru/adelf/idea/dotenv/api/EnvironmentVariablesUsagesProvider.java // public interface EnvironmentVariablesUsagesProvider { // boolean acceptFile(VirtualFile file); // // @NotNull // Collection<KeyUsagePsiElement> getUsages(PsiFile psiFile); // } // // Path: src/main/java/ru/adelf/idea/dotenv/models/KeyUsagePsiElement.java // public class KeyUsagePsiElement { // // private final String key; // private final PsiElement element; // // public KeyUsagePsiElement(String key, PsiElement element) { // this.key = key; // this.element = element; // } // // public String getKey() { // return key; // } // // public PsiElement getElement() { // return element; // } // } // Path: src/main/java/ru/adelf/idea/dotenv/java/JavaEnvironmentVariablesUsagesProvider.java import com.intellij.ide.highlighter.JavaFileType; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiJavaFile; import org.jetbrains.annotations.NotNull; import ru.adelf.idea.dotenv.api.EnvironmentVariablesUsagesProvider; import ru.adelf.idea.dotenv.models.KeyUsagePsiElement; import java.util.Collection; import java.util.Collections; package ru.adelf.idea.dotenv.java; public class JavaEnvironmentVariablesUsagesProvider implements EnvironmentVariablesUsagesProvider { @Override public boolean acceptFile(VirtualFile file) { return file.getFileType().equals(JavaFileType.INSTANCE); } @NotNull @Override
public Collection<KeyUsagePsiElement> getUsages(PsiFile psiFile) {
adelf/idea-php-dotenv-plugin
src/main/java/ru/adelf/idea/dotenv/DotEnvPsiElementsVisitor.java
// Path: src/main/java/ru/adelf/idea/dotenv/models/KeyValuePsiElement.java // public class KeyValuePsiElement { // // private final String key; // private final String value; // private final PsiElement element; // // public KeyValuePsiElement(String key, String value, PsiElement element) { // this.key = key; // this.value = value; // this.element = element; // } // // public String getKey() { // return key.trim(); // } // // public String getShortValue() { // if (value.indexOf('\n') != -1) { // return clearString(value.substring(0, value.indexOf('\n'))) + "..."; // } // // return value.trim(); // } // // private String clearString(String s) { // return StringUtil.trim(s.trim(), ch -> ch != '\\').trim(); // } // // public PsiElement getElement() { // return element; // } // } // // Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvProperty.java // public interface DotEnvProperty extends DotEnvNamedElement { // // @NotNull // DotEnvKey getKey(); // // @Nullable // DotEnvValue getValue(); // // String getKeyText(); // // String getValueText(); // // String getName(); // // PsiElement setName(@NotNull String newName); // // PsiElement getNameIdentifier(); // // } // // Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvVisitor.java // public class DotEnvVisitor extends PsiElementVisitor { // // public void visitKey(@NotNull DotEnvKey o) { // visitPsiElement(o); // } // // public void visitProperty(@NotNull DotEnvProperty o) { // visitNamedElement(o); // } // // public void visitValue(@NotNull DotEnvValue o) { // visitPsiElement(o); // } // // public void visitNamedElement(@NotNull DotEnvNamedElement o) { // visitPsiElement(o); // } // // public void visitPsiElement(@NotNull PsiElement o) { // visitElement(o); // } // // }
import org.jetbrains.annotations.NotNull; import ru.adelf.idea.dotenv.models.KeyValuePsiElement; import ru.adelf.idea.dotenv.psi.DotEnvProperty; import ru.adelf.idea.dotenv.psi.DotEnvVisitor; import java.util.Collection; import java.util.HashSet;
package ru.adelf.idea.dotenv; public class DotEnvPsiElementsVisitor extends DotEnvVisitor { private final Collection<KeyValuePsiElement> collectedItems = new HashSet<>(); @Override
// Path: src/main/java/ru/adelf/idea/dotenv/models/KeyValuePsiElement.java // public class KeyValuePsiElement { // // private final String key; // private final String value; // private final PsiElement element; // // public KeyValuePsiElement(String key, String value, PsiElement element) { // this.key = key; // this.value = value; // this.element = element; // } // // public String getKey() { // return key.trim(); // } // // public String getShortValue() { // if (value.indexOf('\n') != -1) { // return clearString(value.substring(0, value.indexOf('\n'))) + "..."; // } // // return value.trim(); // } // // private String clearString(String s) { // return StringUtil.trim(s.trim(), ch -> ch != '\\').trim(); // } // // public PsiElement getElement() { // return element; // } // } // // Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvProperty.java // public interface DotEnvProperty extends DotEnvNamedElement { // // @NotNull // DotEnvKey getKey(); // // @Nullable // DotEnvValue getValue(); // // String getKeyText(); // // String getValueText(); // // String getName(); // // PsiElement setName(@NotNull String newName); // // PsiElement getNameIdentifier(); // // } // // Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvVisitor.java // public class DotEnvVisitor extends PsiElementVisitor { // // public void visitKey(@NotNull DotEnvKey o) { // visitPsiElement(o); // } // // public void visitProperty(@NotNull DotEnvProperty o) { // visitNamedElement(o); // } // // public void visitValue(@NotNull DotEnvValue o) { // visitPsiElement(o); // } // // public void visitNamedElement(@NotNull DotEnvNamedElement o) { // visitPsiElement(o); // } // // public void visitPsiElement(@NotNull PsiElement o) { // visitElement(o); // } // // } // Path: src/main/java/ru/adelf/idea/dotenv/DotEnvPsiElementsVisitor.java import org.jetbrains.annotations.NotNull; import ru.adelf.idea.dotenv.models.KeyValuePsiElement; import ru.adelf.idea.dotenv.psi.DotEnvProperty; import ru.adelf.idea.dotenv.psi.DotEnvVisitor; import java.util.Collection; import java.util.HashSet; package ru.adelf.idea.dotenv; public class DotEnvPsiElementsVisitor extends DotEnvVisitor { private final Collection<KeyValuePsiElement> collectedItems = new HashSet<>(); @Override
public void visitProperty(@NotNull DotEnvProperty property) {
adelf/idea-php-dotenv-plugin
src/main/java/ru/adelf/idea/dotenv/common/BaseEnvCompletionProvider.java
// Path: src/main/java/ru/adelf/idea/dotenv/api/EnvironmentVariablesApi.java // public class EnvironmentVariablesApi { // // @NotNull // public static Map<String, String> getAllKeyValues(Project project) { // FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance(); // Map<String, String> keyValues = new HashMap<>(); // Map<String, String> secondaryKeyValues = new HashMap<>(); // Map<VirtualFile, FileAcceptResult> resultsCache = new HashMap<>(); // // GlobalSearchScope scope = GlobalSearchScope.allScope(project); // // fileBasedIndex.processAllKeys(DotEnvKeyValuesIndex.KEY, key -> { // for (VirtualFile virtualFile : fileBasedIndex.getContainingFiles(DotEnvKeyValuesIndex.KEY, key, scope)) { // // FileAcceptResult fileAcceptResult; // // if (resultsCache.containsKey(virtualFile)) { // fileAcceptResult = resultsCache.get(virtualFile); // } else { // fileAcceptResult = getFileAcceptResult(virtualFile); // resultsCache.put(virtualFile, fileAcceptResult); // } // // if (!fileAcceptResult.isAccepted()) { // continue; // } // // fileBasedIndex.processValues(DotEnvKeyValuesIndex.KEY, key, virtualFile, ((file, val) -> { // if (fileAcceptResult.isPrimary()) { // keyValues.putIfAbsent(key, val); // } else { // secondaryKeyValues.putIfAbsent(key, val); // } // // return true; // }), scope); // } // // return true; // }, project); // // secondaryKeyValues.putAll(keyValues); // // return secondaryKeyValues; // } // // /** // * @param project project // * @param key environment variable key // * @return All key declarations, in .env files, Dockerfile, docker-compose.yml, etc // */ // @NotNull // public static PsiElement[] getKeyDeclarations(Project project, String key) { // List<PsiElement> targets = new ArrayList<>(); // List<PsiElement> secondaryTargets = new ArrayList<>(); // // FileBasedIndex.getInstance().getFilesWithKey(DotEnvKeyValuesIndex.KEY, new HashSet<>(Collections.singletonList(key)), virtualFile -> { // PsiFile psiFileTarget = PsiManager.getInstance(project).findFile(virtualFile); // if (psiFileTarget == null) { // return true; // } // // for (EnvironmentVariablesProvider provider : EnvironmentVariablesProviderUtil.PROVIDERS) { // FileAcceptResult fileAcceptResult = provider.acceptFile(virtualFile); // if (!fileAcceptResult.isAccepted()) { // continue; // } // // (fileAcceptResult.isPrimary() ? targets : secondaryTargets).addAll(EnvironmentVariablesUtil.getElementsByKey(key, provider.getElements(psiFileTarget))); // } // // return true; // }, GlobalSearchScope.allScope(project)); // // return (targets.size() > 0 ? targets : secondaryTargets).toArray(PsiElement.EMPTY_ARRAY); // } // // /** // * @param project project // * @param key environment variable key // * @return All key usages, like getenv('KEY') // */ // @NotNull // public static PsiElement[] getKeyUsages(Project project, String key) { // List<PsiElement> targets = new ArrayList<>(); // // PsiSearchHelper searchHelper = PsiSearchHelper.getInstance(project); // // Processor<PsiFile> psiFileProcessor = psiFile -> { // for (EnvironmentVariablesUsagesProvider provider : EnvironmentVariablesProviderUtil.USAGES_PROVIDERS) { // targets.addAll(EnvironmentVariablesUtil.getUsagesElementsByKey(key, provider.getUsages(psiFile))); // } // // return true; // }; // // searchHelper.processAllFilesWithWord(key, GlobalSearchScope.allScope(project), psiFileProcessor, true); // searchHelper.processAllFilesWithWordInLiterals(key, GlobalSearchScope.allScope(project), psiFileProcessor); // searchHelper.processAllFilesWithWordInText(key, GlobalSearchScope.allScope(project), psiFileProcessor, true); // // return targets.toArray(PsiElement.EMPTY_ARRAY); // } // // private static FileAcceptResult getFileAcceptResult(VirtualFile virtualFile) { // for (EnvironmentVariablesProvider provider : EnvironmentVariablesProviderUtil.PROVIDERS) { // FileAcceptResult fileAcceptResult = provider.acceptFile(virtualFile); // if (!fileAcceptResult.isAccepted()) { // continue; // } // // return fileAcceptResult; // } // // return FileAcceptResult.NOT_ACCEPTED; // } // }
import com.intellij.codeInsight.completion.CompletionContributor; import com.intellij.codeInsight.completion.CompletionResultSet; import com.intellij.codeInsight.completion.PrioritizedLookupElement; import com.intellij.codeInsight.lookup.LookupElementBuilder; import com.intellij.codeInsight.navigation.actions.GotoDeclarationHandler; import com.intellij.openapi.project.Project; import org.apache.commons.lang.StringUtils; import org.jetbrains.annotations.NotNull; import ru.adelf.idea.dotenv.api.EnvironmentVariablesApi; import java.util.Map;
package ru.adelf.idea.dotenv.common; abstract public class BaseEnvCompletionProvider extends CompletionContributor implements GotoDeclarationHandler { protected void fillCompletionResultSet(@NotNull CompletionResultSet completionResultSet, @NotNull Project project) {
// Path: src/main/java/ru/adelf/idea/dotenv/api/EnvironmentVariablesApi.java // public class EnvironmentVariablesApi { // // @NotNull // public static Map<String, String> getAllKeyValues(Project project) { // FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance(); // Map<String, String> keyValues = new HashMap<>(); // Map<String, String> secondaryKeyValues = new HashMap<>(); // Map<VirtualFile, FileAcceptResult> resultsCache = new HashMap<>(); // // GlobalSearchScope scope = GlobalSearchScope.allScope(project); // // fileBasedIndex.processAllKeys(DotEnvKeyValuesIndex.KEY, key -> { // for (VirtualFile virtualFile : fileBasedIndex.getContainingFiles(DotEnvKeyValuesIndex.KEY, key, scope)) { // // FileAcceptResult fileAcceptResult; // // if (resultsCache.containsKey(virtualFile)) { // fileAcceptResult = resultsCache.get(virtualFile); // } else { // fileAcceptResult = getFileAcceptResult(virtualFile); // resultsCache.put(virtualFile, fileAcceptResult); // } // // if (!fileAcceptResult.isAccepted()) { // continue; // } // // fileBasedIndex.processValues(DotEnvKeyValuesIndex.KEY, key, virtualFile, ((file, val) -> { // if (fileAcceptResult.isPrimary()) { // keyValues.putIfAbsent(key, val); // } else { // secondaryKeyValues.putIfAbsent(key, val); // } // // return true; // }), scope); // } // // return true; // }, project); // // secondaryKeyValues.putAll(keyValues); // // return secondaryKeyValues; // } // // /** // * @param project project // * @param key environment variable key // * @return All key declarations, in .env files, Dockerfile, docker-compose.yml, etc // */ // @NotNull // public static PsiElement[] getKeyDeclarations(Project project, String key) { // List<PsiElement> targets = new ArrayList<>(); // List<PsiElement> secondaryTargets = new ArrayList<>(); // // FileBasedIndex.getInstance().getFilesWithKey(DotEnvKeyValuesIndex.KEY, new HashSet<>(Collections.singletonList(key)), virtualFile -> { // PsiFile psiFileTarget = PsiManager.getInstance(project).findFile(virtualFile); // if (psiFileTarget == null) { // return true; // } // // for (EnvironmentVariablesProvider provider : EnvironmentVariablesProviderUtil.PROVIDERS) { // FileAcceptResult fileAcceptResult = provider.acceptFile(virtualFile); // if (!fileAcceptResult.isAccepted()) { // continue; // } // // (fileAcceptResult.isPrimary() ? targets : secondaryTargets).addAll(EnvironmentVariablesUtil.getElementsByKey(key, provider.getElements(psiFileTarget))); // } // // return true; // }, GlobalSearchScope.allScope(project)); // // return (targets.size() > 0 ? targets : secondaryTargets).toArray(PsiElement.EMPTY_ARRAY); // } // // /** // * @param project project // * @param key environment variable key // * @return All key usages, like getenv('KEY') // */ // @NotNull // public static PsiElement[] getKeyUsages(Project project, String key) { // List<PsiElement> targets = new ArrayList<>(); // // PsiSearchHelper searchHelper = PsiSearchHelper.getInstance(project); // // Processor<PsiFile> psiFileProcessor = psiFile -> { // for (EnvironmentVariablesUsagesProvider provider : EnvironmentVariablesProviderUtil.USAGES_PROVIDERS) { // targets.addAll(EnvironmentVariablesUtil.getUsagesElementsByKey(key, provider.getUsages(psiFile))); // } // // return true; // }; // // searchHelper.processAllFilesWithWord(key, GlobalSearchScope.allScope(project), psiFileProcessor, true); // searchHelper.processAllFilesWithWordInLiterals(key, GlobalSearchScope.allScope(project), psiFileProcessor); // searchHelper.processAllFilesWithWordInText(key, GlobalSearchScope.allScope(project), psiFileProcessor, true); // // return targets.toArray(PsiElement.EMPTY_ARRAY); // } // // private static FileAcceptResult getFileAcceptResult(VirtualFile virtualFile) { // for (EnvironmentVariablesProvider provider : EnvironmentVariablesProviderUtil.PROVIDERS) { // FileAcceptResult fileAcceptResult = provider.acceptFile(virtualFile); // if (!fileAcceptResult.isAccepted()) { // continue; // } // // return fileAcceptResult; // } // // return FileAcceptResult.NOT_ACCEPTED; // } // } // Path: src/main/java/ru/adelf/idea/dotenv/common/BaseEnvCompletionProvider.java import com.intellij.codeInsight.completion.CompletionContributor; import com.intellij.codeInsight.completion.CompletionResultSet; import com.intellij.codeInsight.completion.PrioritizedLookupElement; import com.intellij.codeInsight.lookup.LookupElementBuilder; import com.intellij.codeInsight.navigation.actions.GotoDeclarationHandler; import com.intellij.openapi.project.Project; import org.apache.commons.lang.StringUtils; import org.jetbrains.annotations.NotNull; import ru.adelf.idea.dotenv.api.EnvironmentVariablesApi; import java.util.Map; package ru.adelf.idea.dotenv.common; abstract public class BaseEnvCompletionProvider extends CompletionContributor implements GotoDeclarationHandler { protected void fillCompletionResultSet(@NotNull CompletionResultSet completionResultSet, @NotNull Project project) {
for(Map.Entry<String, String> entry : EnvironmentVariablesApi.getAllKeyValues(project).entrySet()) {
adelf/idea-php-dotenv-plugin
src/main/java/ru/adelf/idea/dotenv/inspections/LeadingCharacterInspection.java
// Path: src/main/java/ru/adelf/idea/dotenv/psi/DotEnvFile.java // public class DotEnvFile extends PsiFileBase { // public DotEnvFile(@NotNull FileViewProvider viewProvider) { // super(viewProvider, DotEnvLanguage.INSTANCE); // } // // @NotNull // @Override // public FileType getFileType() { // return DotEnvFileType.INSTANCE; // } // // @Override // public String toString() { // return ".env file"; // } // // @Override // public Icon getIcon(int flags) { // return super.getIcon(flags); // } // } // // Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvKey.java // public interface DotEnvKey extends PsiElement { // // }
import com.intellij.codeInspection.InspectionManager; import com.intellij.codeInspection.LocalInspectionTool; import com.intellij.codeInspection.ProblemDescriptor; import com.intellij.codeInspection.ProblemsHolder; import com.intellij.psi.PsiFile; import com.intellij.psi.util.PsiTreeUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import ru.adelf.idea.dotenv.psi.DotEnvFile; import ru.adelf.idea.dotenv.psi.DotEnvKey;
package ru.adelf.idea.dotenv.inspections; public class LeadingCharacterInspection extends LocalInspectionTool { // Change the display name within the plugin.xml // This needs to be here as otherwise the tests will throw errors. @NotNull @Override public String getDisplayName() { return "Invalid leading character"; } @Nullable @Override public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
// Path: src/main/java/ru/adelf/idea/dotenv/psi/DotEnvFile.java // public class DotEnvFile extends PsiFileBase { // public DotEnvFile(@NotNull FileViewProvider viewProvider) { // super(viewProvider, DotEnvLanguage.INSTANCE); // } // // @NotNull // @Override // public FileType getFileType() { // return DotEnvFileType.INSTANCE; // } // // @Override // public String toString() { // return ".env file"; // } // // @Override // public Icon getIcon(int flags) { // return super.getIcon(flags); // } // } // // Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvKey.java // public interface DotEnvKey extends PsiElement { // // } // Path: src/main/java/ru/adelf/idea/dotenv/inspections/LeadingCharacterInspection.java import com.intellij.codeInspection.InspectionManager; import com.intellij.codeInspection.LocalInspectionTool; import com.intellij.codeInspection.ProblemDescriptor; import com.intellij.codeInspection.ProblemsHolder; import com.intellij.psi.PsiFile; import com.intellij.psi.util.PsiTreeUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import ru.adelf.idea.dotenv.psi.DotEnvFile; import ru.adelf.idea.dotenv.psi.DotEnvKey; package ru.adelf.idea.dotenv.inspections; public class LeadingCharacterInspection extends LocalInspectionTool { // Change the display name within the plugin.xml // This needs to be here as otherwise the tests will throw errors. @NotNull @Override public String getDisplayName() { return "Invalid leading character"; } @Nullable @Override public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
if (!(file instanceof DotEnvFile)) {
adelf/idea-php-dotenv-plugin
src/main/java/ru/adelf/idea/dotenv/inspections/LeadingCharacterInspection.java
// Path: src/main/java/ru/adelf/idea/dotenv/psi/DotEnvFile.java // public class DotEnvFile extends PsiFileBase { // public DotEnvFile(@NotNull FileViewProvider viewProvider) { // super(viewProvider, DotEnvLanguage.INSTANCE); // } // // @NotNull // @Override // public FileType getFileType() { // return DotEnvFileType.INSTANCE; // } // // @Override // public String toString() { // return ".env file"; // } // // @Override // public Icon getIcon(int flags) { // return super.getIcon(flags); // } // } // // Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvKey.java // public interface DotEnvKey extends PsiElement { // // }
import com.intellij.codeInspection.InspectionManager; import com.intellij.codeInspection.LocalInspectionTool; import com.intellij.codeInspection.ProblemDescriptor; import com.intellij.codeInspection.ProblemsHolder; import com.intellij.psi.PsiFile; import com.intellij.psi.util.PsiTreeUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import ru.adelf.idea.dotenv.psi.DotEnvFile; import ru.adelf.idea.dotenv.psi.DotEnvKey;
package ru.adelf.idea.dotenv.inspections; public class LeadingCharacterInspection extends LocalInspectionTool { // Change the display name within the plugin.xml // This needs to be here as otherwise the tests will throw errors. @NotNull @Override public String getDisplayName() { return "Invalid leading character"; } @Nullable @Override public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) { if (!(file instanceof DotEnvFile)) { return null; } return analyzeFile(file, manager, isOnTheFly).getResultsArray(); } @NotNull private ProblemsHolder analyzeFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) { ProblemsHolder problemsHolder = new ProblemsHolder(manager, file, isOnTheFly);
// Path: src/main/java/ru/adelf/idea/dotenv/psi/DotEnvFile.java // public class DotEnvFile extends PsiFileBase { // public DotEnvFile(@NotNull FileViewProvider viewProvider) { // super(viewProvider, DotEnvLanguage.INSTANCE); // } // // @NotNull // @Override // public FileType getFileType() { // return DotEnvFileType.INSTANCE; // } // // @Override // public String toString() { // return ".env file"; // } // // @Override // public Icon getIcon(int flags) { // return super.getIcon(flags); // } // } // // Path: src/main/gen/ru/adelf/idea/dotenv/psi/DotEnvKey.java // public interface DotEnvKey extends PsiElement { // // } // Path: src/main/java/ru/adelf/idea/dotenv/inspections/LeadingCharacterInspection.java import com.intellij.codeInspection.InspectionManager; import com.intellij.codeInspection.LocalInspectionTool; import com.intellij.codeInspection.ProblemDescriptor; import com.intellij.codeInspection.ProblemsHolder; import com.intellij.psi.PsiFile; import com.intellij.psi.util.PsiTreeUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import ru.adelf.idea.dotenv.psi.DotEnvFile; import ru.adelf.idea.dotenv.psi.DotEnvKey; package ru.adelf.idea.dotenv.inspections; public class LeadingCharacterInspection extends LocalInspectionTool { // Change the display name within the plugin.xml // This needs to be here as otherwise the tests will throw errors. @NotNull @Override public String getDisplayName() { return "Invalid leading character"; } @Nullable @Override public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) { if (!(file instanceof DotEnvFile)) { return null; } return analyzeFile(file, manager, isOnTheFly).getResultsArray(); } @NotNull private ProblemsHolder analyzeFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) { ProblemsHolder problemsHolder = new ProblemsHolder(manager, file, isOnTheFly);
PsiTreeUtil.findChildrenOfType(file, DotEnvKey.class).forEach(dotEnvKey -> {
mpazik/State-synchronisation-protocol
state-synchronization-components/src/main/java/pl/marekpazik/state_synchronisation/component/store/CachedEntityStore.java
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/Change.java // public interface Change<E extends Entity<E>> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Entity.java // public interface Entity<E extends Entity<E>> { // // Id<E> getId(); // // /** // * @return and immutable state of the entity // */ // EntityState<E> getState(); // // /** // * @return immutable entity properties. // */ // EntityProperties<E> getProperties(); // // /** // * @return the version of the entity sate. // */ // Version getVersion(); // // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/EntityStore.java // public interface EntityStore { // // /** // * Store assumes that for each id object there is corresponding entity. // * @throws RuntimeException if there is no entity for the given id. // */ // <E extends Entity<E>> E getEntity(Id<E> id); // // <E extends Entity<E>> void saveChange(Id<E> id, Change<E> change); // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/UpdateChange.java // public interface UpdateChange<E extends Entity<E>> extends Change<E> { // void updateEntityState(E entity); // }
import com.google.common.cache.Cache; import pl.marekpazik.state_synchronisation.Change; import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.Entity; import pl.marekpazik.state_synchronisation.entity.EntityStore; import pl.marekpazik.state_synchronisation.entity.UpdateChange; import java.util.concurrent.ExecutionException;
package pl.marekpazik.state_synchronisation.component.store; public final class CachedEntityStore implements EntityStore { private final EntityStore entityStore;
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/Change.java // public interface Change<E extends Entity<E>> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Entity.java // public interface Entity<E extends Entity<E>> { // // Id<E> getId(); // // /** // * @return and immutable state of the entity // */ // EntityState<E> getState(); // // /** // * @return immutable entity properties. // */ // EntityProperties<E> getProperties(); // // /** // * @return the version of the entity sate. // */ // Version getVersion(); // // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/EntityStore.java // public interface EntityStore { // // /** // * Store assumes that for each id object there is corresponding entity. // * @throws RuntimeException if there is no entity for the given id. // */ // <E extends Entity<E>> E getEntity(Id<E> id); // // <E extends Entity<E>> void saveChange(Id<E> id, Change<E> change); // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/UpdateChange.java // public interface UpdateChange<E extends Entity<E>> extends Change<E> { // void updateEntityState(E entity); // } // Path: state-synchronization-components/src/main/java/pl/marekpazik/state_synchronisation/component/store/CachedEntityStore.java import com.google.common.cache.Cache; import pl.marekpazik.state_synchronisation.Change; import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.Entity; import pl.marekpazik.state_synchronisation.entity.EntityStore; import pl.marekpazik.state_synchronisation.entity.UpdateChange; import java.util.concurrent.ExecutionException; package pl.marekpazik.state_synchronisation.component.store; public final class CachedEntityStore implements EntityStore { private final EntityStore entityStore;
private final Cache<Id<?>, Entity<?>> cache;
mpazik/State-synchronisation-protocol
state-synchronization-components/src/main/java/pl/marekpazik/state_synchronisation/component/store/CachedEntityStore.java
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/Change.java // public interface Change<E extends Entity<E>> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Entity.java // public interface Entity<E extends Entity<E>> { // // Id<E> getId(); // // /** // * @return and immutable state of the entity // */ // EntityState<E> getState(); // // /** // * @return immutable entity properties. // */ // EntityProperties<E> getProperties(); // // /** // * @return the version of the entity sate. // */ // Version getVersion(); // // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/EntityStore.java // public interface EntityStore { // // /** // * Store assumes that for each id object there is corresponding entity. // * @throws RuntimeException if there is no entity for the given id. // */ // <E extends Entity<E>> E getEntity(Id<E> id); // // <E extends Entity<E>> void saveChange(Id<E> id, Change<E> change); // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/UpdateChange.java // public interface UpdateChange<E extends Entity<E>> extends Change<E> { // void updateEntityState(E entity); // }
import com.google.common.cache.Cache; import pl.marekpazik.state_synchronisation.Change; import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.Entity; import pl.marekpazik.state_synchronisation.entity.EntityStore; import pl.marekpazik.state_synchronisation.entity.UpdateChange; import java.util.concurrent.ExecutionException;
package pl.marekpazik.state_synchronisation.component.store; public final class CachedEntityStore implements EntityStore { private final EntityStore entityStore;
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/Change.java // public interface Change<E extends Entity<E>> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Entity.java // public interface Entity<E extends Entity<E>> { // // Id<E> getId(); // // /** // * @return and immutable state of the entity // */ // EntityState<E> getState(); // // /** // * @return immutable entity properties. // */ // EntityProperties<E> getProperties(); // // /** // * @return the version of the entity sate. // */ // Version getVersion(); // // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/EntityStore.java // public interface EntityStore { // // /** // * Store assumes that for each id object there is corresponding entity. // * @throws RuntimeException if there is no entity for the given id. // */ // <E extends Entity<E>> E getEntity(Id<E> id); // // <E extends Entity<E>> void saveChange(Id<E> id, Change<E> change); // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/UpdateChange.java // public interface UpdateChange<E extends Entity<E>> extends Change<E> { // void updateEntityState(E entity); // } // Path: state-synchronization-components/src/main/java/pl/marekpazik/state_synchronisation/component/store/CachedEntityStore.java import com.google.common.cache.Cache; import pl.marekpazik.state_synchronisation.Change; import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.Entity; import pl.marekpazik.state_synchronisation.entity.EntityStore; import pl.marekpazik.state_synchronisation.entity.UpdateChange; import java.util.concurrent.ExecutionException; package pl.marekpazik.state_synchronisation.component.store; public final class CachedEntityStore implements EntityStore { private final EntityStore entityStore;
private final Cache<Id<?>, Entity<?>> cache;
mpazik/State-synchronisation-protocol
state-synchronization-components/src/main/java/pl/marekpazik/state_synchronisation/component/store/CachedEntityStore.java
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/Change.java // public interface Change<E extends Entity<E>> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Entity.java // public interface Entity<E extends Entity<E>> { // // Id<E> getId(); // // /** // * @return and immutable state of the entity // */ // EntityState<E> getState(); // // /** // * @return immutable entity properties. // */ // EntityProperties<E> getProperties(); // // /** // * @return the version of the entity sate. // */ // Version getVersion(); // // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/EntityStore.java // public interface EntityStore { // // /** // * Store assumes that for each id object there is corresponding entity. // * @throws RuntimeException if there is no entity for the given id. // */ // <E extends Entity<E>> E getEntity(Id<E> id); // // <E extends Entity<E>> void saveChange(Id<E> id, Change<E> change); // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/UpdateChange.java // public interface UpdateChange<E extends Entity<E>> extends Change<E> { // void updateEntityState(E entity); // }
import com.google.common.cache.Cache; import pl.marekpazik.state_synchronisation.Change; import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.Entity; import pl.marekpazik.state_synchronisation.entity.EntityStore; import pl.marekpazik.state_synchronisation.entity.UpdateChange; import java.util.concurrent.ExecutionException;
package pl.marekpazik.state_synchronisation.component.store; public final class CachedEntityStore implements EntityStore { private final EntityStore entityStore; private final Cache<Id<?>, Entity<?>> cache; public CachedEntityStore(EntityStore entityStore, Cache<Id<?>, Entity<?>> cache) { this.entityStore = entityStore; this.cache = cache; } @Override public <E extends Entity<E>> E getEntity(Id<E> id) { try { //noinspection unchecked return (E) cache.get(id, () -> entityStore.getEntity(id)); } catch (ExecutionException e) { throw new RuntimeException(e); } } @Override
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/Change.java // public interface Change<E extends Entity<E>> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Entity.java // public interface Entity<E extends Entity<E>> { // // Id<E> getId(); // // /** // * @return and immutable state of the entity // */ // EntityState<E> getState(); // // /** // * @return immutable entity properties. // */ // EntityProperties<E> getProperties(); // // /** // * @return the version of the entity sate. // */ // Version getVersion(); // // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/EntityStore.java // public interface EntityStore { // // /** // * Store assumes that for each id object there is corresponding entity. // * @throws RuntimeException if there is no entity for the given id. // */ // <E extends Entity<E>> E getEntity(Id<E> id); // // <E extends Entity<E>> void saveChange(Id<E> id, Change<E> change); // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/UpdateChange.java // public interface UpdateChange<E extends Entity<E>> extends Change<E> { // void updateEntityState(E entity); // } // Path: state-synchronization-components/src/main/java/pl/marekpazik/state_synchronisation/component/store/CachedEntityStore.java import com.google.common.cache.Cache; import pl.marekpazik.state_synchronisation.Change; import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.Entity; import pl.marekpazik.state_synchronisation.entity.EntityStore; import pl.marekpazik.state_synchronisation.entity.UpdateChange; import java.util.concurrent.ExecutionException; package pl.marekpazik.state_synchronisation.component.store; public final class CachedEntityStore implements EntityStore { private final EntityStore entityStore; private final Cache<Id<?>, Entity<?>> cache; public CachedEntityStore(EntityStore entityStore, Cache<Id<?>, Entity<?>> cache) { this.entityStore = entityStore; this.cache = cache; } @Override public <E extends Entity<E>> E getEntity(Id<E> id) { try { //noinspection unchecked return (E) cache.get(id, () -> entityStore.getEntity(id)); } catch (ExecutionException e) { throw new RuntimeException(e); } } @Override
public <E extends Entity<E>> void saveChange(Id<E> id, Change<E> change) {
mpazik/State-synchronisation-protocol
state-synchronization-components/src/main/java/pl/marekpazik/state_synchronisation/component/store/CachedEntityStore.java
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/Change.java // public interface Change<E extends Entity<E>> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Entity.java // public interface Entity<E extends Entity<E>> { // // Id<E> getId(); // // /** // * @return and immutable state of the entity // */ // EntityState<E> getState(); // // /** // * @return immutable entity properties. // */ // EntityProperties<E> getProperties(); // // /** // * @return the version of the entity sate. // */ // Version getVersion(); // // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/EntityStore.java // public interface EntityStore { // // /** // * Store assumes that for each id object there is corresponding entity. // * @throws RuntimeException if there is no entity for the given id. // */ // <E extends Entity<E>> E getEntity(Id<E> id); // // <E extends Entity<E>> void saveChange(Id<E> id, Change<E> change); // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/UpdateChange.java // public interface UpdateChange<E extends Entity<E>> extends Change<E> { // void updateEntityState(E entity); // }
import com.google.common.cache.Cache; import pl.marekpazik.state_synchronisation.Change; import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.Entity; import pl.marekpazik.state_synchronisation.entity.EntityStore; import pl.marekpazik.state_synchronisation.entity.UpdateChange; import java.util.concurrent.ExecutionException;
package pl.marekpazik.state_synchronisation.component.store; public final class CachedEntityStore implements EntityStore { private final EntityStore entityStore; private final Cache<Id<?>, Entity<?>> cache; public CachedEntityStore(EntityStore entityStore, Cache<Id<?>, Entity<?>> cache) { this.entityStore = entityStore; this.cache = cache; } @Override public <E extends Entity<E>> E getEntity(Id<E> id) { try { //noinspection unchecked return (E) cache.get(id, () -> entityStore.getEntity(id)); } catch (ExecutionException e) { throw new RuntimeException(e); } } @Override public <E extends Entity<E>> void saveChange(Id<E> id, Change<E> change) { //noinspection unchecked E entity = (E) cache.getIfPresent(id);
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/Change.java // public interface Change<E extends Entity<E>> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Entity.java // public interface Entity<E extends Entity<E>> { // // Id<E> getId(); // // /** // * @return and immutable state of the entity // */ // EntityState<E> getState(); // // /** // * @return immutable entity properties. // */ // EntityProperties<E> getProperties(); // // /** // * @return the version of the entity sate. // */ // Version getVersion(); // // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/EntityStore.java // public interface EntityStore { // // /** // * Store assumes that for each id object there is corresponding entity. // * @throws RuntimeException if there is no entity for the given id. // */ // <E extends Entity<E>> E getEntity(Id<E> id); // // <E extends Entity<E>> void saveChange(Id<E> id, Change<E> change); // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/UpdateChange.java // public interface UpdateChange<E extends Entity<E>> extends Change<E> { // void updateEntityState(E entity); // } // Path: state-synchronization-components/src/main/java/pl/marekpazik/state_synchronisation/component/store/CachedEntityStore.java import com.google.common.cache.Cache; import pl.marekpazik.state_synchronisation.Change; import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.Entity; import pl.marekpazik.state_synchronisation.entity.EntityStore; import pl.marekpazik.state_synchronisation.entity.UpdateChange; import java.util.concurrent.ExecutionException; package pl.marekpazik.state_synchronisation.component.store; public final class CachedEntityStore implements EntityStore { private final EntityStore entityStore; private final Cache<Id<?>, Entity<?>> cache; public CachedEntityStore(EntityStore entityStore, Cache<Id<?>, Entity<?>> cache) { this.entityStore = entityStore; this.cache = cache; } @Override public <E extends Entity<E>> E getEntity(Id<E> id) { try { //noinspection unchecked return (E) cache.get(id, () -> entityStore.getEntity(id)); } catch (ExecutionException e) { throw new RuntimeException(e); } } @Override public <E extends Entity<E>> void saveChange(Id<E> id, Change<E> change) { //noinspection unchecked E entity = (E) cache.getIfPresent(id);
if (entity != null && change instanceof UpdateChange) {
mpazik/State-synchronisation-protocol
state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/character/CharacterMoved.java
// Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/Position.java // public final class Position { // public final double x; // public final double y; // // public Position(double x, double y) { // this.x = x; // this.y = y; // } // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/character/GameCharacter.java // public static final class Properties implements EntityProperties<GameCharacter> { // public final String name; // public final GameCharacterType gameCharacterType; // // public Properties(String name, GameCharacterType gameCharacterType) { // this.name = name; // this.gameCharacterType = gameCharacterType; // } // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/character/GameCharacter.java // public static final class State implements EntityState<GameCharacter> { // public final Position position; // // public State(Position position) { // this.position = position; // } // }
import pl.marekpazik.state_synchronisation.reference_implementation.Position; import pl.marekpazik.state_synchronisation.reference_implementation.character.GameCharacter.Properties; import pl.marekpazik.state_synchronisation.reference_implementation.character.GameCharacter.State;
package pl.marekpazik.state_synchronisation.reference_implementation.character; public class CharacterMoved extends CharacterUpdateChange { public final Position newPosition; public CharacterMoved(Position newPosition) { this.newPosition = newPosition; } @Override
// Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/Position.java // public final class Position { // public final double x; // public final double y; // // public Position(double x, double y) { // this.x = x; // this.y = y; // } // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/character/GameCharacter.java // public static final class Properties implements EntityProperties<GameCharacter> { // public final String name; // public final GameCharacterType gameCharacterType; // // public Properties(String name, GameCharacterType gameCharacterType) { // this.name = name; // this.gameCharacterType = gameCharacterType; // } // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/character/GameCharacter.java // public static final class State implements EntityState<GameCharacter> { // public final Position position; // // public State(Position position) { // this.position = position; // } // } // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/character/CharacterMoved.java import pl.marekpazik.state_synchronisation.reference_implementation.Position; import pl.marekpazik.state_synchronisation.reference_implementation.character.GameCharacter.Properties; import pl.marekpazik.state_synchronisation.reference_implementation.character.GameCharacter.State; package pl.marekpazik.state_synchronisation.reference_implementation.character; public class CharacterMoved extends CharacterUpdateChange { public final Position newPosition; public CharacterMoved(Position newPosition) { this.newPosition = newPosition; } @Override
public State calculateNewState(Properties properties, State state) {
mpazik/State-synchronisation-protocol
state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/character/CharacterMoved.java
// Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/Position.java // public final class Position { // public final double x; // public final double y; // // public Position(double x, double y) { // this.x = x; // this.y = y; // } // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/character/GameCharacter.java // public static final class Properties implements EntityProperties<GameCharacter> { // public final String name; // public final GameCharacterType gameCharacterType; // // public Properties(String name, GameCharacterType gameCharacterType) { // this.name = name; // this.gameCharacterType = gameCharacterType; // } // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/character/GameCharacter.java // public static final class State implements EntityState<GameCharacter> { // public final Position position; // // public State(Position position) { // this.position = position; // } // }
import pl.marekpazik.state_synchronisation.reference_implementation.Position; import pl.marekpazik.state_synchronisation.reference_implementation.character.GameCharacter.Properties; import pl.marekpazik.state_synchronisation.reference_implementation.character.GameCharacter.State;
package pl.marekpazik.state_synchronisation.reference_implementation.character; public class CharacterMoved extends CharacterUpdateChange { public final Position newPosition; public CharacterMoved(Position newPosition) { this.newPosition = newPosition; } @Override
// Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/Position.java // public final class Position { // public final double x; // public final double y; // // public Position(double x, double y) { // this.x = x; // this.y = y; // } // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/character/GameCharacter.java // public static final class Properties implements EntityProperties<GameCharacter> { // public final String name; // public final GameCharacterType gameCharacterType; // // public Properties(String name, GameCharacterType gameCharacterType) { // this.name = name; // this.gameCharacterType = gameCharacterType; // } // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/character/GameCharacter.java // public static final class State implements EntityState<GameCharacter> { // public final Position position; // // public State(Position position) { // this.position = position; // } // } // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/character/CharacterMoved.java import pl.marekpazik.state_synchronisation.reference_implementation.Position; import pl.marekpazik.state_synchronisation.reference_implementation.character.GameCharacter.Properties; import pl.marekpazik.state_synchronisation.reference_implementation.character.GameCharacter.State; package pl.marekpazik.state_synchronisation.reference_implementation.character; public class CharacterMoved extends CharacterUpdateChange { public final Position newPosition; public CharacterMoved(Position newPosition) { this.newPosition = newPosition; } @Override
public State calculateNewState(Properties properties, State state) {
mpazik/State-synchronisation-protocol
state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/character/GameCharacter.java
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/Position.java // public final class Position { // public final double x; // public final double y; // // public Position(double x, double y) { // this.x = x; // this.y = y; // } // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/StringEntityType.java // public class StringEntityType<E extends Entity<E>> implements EntityType<E> { // private final String type; // // public StringEntityType(String type) { // this.type = type; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // StringEntityType<?> that = (StringEntityType<?>) o; // return Objects.equals(type, that.type); // } // // @Override // public int hashCode() { // return Objects.hash(type); // } // }
import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.*; import pl.marekpazik.state_synchronisation.reference_implementation.Position; import pl.marekpazik.state_synchronisation.reference_implementation.StringEntityType;
package pl.marekpazik.state_synchronisation.reference_implementation.character; public final class GameCharacter extends AbstractEntity<GameCharacter, GameCharacter.Properties, GameCharacter.State> { public static EntityType<GameCharacter> entityType = new StringEntityType<>("character");
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/Position.java // public final class Position { // public final double x; // public final double y; // // public Position(double x, double y) { // this.x = x; // this.y = y; // } // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/StringEntityType.java // public class StringEntityType<E extends Entity<E>> implements EntityType<E> { // private final String type; // // public StringEntityType(String type) { // this.type = type; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // StringEntityType<?> that = (StringEntityType<?>) o; // return Objects.equals(type, that.type); // } // // @Override // public int hashCode() { // return Objects.hash(type); // } // } // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/character/GameCharacter.java import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.*; import pl.marekpazik.state_synchronisation.reference_implementation.Position; import pl.marekpazik.state_synchronisation.reference_implementation.StringEntityType; package pl.marekpazik.state_synchronisation.reference_implementation.character; public final class GameCharacter extends AbstractEntity<GameCharacter, GameCharacter.Properties, GameCharacter.State> { public static EntityType<GameCharacter> entityType = new StringEntityType<>("character");
public GameCharacter(Id<GameCharacter> id, Properties properties, State state) {
mpazik/State-synchronisation-protocol
state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/character/GameCharacter.java
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/Position.java // public final class Position { // public final double x; // public final double y; // // public Position(double x, double y) { // this.x = x; // this.y = y; // } // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/StringEntityType.java // public class StringEntityType<E extends Entity<E>> implements EntityType<E> { // private final String type; // // public StringEntityType(String type) { // this.type = type; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // StringEntityType<?> that = (StringEntityType<?>) o; // return Objects.equals(type, that.type); // } // // @Override // public int hashCode() { // return Objects.hash(type); // } // }
import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.*; import pl.marekpazik.state_synchronisation.reference_implementation.Position; import pl.marekpazik.state_synchronisation.reference_implementation.StringEntityType;
package pl.marekpazik.state_synchronisation.reference_implementation.character; public final class GameCharacter extends AbstractEntity<GameCharacter, GameCharacter.Properties, GameCharacter.State> { public static EntityType<GameCharacter> entityType = new StringEntityType<>("character"); public GameCharacter(Id<GameCharacter> id, Properties properties, State state) { super(id, properties, state); } public enum GameCharacterType { Player, Mob } public static final class Properties implements EntityProperties<GameCharacter> { public final String name; public final GameCharacterType gameCharacterType; public Properties(String name, GameCharacterType gameCharacterType) { this.name = name; this.gameCharacterType = gameCharacterType; } } public static final class State implements EntityState<GameCharacter> {
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/Position.java // public final class Position { // public final double x; // public final double y; // // public Position(double x, double y) { // this.x = x; // this.y = y; // } // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/StringEntityType.java // public class StringEntityType<E extends Entity<E>> implements EntityType<E> { // private final String type; // // public StringEntityType(String type) { // this.type = type; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // StringEntityType<?> that = (StringEntityType<?>) o; // return Objects.equals(type, that.type); // } // // @Override // public int hashCode() { // return Objects.hash(type); // } // } // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/character/GameCharacter.java import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.*; import pl.marekpazik.state_synchronisation.reference_implementation.Position; import pl.marekpazik.state_synchronisation.reference_implementation.StringEntityType; package pl.marekpazik.state_synchronisation.reference_implementation.character; public final class GameCharacter extends AbstractEntity<GameCharacter, GameCharacter.Properties, GameCharacter.State> { public static EntityType<GameCharacter> entityType = new StringEntityType<>("character"); public GameCharacter(Id<GameCharacter> id, Properties properties, State state) { super(id, properties, state); } public enum GameCharacterType { Player, Mob } public static final class Properties implements EntityProperties<GameCharacter> { public final String name; public final GameCharacterType gameCharacterType; public Properties(String name, GameCharacterType gameCharacterType) { this.name = name; this.gameCharacterType = gameCharacterType; } } public static final class State implements EntityState<GameCharacter> {
public final Position position;
mpazik/State-synchronisation-protocol
state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/character/CharacterCreated.java
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/CreationChange.java // public interface CreationChange<E extends Entity<E>> extends Change<E> { // E createEntity(Id<E> entityId); // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/Position.java // public final class Position { // public final double x; // public final double y; // // public Position(double x, double y) { // this.x = x; // this.y = y; // } // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/character/GameCharacter.java // public static final class Properties implements EntityProperties<GameCharacter> { // public final String name; // public final GameCharacterType gameCharacterType; // // public Properties(String name, GameCharacterType gameCharacterType) { // this.name = name; // this.gameCharacterType = gameCharacterType; // } // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/character/GameCharacter.java // public static final class State implements EntityState<GameCharacter> { // public final Position position; // // public State(Position position) { // this.position = position; // } // }
import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.CreationChange; import pl.marekpazik.state_synchronisation.reference_implementation.Position; import pl.marekpazik.state_synchronisation.reference_implementation.character.GameCharacter.Properties; import pl.marekpazik.state_synchronisation.reference_implementation.character.GameCharacter.State;
package pl.marekpazik.state_synchronisation.reference_implementation.character; public class CharacterCreated implements CreationChange<GameCharacter> { public final String name; public final GameCharacter.GameCharacterType type;
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/CreationChange.java // public interface CreationChange<E extends Entity<E>> extends Change<E> { // E createEntity(Id<E> entityId); // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/Position.java // public final class Position { // public final double x; // public final double y; // // public Position(double x, double y) { // this.x = x; // this.y = y; // } // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/character/GameCharacter.java // public static final class Properties implements EntityProperties<GameCharacter> { // public final String name; // public final GameCharacterType gameCharacterType; // // public Properties(String name, GameCharacterType gameCharacterType) { // this.name = name; // this.gameCharacterType = gameCharacterType; // } // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/character/GameCharacter.java // public static final class State implements EntityState<GameCharacter> { // public final Position position; // // public State(Position position) { // this.position = position; // } // } // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/character/CharacterCreated.java import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.CreationChange; import pl.marekpazik.state_synchronisation.reference_implementation.Position; import pl.marekpazik.state_synchronisation.reference_implementation.character.GameCharacter.Properties; import pl.marekpazik.state_synchronisation.reference_implementation.character.GameCharacter.State; package pl.marekpazik.state_synchronisation.reference_implementation.character; public class CharacterCreated implements CreationChange<GameCharacter> { public final String name; public final GameCharacter.GameCharacterType type;
public final Position position;
mpazik/State-synchronisation-protocol
state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/character/CharacterCreated.java
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/CreationChange.java // public interface CreationChange<E extends Entity<E>> extends Change<E> { // E createEntity(Id<E> entityId); // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/Position.java // public final class Position { // public final double x; // public final double y; // // public Position(double x, double y) { // this.x = x; // this.y = y; // } // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/character/GameCharacter.java // public static final class Properties implements EntityProperties<GameCharacter> { // public final String name; // public final GameCharacterType gameCharacterType; // // public Properties(String name, GameCharacterType gameCharacterType) { // this.name = name; // this.gameCharacterType = gameCharacterType; // } // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/character/GameCharacter.java // public static final class State implements EntityState<GameCharacter> { // public final Position position; // // public State(Position position) { // this.position = position; // } // }
import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.CreationChange; import pl.marekpazik.state_synchronisation.reference_implementation.Position; import pl.marekpazik.state_synchronisation.reference_implementation.character.GameCharacter.Properties; import pl.marekpazik.state_synchronisation.reference_implementation.character.GameCharacter.State;
package pl.marekpazik.state_synchronisation.reference_implementation.character; public class CharacterCreated implements CreationChange<GameCharacter> { public final String name; public final GameCharacter.GameCharacterType type; public final Position position; public CharacterCreated(String name, GameCharacter.GameCharacterType type, Position position) { this.name = name; this.type = type; this.position = position; } @Override
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/CreationChange.java // public interface CreationChange<E extends Entity<E>> extends Change<E> { // E createEntity(Id<E> entityId); // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/Position.java // public final class Position { // public final double x; // public final double y; // // public Position(double x, double y) { // this.x = x; // this.y = y; // } // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/character/GameCharacter.java // public static final class Properties implements EntityProperties<GameCharacter> { // public final String name; // public final GameCharacterType gameCharacterType; // // public Properties(String name, GameCharacterType gameCharacterType) { // this.name = name; // this.gameCharacterType = gameCharacterType; // } // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/character/GameCharacter.java // public static final class State implements EntityState<GameCharacter> { // public final Position position; // // public State(Position position) { // this.position = position; // } // } // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/character/CharacterCreated.java import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.CreationChange; import pl.marekpazik.state_synchronisation.reference_implementation.Position; import pl.marekpazik.state_synchronisation.reference_implementation.character.GameCharacter.Properties; import pl.marekpazik.state_synchronisation.reference_implementation.character.GameCharacter.State; package pl.marekpazik.state_synchronisation.reference_implementation.character; public class CharacterCreated implements CreationChange<GameCharacter> { public final String name; public final GameCharacter.GameCharacterType type; public final Position position; public CharacterCreated(String name, GameCharacter.GameCharacterType type, Position position) { this.name = name; this.type = type; this.position = position; } @Override
public GameCharacter createEntity(Id<GameCharacter> entityId) {
mpazik/State-synchronisation-protocol
state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/character/CharacterCreated.java
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/CreationChange.java // public interface CreationChange<E extends Entity<E>> extends Change<E> { // E createEntity(Id<E> entityId); // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/Position.java // public final class Position { // public final double x; // public final double y; // // public Position(double x, double y) { // this.x = x; // this.y = y; // } // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/character/GameCharacter.java // public static final class Properties implements EntityProperties<GameCharacter> { // public final String name; // public final GameCharacterType gameCharacterType; // // public Properties(String name, GameCharacterType gameCharacterType) { // this.name = name; // this.gameCharacterType = gameCharacterType; // } // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/character/GameCharacter.java // public static final class State implements EntityState<GameCharacter> { // public final Position position; // // public State(Position position) { // this.position = position; // } // }
import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.CreationChange; import pl.marekpazik.state_synchronisation.reference_implementation.Position; import pl.marekpazik.state_synchronisation.reference_implementation.character.GameCharacter.Properties; import pl.marekpazik.state_synchronisation.reference_implementation.character.GameCharacter.State;
package pl.marekpazik.state_synchronisation.reference_implementation.character; public class CharacterCreated implements CreationChange<GameCharacter> { public final String name; public final GameCharacter.GameCharacterType type; public final Position position; public CharacterCreated(String name, GameCharacter.GameCharacterType type, Position position) { this.name = name; this.type = type; this.position = position; } @Override public GameCharacter createEntity(Id<GameCharacter> entityId) {
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/CreationChange.java // public interface CreationChange<E extends Entity<E>> extends Change<E> { // E createEntity(Id<E> entityId); // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/Position.java // public final class Position { // public final double x; // public final double y; // // public Position(double x, double y) { // this.x = x; // this.y = y; // } // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/character/GameCharacter.java // public static final class Properties implements EntityProperties<GameCharacter> { // public final String name; // public final GameCharacterType gameCharacterType; // // public Properties(String name, GameCharacterType gameCharacterType) { // this.name = name; // this.gameCharacterType = gameCharacterType; // } // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/character/GameCharacter.java // public static final class State implements EntityState<GameCharacter> { // public final Position position; // // public State(Position position) { // this.position = position; // } // } // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/character/CharacterCreated.java import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.CreationChange; import pl.marekpazik.state_synchronisation.reference_implementation.Position; import pl.marekpazik.state_synchronisation.reference_implementation.character.GameCharacter.Properties; import pl.marekpazik.state_synchronisation.reference_implementation.character.GameCharacter.State; package pl.marekpazik.state_synchronisation.reference_implementation.character; public class CharacterCreated implements CreationChange<GameCharacter> { public final String name; public final GameCharacter.GameCharacterType type; public final Position position; public CharacterCreated(String name, GameCharacter.GameCharacterType type, Position position) { this.name = name; this.type = type; this.position = position; } @Override public GameCharacter createEntity(Id<GameCharacter> entityId) {
return new GameCharacter(entityId, new Properties(name, type), new State(position));
mpazik/State-synchronisation-protocol
state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/character/CharacterCreated.java
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/CreationChange.java // public interface CreationChange<E extends Entity<E>> extends Change<E> { // E createEntity(Id<E> entityId); // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/Position.java // public final class Position { // public final double x; // public final double y; // // public Position(double x, double y) { // this.x = x; // this.y = y; // } // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/character/GameCharacter.java // public static final class Properties implements EntityProperties<GameCharacter> { // public final String name; // public final GameCharacterType gameCharacterType; // // public Properties(String name, GameCharacterType gameCharacterType) { // this.name = name; // this.gameCharacterType = gameCharacterType; // } // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/character/GameCharacter.java // public static final class State implements EntityState<GameCharacter> { // public final Position position; // // public State(Position position) { // this.position = position; // } // }
import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.CreationChange; import pl.marekpazik.state_synchronisation.reference_implementation.Position; import pl.marekpazik.state_synchronisation.reference_implementation.character.GameCharacter.Properties; import pl.marekpazik.state_synchronisation.reference_implementation.character.GameCharacter.State;
package pl.marekpazik.state_synchronisation.reference_implementation.character; public class CharacterCreated implements CreationChange<GameCharacter> { public final String name; public final GameCharacter.GameCharacterType type; public final Position position; public CharacterCreated(String name, GameCharacter.GameCharacterType type, Position position) { this.name = name; this.type = type; this.position = position; } @Override public GameCharacter createEntity(Id<GameCharacter> entityId) {
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/CreationChange.java // public interface CreationChange<E extends Entity<E>> extends Change<E> { // E createEntity(Id<E> entityId); // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/Position.java // public final class Position { // public final double x; // public final double y; // // public Position(double x, double y) { // this.x = x; // this.y = y; // } // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/character/GameCharacter.java // public static final class Properties implements EntityProperties<GameCharacter> { // public final String name; // public final GameCharacterType gameCharacterType; // // public Properties(String name, GameCharacterType gameCharacterType) { // this.name = name; // this.gameCharacterType = gameCharacterType; // } // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/character/GameCharacter.java // public static final class State implements EntityState<GameCharacter> { // public final Position position; // // public State(Position position) { // this.position = position; // } // } // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/character/CharacterCreated.java import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.CreationChange; import pl.marekpazik.state_synchronisation.reference_implementation.Position; import pl.marekpazik.state_synchronisation.reference_implementation.character.GameCharacter.Properties; import pl.marekpazik.state_synchronisation.reference_implementation.character.GameCharacter.State; package pl.marekpazik.state_synchronisation.reference_implementation.character; public class CharacterCreated implements CreationChange<GameCharacter> { public final String name; public final GameCharacter.GameCharacterType type; public final Position position; public CharacterCreated(String name, GameCharacter.GameCharacterType type, Position position) { this.name = name; this.type = type; this.position = position; } @Override public GameCharacter createEntity(Id<GameCharacter> entityId) {
return new GameCharacter(entityId, new Properties(name, type), new State(position));
mpazik/State-synchronisation-protocol
state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Changes.java
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/Change.java // public interface Change<E extends Entity<E>> { // }
import com.google.common.collect.ImmutableList; import pl.marekpazik.state_synchronisation.Change; import java.util.List; import java.util.Objects; import java.util.stream.Collectors;
package pl.marekpazik.state_synchronisation.entity; /** * Entity changes since it creation. It guarantees that the first change is a {@link CreationChange}. */ public final class Changes<E extends Entity<E>> { private final CreationChange<E> creationChange; private final List<UpdateChange<E>> changes;
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/Change.java // public interface Change<E extends Entity<E>> { // } // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Changes.java import com.google.common.collect.ImmutableList; import pl.marekpazik.state_synchronisation.Change; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; package pl.marekpazik.state_synchronisation.entity; /** * Entity changes since it creation. It guarantees that the first change is a {@link CreationChange}. */ public final class Changes<E extends Entity<E>> { private final CreationChange<E> creationChange; private final List<UpdateChange<E>> changes;
public Changes(List<Change<E>> changes) {
mpazik/State-synchronisation-protocol
state-synchronization-api/src/test/java/pl/marekpazik/state_synchronisation/entity/EntityStoreTest.java
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // }
import org.junit.Before; import org.junit.Test; import pl.marekpazik.state_synchronisation.common.Id; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.ThrowableAssert.catchThrowable;
package pl.marekpazik.state_synchronisation.entity; public abstract class EntityStoreTest<E extends Entity<E>> { EntityStore entityStore; @Before public void setUp() throws Exception { entityStore = createSut(); } @Test public void getEntity_ifExists_returnsIt() {
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // Path: state-synchronization-api/src/test/java/pl/marekpazik/state_synchronisation/entity/EntityStoreTest.java import org.junit.Before; import org.junit.Test; import pl.marekpazik.state_synchronisation.common.Id; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.ThrowableAssert.catchThrowable; package pl.marekpazik.state_synchronisation.entity; public abstract class EntityStoreTest<E extends Entity<E>> { EntityStore entityStore; @Before public void setUp() throws Exception { entityStore = createSut(); } @Test public void getEntity_ifExists_returnsIt() {
Id<E> id = generateId();
mpazik/State-synchronisation-protocol
state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/id/LongIdGenerator.java
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Entity.java // public interface Entity<E extends Entity<E>> { // // Id<E> getId(); // // /** // * @return and immutable state of the entity // */ // EntityState<E> getState(); // // /** // * @return immutable entity properties. // */ // EntityProperties<E> getProperties(); // // /** // * @return the version of the entity sate. // */ // Version getVersion(); // // }
import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.Entity;
package pl.marekpazik.state_synchronisation.reference_implementation.id; public class LongIdGenerator { private long lastId = 0;
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Entity.java // public interface Entity<E extends Entity<E>> { // // Id<E> getId(); // // /** // * @return and immutable state of the entity // */ // EntityState<E> getState(); // // /** // * @return immutable entity properties. // */ // EntityProperties<E> getProperties(); // // /** // * @return the version of the entity sate. // */ // Version getVersion(); // // } // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/id/LongIdGenerator.java import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.Entity; package pl.marekpazik.state_synchronisation.reference_implementation.id; public class LongIdGenerator { private long lastId = 0;
public <E extends Entity<E>> Id<E> generateId() {
mpazik/State-synchronisation-protocol
state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/id/LongIdGenerator.java
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Entity.java // public interface Entity<E extends Entity<E>> { // // Id<E> getId(); // // /** // * @return and immutable state of the entity // */ // EntityState<E> getState(); // // /** // * @return immutable entity properties. // */ // EntityProperties<E> getProperties(); // // /** // * @return the version of the entity sate. // */ // Version getVersion(); // // }
import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.Entity;
package pl.marekpazik.state_synchronisation.reference_implementation.id; public class LongIdGenerator { private long lastId = 0;
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Entity.java // public interface Entity<E extends Entity<E>> { // // Id<E> getId(); // // /** // * @return and immutable state of the entity // */ // EntityState<E> getState(); // // /** // * @return immutable entity properties. // */ // EntityProperties<E> getProperties(); // // /** // * @return the version of the entity sate. // */ // Version getVersion(); // // } // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/id/LongIdGenerator.java import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.Entity; package pl.marekpazik.state_synchronisation.reference_implementation.id; public class LongIdGenerator { private long lastId = 0;
public <E extends Entity<E>> Id<E> generateId() {
mpazik/State-synchronisation-protocol
state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Entity.java
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/Version.java // public final class Version { // private final int version; // // private Version(int version) { // this.version = version; // } // // public Version next() { // return new Version(version + 1); // } // // public static Version first() { // return new Version(1); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // Version version1 = (Version) o; // return version == version1.version; // } // // @Override // public int hashCode() { // return Objects.hash(version); // } // // @Override // public String toString() { // return "Version{" + // "version=" + version + // '}'; // } // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // }
import pl.marekpazik.state_synchronisation.Version; import pl.marekpazik.state_synchronisation.common.Id;
package pl.marekpazik.state_synchronisation.entity; public interface Entity<E extends Entity<E>> { Id<E> getId(); /** * @return and immutable state of the entity */ EntityState<E> getState(); /** * @return immutable entity properties. */ EntityProperties<E> getProperties(); /** * @return the version of the entity sate. */
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/Version.java // public final class Version { // private final int version; // // private Version(int version) { // this.version = version; // } // // public Version next() { // return new Version(version + 1); // } // // public static Version first() { // return new Version(1); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // Version version1 = (Version) o; // return version == version1.version; // } // // @Override // public int hashCode() { // return Objects.hash(version); // } // // @Override // public String toString() { // return "Version{" + // "version=" + version + // '}'; // } // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Entity.java import pl.marekpazik.state_synchronisation.Version; import pl.marekpazik.state_synchronisation.common.Id; package pl.marekpazik.state_synchronisation.entity; public interface Entity<E extends Entity<E>> { Id<E> getId(); /** * @return and immutable state of the entity */ EntityState<E> getState(); /** * @return immutable entity properties. */ EntityProperties<E> getProperties(); /** * @return the version of the entity sate. */
Version getVersion();
mpazik/State-synchronisation-protocol
state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/InMemoryChangesStore.java
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/Change.java // public interface Change<E extends Entity<E>> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/ChangesStore.java // public interface ChangesStore { // // <E extends Entity<E>> Changes<E> getAllChanges(Id<E> id); // // /** // * All changes have to be saved to this store. // */ // <E extends Entity<E>> void saveChange(Id<E> id, Change<E> change); // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Changes.java // public final class Changes<E extends Entity<E>> { // private final CreationChange<E> creationChange; // private final List<UpdateChange<E>> changes; // // public Changes(List<Change<E>> changes) { // assert changes.size() > 0; // assert changes.get(0) instanceof CreationChange; // creationChange = (CreationChange<E>) changes.get(0); // this.changes = changes.stream().skip(1).map(change -> (UpdateChange<E>) change).collect(Collectors.toList()); // } // // public CreationChange<E> getCreationChange() { // return creationChange; // } // // public List<UpdateChange<E>> getUpdateChanges() { // return changes; // } // // public List<Change<E>> getAsList() { // return ImmutableList.<Change<E>>builder().add(creationChange).addAll(changes).build(); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // Changes<?> changes1 = (Changes<?>) o; // return Objects.equals(changes, changes1.changes); // } // // @Override // public int hashCode() { // return Objects.hash(changes); // } // // @Override // public String toString() { // return "Changes{" + // "changes=" + changes + // '}'; // } // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Entity.java // public interface Entity<E extends Entity<E>> { // // Id<E> getId(); // // /** // * @return and immutable state of the entity // */ // EntityState<E> getState(); // // /** // * @return immutable entity properties. // */ // EntityProperties<E> getProperties(); // // /** // * @return the version of the entity sate. // */ // Version getVersion(); // // }
import com.google.common.collect.ImmutableList; import pl.marekpazik.state_synchronisation.Change; import pl.marekpazik.state_synchronisation.ChangesStore; import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.Changes; import pl.marekpazik.state_synchronisation.entity.Entity; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Stream;
package pl.marekpazik.state_synchronisation.reference_implementation; public class InMemoryChangesStore implements ChangesStore { Map<Id<?>, List<Change<?>>> changes = new HashMap<>(); @Override
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/Change.java // public interface Change<E extends Entity<E>> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/ChangesStore.java // public interface ChangesStore { // // <E extends Entity<E>> Changes<E> getAllChanges(Id<E> id); // // /** // * All changes have to be saved to this store. // */ // <E extends Entity<E>> void saveChange(Id<E> id, Change<E> change); // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Changes.java // public final class Changes<E extends Entity<E>> { // private final CreationChange<E> creationChange; // private final List<UpdateChange<E>> changes; // // public Changes(List<Change<E>> changes) { // assert changes.size() > 0; // assert changes.get(0) instanceof CreationChange; // creationChange = (CreationChange<E>) changes.get(0); // this.changes = changes.stream().skip(1).map(change -> (UpdateChange<E>) change).collect(Collectors.toList()); // } // // public CreationChange<E> getCreationChange() { // return creationChange; // } // // public List<UpdateChange<E>> getUpdateChanges() { // return changes; // } // // public List<Change<E>> getAsList() { // return ImmutableList.<Change<E>>builder().add(creationChange).addAll(changes).build(); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // Changes<?> changes1 = (Changes<?>) o; // return Objects.equals(changes, changes1.changes); // } // // @Override // public int hashCode() { // return Objects.hash(changes); // } // // @Override // public String toString() { // return "Changes{" + // "changes=" + changes + // '}'; // } // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Entity.java // public interface Entity<E extends Entity<E>> { // // Id<E> getId(); // // /** // * @return and immutable state of the entity // */ // EntityState<E> getState(); // // /** // * @return immutable entity properties. // */ // EntityProperties<E> getProperties(); // // /** // * @return the version of the entity sate. // */ // Version getVersion(); // // } // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/InMemoryChangesStore.java import com.google.common.collect.ImmutableList; import pl.marekpazik.state_synchronisation.Change; import pl.marekpazik.state_synchronisation.ChangesStore; import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.Changes; import pl.marekpazik.state_synchronisation.entity.Entity; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Stream; package pl.marekpazik.state_synchronisation.reference_implementation; public class InMemoryChangesStore implements ChangesStore { Map<Id<?>, List<Change<?>>> changes = new HashMap<>(); @Override
public <E extends Entity<E>> Changes<E> getAllChanges(Id<E> id) {
mpazik/State-synchronisation-protocol
state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/InMemoryChangesStore.java
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/Change.java // public interface Change<E extends Entity<E>> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/ChangesStore.java // public interface ChangesStore { // // <E extends Entity<E>> Changes<E> getAllChanges(Id<E> id); // // /** // * All changes have to be saved to this store. // */ // <E extends Entity<E>> void saveChange(Id<E> id, Change<E> change); // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Changes.java // public final class Changes<E extends Entity<E>> { // private final CreationChange<E> creationChange; // private final List<UpdateChange<E>> changes; // // public Changes(List<Change<E>> changes) { // assert changes.size() > 0; // assert changes.get(0) instanceof CreationChange; // creationChange = (CreationChange<E>) changes.get(0); // this.changes = changes.stream().skip(1).map(change -> (UpdateChange<E>) change).collect(Collectors.toList()); // } // // public CreationChange<E> getCreationChange() { // return creationChange; // } // // public List<UpdateChange<E>> getUpdateChanges() { // return changes; // } // // public List<Change<E>> getAsList() { // return ImmutableList.<Change<E>>builder().add(creationChange).addAll(changes).build(); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // Changes<?> changes1 = (Changes<?>) o; // return Objects.equals(changes, changes1.changes); // } // // @Override // public int hashCode() { // return Objects.hash(changes); // } // // @Override // public String toString() { // return "Changes{" + // "changes=" + changes + // '}'; // } // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Entity.java // public interface Entity<E extends Entity<E>> { // // Id<E> getId(); // // /** // * @return and immutable state of the entity // */ // EntityState<E> getState(); // // /** // * @return immutable entity properties. // */ // EntityProperties<E> getProperties(); // // /** // * @return the version of the entity sate. // */ // Version getVersion(); // // }
import com.google.common.collect.ImmutableList; import pl.marekpazik.state_synchronisation.Change; import pl.marekpazik.state_synchronisation.ChangesStore; import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.Changes; import pl.marekpazik.state_synchronisation.entity.Entity; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Stream;
package pl.marekpazik.state_synchronisation.reference_implementation; public class InMemoryChangesStore implements ChangesStore { Map<Id<?>, List<Change<?>>> changes = new HashMap<>(); @Override
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/Change.java // public interface Change<E extends Entity<E>> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/ChangesStore.java // public interface ChangesStore { // // <E extends Entity<E>> Changes<E> getAllChanges(Id<E> id); // // /** // * All changes have to be saved to this store. // */ // <E extends Entity<E>> void saveChange(Id<E> id, Change<E> change); // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Changes.java // public final class Changes<E extends Entity<E>> { // private final CreationChange<E> creationChange; // private final List<UpdateChange<E>> changes; // // public Changes(List<Change<E>> changes) { // assert changes.size() > 0; // assert changes.get(0) instanceof CreationChange; // creationChange = (CreationChange<E>) changes.get(0); // this.changes = changes.stream().skip(1).map(change -> (UpdateChange<E>) change).collect(Collectors.toList()); // } // // public CreationChange<E> getCreationChange() { // return creationChange; // } // // public List<UpdateChange<E>> getUpdateChanges() { // return changes; // } // // public List<Change<E>> getAsList() { // return ImmutableList.<Change<E>>builder().add(creationChange).addAll(changes).build(); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // Changes<?> changes1 = (Changes<?>) o; // return Objects.equals(changes, changes1.changes); // } // // @Override // public int hashCode() { // return Objects.hash(changes); // } // // @Override // public String toString() { // return "Changes{" + // "changes=" + changes + // '}'; // } // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Entity.java // public interface Entity<E extends Entity<E>> { // // Id<E> getId(); // // /** // * @return and immutable state of the entity // */ // EntityState<E> getState(); // // /** // * @return immutable entity properties. // */ // EntityProperties<E> getProperties(); // // /** // * @return the version of the entity sate. // */ // Version getVersion(); // // } // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/InMemoryChangesStore.java import com.google.common.collect.ImmutableList; import pl.marekpazik.state_synchronisation.Change; import pl.marekpazik.state_synchronisation.ChangesStore; import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.Changes; import pl.marekpazik.state_synchronisation.entity.Entity; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Stream; package pl.marekpazik.state_synchronisation.reference_implementation; public class InMemoryChangesStore implements ChangesStore { Map<Id<?>, List<Change<?>>> changes = new HashMap<>(); @Override
public <E extends Entity<E>> Changes<E> getAllChanges(Id<E> id) {
mpazik/State-synchronisation-protocol
state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/EntityStore.java
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/Change.java // public interface Change<E extends Entity<E>> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // }
import pl.marekpazik.state_synchronisation.Change; import pl.marekpazik.state_synchronisation.common.Id;
package pl.marekpazik.state_synchronisation.entity; /** * Store that returns entity with the latest state for the given {@link Id} * All changes have to be saved to this store. */ public interface EntityStore { /** * Store assumes that for each id object there is corresponding entity. * @throws RuntimeException if there is no entity for the given id. */ <E extends Entity<E>> E getEntity(Id<E> id);
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/Change.java // public interface Change<E extends Entity<E>> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/EntityStore.java import pl.marekpazik.state_synchronisation.Change; import pl.marekpazik.state_synchronisation.common.Id; package pl.marekpazik.state_synchronisation.entity; /** * Store that returns entity with the latest state for the given {@link Id} * All changes have to be saved to this store. */ public interface EntityStore { /** * Store assumes that for each id object there is corresponding entity. * @throws RuntimeException if there is no entity for the given id. */ <E extends Entity<E>> E getEntity(Id<E> id);
<E extends Entity<E>> void saveChange(Id<E> id, Change<E> change);
mpazik/State-synchronisation-protocol
state-synchronization-components/src/main/java/pl/marekpazik/state_synchronisation/component/store/BuildingFromChangesEntityStore.java
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/Change.java // public interface Change<E extends Entity<E>> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/ChangesStore.java // public interface ChangesStore { // // <E extends Entity<E>> Changes<E> getAllChanges(Id<E> id); // // /** // * All changes have to be saved to this store. // */ // <E extends Entity<E>> void saveChange(Id<E> id, Change<E> change); // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Changes.java // public final class Changes<E extends Entity<E>> { // private final CreationChange<E> creationChange; // private final List<UpdateChange<E>> changes; // // public Changes(List<Change<E>> changes) { // assert changes.size() > 0; // assert changes.get(0) instanceof CreationChange; // creationChange = (CreationChange<E>) changes.get(0); // this.changes = changes.stream().skip(1).map(change -> (UpdateChange<E>) change).collect(Collectors.toList()); // } // // public CreationChange<E> getCreationChange() { // return creationChange; // } // // public List<UpdateChange<E>> getUpdateChanges() { // return changes; // } // // public List<Change<E>> getAsList() { // return ImmutableList.<Change<E>>builder().add(creationChange).addAll(changes).build(); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // Changes<?> changes1 = (Changes<?>) o; // return Objects.equals(changes, changes1.changes); // } // // @Override // public int hashCode() { // return Objects.hash(changes); // } // // @Override // public String toString() { // return "Changes{" + // "changes=" + changes + // '}'; // } // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Entity.java // public interface Entity<E extends Entity<E>> { // // Id<E> getId(); // // /** // * @return and immutable state of the entity // */ // EntityState<E> getState(); // // /** // * @return immutable entity properties. // */ // EntityProperties<E> getProperties(); // // /** // * @return the version of the entity sate. // */ // Version getVersion(); // // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/EntityStore.java // public interface EntityStore { // // /** // * Store assumes that for each id object there is corresponding entity. // * @throws RuntimeException if there is no entity for the given id. // */ // <E extends Entity<E>> E getEntity(Id<E> id); // // <E extends Entity<E>> void saveChange(Id<E> id, Change<E> change); // }
import pl.marekpazik.state_synchronisation.Change; import pl.marekpazik.state_synchronisation.ChangesStore; import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.Changes; import pl.marekpazik.state_synchronisation.entity.Entity; import pl.marekpazik.state_synchronisation.entity.EntityStore;
package pl.marekpazik.state_synchronisation.component.store; /** * Entity store that base on {@link Changes}. All saved changes are saved in the {@link ChangesStore}. * @see ChangesStore#saveChange(Id, Change) ChangesStore#saveChange */ public final class BuildingFromChangesEntityStore implements EntityStore { private final ChangesStore changesStore; public BuildingFromChangesEntityStore(ChangesStore changesStore) { this.changesStore = changesStore; } @Override
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/Change.java // public interface Change<E extends Entity<E>> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/ChangesStore.java // public interface ChangesStore { // // <E extends Entity<E>> Changes<E> getAllChanges(Id<E> id); // // /** // * All changes have to be saved to this store. // */ // <E extends Entity<E>> void saveChange(Id<E> id, Change<E> change); // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Changes.java // public final class Changes<E extends Entity<E>> { // private final CreationChange<E> creationChange; // private final List<UpdateChange<E>> changes; // // public Changes(List<Change<E>> changes) { // assert changes.size() > 0; // assert changes.get(0) instanceof CreationChange; // creationChange = (CreationChange<E>) changes.get(0); // this.changes = changes.stream().skip(1).map(change -> (UpdateChange<E>) change).collect(Collectors.toList()); // } // // public CreationChange<E> getCreationChange() { // return creationChange; // } // // public List<UpdateChange<E>> getUpdateChanges() { // return changes; // } // // public List<Change<E>> getAsList() { // return ImmutableList.<Change<E>>builder().add(creationChange).addAll(changes).build(); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // Changes<?> changes1 = (Changes<?>) o; // return Objects.equals(changes, changes1.changes); // } // // @Override // public int hashCode() { // return Objects.hash(changes); // } // // @Override // public String toString() { // return "Changes{" + // "changes=" + changes + // '}'; // } // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Entity.java // public interface Entity<E extends Entity<E>> { // // Id<E> getId(); // // /** // * @return and immutable state of the entity // */ // EntityState<E> getState(); // // /** // * @return immutable entity properties. // */ // EntityProperties<E> getProperties(); // // /** // * @return the version of the entity sate. // */ // Version getVersion(); // // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/EntityStore.java // public interface EntityStore { // // /** // * Store assumes that for each id object there is corresponding entity. // * @throws RuntimeException if there is no entity for the given id. // */ // <E extends Entity<E>> E getEntity(Id<E> id); // // <E extends Entity<E>> void saveChange(Id<E> id, Change<E> change); // } // Path: state-synchronization-components/src/main/java/pl/marekpazik/state_synchronisation/component/store/BuildingFromChangesEntityStore.java import pl.marekpazik.state_synchronisation.Change; import pl.marekpazik.state_synchronisation.ChangesStore; import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.Changes; import pl.marekpazik.state_synchronisation.entity.Entity; import pl.marekpazik.state_synchronisation.entity.EntityStore; package pl.marekpazik.state_synchronisation.component.store; /** * Entity store that base on {@link Changes}. All saved changes are saved in the {@link ChangesStore}. * @see ChangesStore#saveChange(Id, Change) ChangesStore#saveChange */ public final class BuildingFromChangesEntityStore implements EntityStore { private final ChangesStore changesStore; public BuildingFromChangesEntityStore(ChangesStore changesStore) { this.changesStore = changesStore; } @Override
public <E extends Entity<E>> E getEntity(Id<E> id) {
mpazik/State-synchronisation-protocol
state-synchronization-components/src/main/java/pl/marekpazik/state_synchronisation/component/store/BuildingFromChangesEntityStore.java
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/Change.java // public interface Change<E extends Entity<E>> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/ChangesStore.java // public interface ChangesStore { // // <E extends Entity<E>> Changes<E> getAllChanges(Id<E> id); // // /** // * All changes have to be saved to this store. // */ // <E extends Entity<E>> void saveChange(Id<E> id, Change<E> change); // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Changes.java // public final class Changes<E extends Entity<E>> { // private final CreationChange<E> creationChange; // private final List<UpdateChange<E>> changes; // // public Changes(List<Change<E>> changes) { // assert changes.size() > 0; // assert changes.get(0) instanceof CreationChange; // creationChange = (CreationChange<E>) changes.get(0); // this.changes = changes.stream().skip(1).map(change -> (UpdateChange<E>) change).collect(Collectors.toList()); // } // // public CreationChange<E> getCreationChange() { // return creationChange; // } // // public List<UpdateChange<E>> getUpdateChanges() { // return changes; // } // // public List<Change<E>> getAsList() { // return ImmutableList.<Change<E>>builder().add(creationChange).addAll(changes).build(); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // Changes<?> changes1 = (Changes<?>) o; // return Objects.equals(changes, changes1.changes); // } // // @Override // public int hashCode() { // return Objects.hash(changes); // } // // @Override // public String toString() { // return "Changes{" + // "changes=" + changes + // '}'; // } // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Entity.java // public interface Entity<E extends Entity<E>> { // // Id<E> getId(); // // /** // * @return and immutable state of the entity // */ // EntityState<E> getState(); // // /** // * @return immutable entity properties. // */ // EntityProperties<E> getProperties(); // // /** // * @return the version of the entity sate. // */ // Version getVersion(); // // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/EntityStore.java // public interface EntityStore { // // /** // * Store assumes that for each id object there is corresponding entity. // * @throws RuntimeException if there is no entity for the given id. // */ // <E extends Entity<E>> E getEntity(Id<E> id); // // <E extends Entity<E>> void saveChange(Id<E> id, Change<E> change); // }
import pl.marekpazik.state_synchronisation.Change; import pl.marekpazik.state_synchronisation.ChangesStore; import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.Changes; import pl.marekpazik.state_synchronisation.entity.Entity; import pl.marekpazik.state_synchronisation.entity.EntityStore;
package pl.marekpazik.state_synchronisation.component.store; /** * Entity store that base on {@link Changes}. All saved changes are saved in the {@link ChangesStore}. * @see ChangesStore#saveChange(Id, Change) ChangesStore#saveChange */ public final class BuildingFromChangesEntityStore implements EntityStore { private final ChangesStore changesStore; public BuildingFromChangesEntityStore(ChangesStore changesStore) { this.changesStore = changesStore; } @Override
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/Change.java // public interface Change<E extends Entity<E>> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/ChangesStore.java // public interface ChangesStore { // // <E extends Entity<E>> Changes<E> getAllChanges(Id<E> id); // // /** // * All changes have to be saved to this store. // */ // <E extends Entity<E>> void saveChange(Id<E> id, Change<E> change); // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Changes.java // public final class Changes<E extends Entity<E>> { // private final CreationChange<E> creationChange; // private final List<UpdateChange<E>> changes; // // public Changes(List<Change<E>> changes) { // assert changes.size() > 0; // assert changes.get(0) instanceof CreationChange; // creationChange = (CreationChange<E>) changes.get(0); // this.changes = changes.stream().skip(1).map(change -> (UpdateChange<E>) change).collect(Collectors.toList()); // } // // public CreationChange<E> getCreationChange() { // return creationChange; // } // // public List<UpdateChange<E>> getUpdateChanges() { // return changes; // } // // public List<Change<E>> getAsList() { // return ImmutableList.<Change<E>>builder().add(creationChange).addAll(changes).build(); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // Changes<?> changes1 = (Changes<?>) o; // return Objects.equals(changes, changes1.changes); // } // // @Override // public int hashCode() { // return Objects.hash(changes); // } // // @Override // public String toString() { // return "Changes{" + // "changes=" + changes + // '}'; // } // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Entity.java // public interface Entity<E extends Entity<E>> { // // Id<E> getId(); // // /** // * @return and immutable state of the entity // */ // EntityState<E> getState(); // // /** // * @return immutable entity properties. // */ // EntityProperties<E> getProperties(); // // /** // * @return the version of the entity sate. // */ // Version getVersion(); // // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/EntityStore.java // public interface EntityStore { // // /** // * Store assumes that for each id object there is corresponding entity. // * @throws RuntimeException if there is no entity for the given id. // */ // <E extends Entity<E>> E getEntity(Id<E> id); // // <E extends Entity<E>> void saveChange(Id<E> id, Change<E> change); // } // Path: state-synchronization-components/src/main/java/pl/marekpazik/state_synchronisation/component/store/BuildingFromChangesEntityStore.java import pl.marekpazik.state_synchronisation.Change; import pl.marekpazik.state_synchronisation.ChangesStore; import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.Changes; import pl.marekpazik.state_synchronisation.entity.Entity; import pl.marekpazik.state_synchronisation.entity.EntityStore; package pl.marekpazik.state_synchronisation.component.store; /** * Entity store that base on {@link Changes}. All saved changes are saved in the {@link ChangesStore}. * @see ChangesStore#saveChange(Id, Change) ChangesStore#saveChange */ public final class BuildingFromChangesEntityStore implements EntityStore { private final ChangesStore changesStore; public BuildingFromChangesEntityStore(ChangesStore changesStore) { this.changesStore = changesStore; } @Override
public <E extends Entity<E>> E getEntity(Id<E> id) {
mpazik/State-synchronisation-protocol
state-synchronization-components/src/main/java/pl/marekpazik/state_synchronisation/component/store/BuildingFromChangesEntityStore.java
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/Change.java // public interface Change<E extends Entity<E>> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/ChangesStore.java // public interface ChangesStore { // // <E extends Entity<E>> Changes<E> getAllChanges(Id<E> id); // // /** // * All changes have to be saved to this store. // */ // <E extends Entity<E>> void saveChange(Id<E> id, Change<E> change); // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Changes.java // public final class Changes<E extends Entity<E>> { // private final CreationChange<E> creationChange; // private final List<UpdateChange<E>> changes; // // public Changes(List<Change<E>> changes) { // assert changes.size() > 0; // assert changes.get(0) instanceof CreationChange; // creationChange = (CreationChange<E>) changes.get(0); // this.changes = changes.stream().skip(1).map(change -> (UpdateChange<E>) change).collect(Collectors.toList()); // } // // public CreationChange<E> getCreationChange() { // return creationChange; // } // // public List<UpdateChange<E>> getUpdateChanges() { // return changes; // } // // public List<Change<E>> getAsList() { // return ImmutableList.<Change<E>>builder().add(creationChange).addAll(changes).build(); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // Changes<?> changes1 = (Changes<?>) o; // return Objects.equals(changes, changes1.changes); // } // // @Override // public int hashCode() { // return Objects.hash(changes); // } // // @Override // public String toString() { // return "Changes{" + // "changes=" + changes + // '}'; // } // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Entity.java // public interface Entity<E extends Entity<E>> { // // Id<E> getId(); // // /** // * @return and immutable state of the entity // */ // EntityState<E> getState(); // // /** // * @return immutable entity properties. // */ // EntityProperties<E> getProperties(); // // /** // * @return the version of the entity sate. // */ // Version getVersion(); // // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/EntityStore.java // public interface EntityStore { // // /** // * Store assumes that for each id object there is corresponding entity. // * @throws RuntimeException if there is no entity for the given id. // */ // <E extends Entity<E>> E getEntity(Id<E> id); // // <E extends Entity<E>> void saveChange(Id<E> id, Change<E> change); // }
import pl.marekpazik.state_synchronisation.Change; import pl.marekpazik.state_synchronisation.ChangesStore; import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.Changes; import pl.marekpazik.state_synchronisation.entity.Entity; import pl.marekpazik.state_synchronisation.entity.EntityStore;
package pl.marekpazik.state_synchronisation.component.store; /** * Entity store that base on {@link Changes}. All saved changes are saved in the {@link ChangesStore}. * @see ChangesStore#saveChange(Id, Change) ChangesStore#saveChange */ public final class BuildingFromChangesEntityStore implements EntityStore { private final ChangesStore changesStore; public BuildingFromChangesEntityStore(ChangesStore changesStore) { this.changesStore = changesStore; } @Override public <E extends Entity<E>> E getEntity(Id<E> id) {
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/Change.java // public interface Change<E extends Entity<E>> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/ChangesStore.java // public interface ChangesStore { // // <E extends Entity<E>> Changes<E> getAllChanges(Id<E> id); // // /** // * All changes have to be saved to this store. // */ // <E extends Entity<E>> void saveChange(Id<E> id, Change<E> change); // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Changes.java // public final class Changes<E extends Entity<E>> { // private final CreationChange<E> creationChange; // private final List<UpdateChange<E>> changes; // // public Changes(List<Change<E>> changes) { // assert changes.size() > 0; // assert changes.get(0) instanceof CreationChange; // creationChange = (CreationChange<E>) changes.get(0); // this.changes = changes.stream().skip(1).map(change -> (UpdateChange<E>) change).collect(Collectors.toList()); // } // // public CreationChange<E> getCreationChange() { // return creationChange; // } // // public List<UpdateChange<E>> getUpdateChanges() { // return changes; // } // // public List<Change<E>> getAsList() { // return ImmutableList.<Change<E>>builder().add(creationChange).addAll(changes).build(); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // Changes<?> changes1 = (Changes<?>) o; // return Objects.equals(changes, changes1.changes); // } // // @Override // public int hashCode() { // return Objects.hash(changes); // } // // @Override // public String toString() { // return "Changes{" + // "changes=" + changes + // '}'; // } // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Entity.java // public interface Entity<E extends Entity<E>> { // // Id<E> getId(); // // /** // * @return and immutable state of the entity // */ // EntityState<E> getState(); // // /** // * @return immutable entity properties. // */ // EntityProperties<E> getProperties(); // // /** // * @return the version of the entity sate. // */ // Version getVersion(); // // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/EntityStore.java // public interface EntityStore { // // /** // * Store assumes that for each id object there is corresponding entity. // * @throws RuntimeException if there is no entity for the given id. // */ // <E extends Entity<E>> E getEntity(Id<E> id); // // <E extends Entity<E>> void saveChange(Id<E> id, Change<E> change); // } // Path: state-synchronization-components/src/main/java/pl/marekpazik/state_synchronisation/component/store/BuildingFromChangesEntityStore.java import pl.marekpazik.state_synchronisation.Change; import pl.marekpazik.state_synchronisation.ChangesStore; import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.Changes; import pl.marekpazik.state_synchronisation.entity.Entity; import pl.marekpazik.state_synchronisation.entity.EntityStore; package pl.marekpazik.state_synchronisation.component.store; /** * Entity store that base on {@link Changes}. All saved changes are saved in the {@link ChangesStore}. * @see ChangesStore#saveChange(Id, Change) ChangesStore#saveChange */ public final class BuildingFromChangesEntityStore implements EntityStore { private final ChangesStore changesStore; public BuildingFromChangesEntityStore(ChangesStore changesStore) { this.changesStore = changesStore; } @Override public <E extends Entity<E>> E getEntity(Id<E> id) {
Changes<E> changes = changesStore.getAllChanges(id);
mpazik/State-synchronisation-protocol
state-synchronization-components/src/main/java/pl/marekpazik/state_synchronisation/component/store/BuildingFromChangesEntityStore.java
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/Change.java // public interface Change<E extends Entity<E>> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/ChangesStore.java // public interface ChangesStore { // // <E extends Entity<E>> Changes<E> getAllChanges(Id<E> id); // // /** // * All changes have to be saved to this store. // */ // <E extends Entity<E>> void saveChange(Id<E> id, Change<E> change); // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Changes.java // public final class Changes<E extends Entity<E>> { // private final CreationChange<E> creationChange; // private final List<UpdateChange<E>> changes; // // public Changes(List<Change<E>> changes) { // assert changes.size() > 0; // assert changes.get(0) instanceof CreationChange; // creationChange = (CreationChange<E>) changes.get(0); // this.changes = changes.stream().skip(1).map(change -> (UpdateChange<E>) change).collect(Collectors.toList()); // } // // public CreationChange<E> getCreationChange() { // return creationChange; // } // // public List<UpdateChange<E>> getUpdateChanges() { // return changes; // } // // public List<Change<E>> getAsList() { // return ImmutableList.<Change<E>>builder().add(creationChange).addAll(changes).build(); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // Changes<?> changes1 = (Changes<?>) o; // return Objects.equals(changes, changes1.changes); // } // // @Override // public int hashCode() { // return Objects.hash(changes); // } // // @Override // public String toString() { // return "Changes{" + // "changes=" + changes + // '}'; // } // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Entity.java // public interface Entity<E extends Entity<E>> { // // Id<E> getId(); // // /** // * @return and immutable state of the entity // */ // EntityState<E> getState(); // // /** // * @return immutable entity properties. // */ // EntityProperties<E> getProperties(); // // /** // * @return the version of the entity sate. // */ // Version getVersion(); // // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/EntityStore.java // public interface EntityStore { // // /** // * Store assumes that for each id object there is corresponding entity. // * @throws RuntimeException if there is no entity for the given id. // */ // <E extends Entity<E>> E getEntity(Id<E> id); // // <E extends Entity<E>> void saveChange(Id<E> id, Change<E> change); // }
import pl.marekpazik.state_synchronisation.Change; import pl.marekpazik.state_synchronisation.ChangesStore; import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.Changes; import pl.marekpazik.state_synchronisation.entity.Entity; import pl.marekpazik.state_synchronisation.entity.EntityStore;
package pl.marekpazik.state_synchronisation.component.store; /** * Entity store that base on {@link Changes}. All saved changes are saved in the {@link ChangesStore}. * @see ChangesStore#saveChange(Id, Change) ChangesStore#saveChange */ public final class BuildingFromChangesEntityStore implements EntityStore { private final ChangesStore changesStore; public BuildingFromChangesEntityStore(ChangesStore changesStore) { this.changesStore = changesStore; } @Override public <E extends Entity<E>> E getEntity(Id<E> id) { Changes<E> changes = changesStore.getAllChanges(id); E entity = changes.getCreationChange().createEntity(id); changes.getUpdateChanges().forEach(change -> change.updateEntityState(entity)); return entity; } @Override
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/Change.java // public interface Change<E extends Entity<E>> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/ChangesStore.java // public interface ChangesStore { // // <E extends Entity<E>> Changes<E> getAllChanges(Id<E> id); // // /** // * All changes have to be saved to this store. // */ // <E extends Entity<E>> void saveChange(Id<E> id, Change<E> change); // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Changes.java // public final class Changes<E extends Entity<E>> { // private final CreationChange<E> creationChange; // private final List<UpdateChange<E>> changes; // // public Changes(List<Change<E>> changes) { // assert changes.size() > 0; // assert changes.get(0) instanceof CreationChange; // creationChange = (CreationChange<E>) changes.get(0); // this.changes = changes.stream().skip(1).map(change -> (UpdateChange<E>) change).collect(Collectors.toList()); // } // // public CreationChange<E> getCreationChange() { // return creationChange; // } // // public List<UpdateChange<E>> getUpdateChanges() { // return changes; // } // // public List<Change<E>> getAsList() { // return ImmutableList.<Change<E>>builder().add(creationChange).addAll(changes).build(); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // Changes<?> changes1 = (Changes<?>) o; // return Objects.equals(changes, changes1.changes); // } // // @Override // public int hashCode() { // return Objects.hash(changes); // } // // @Override // public String toString() { // return "Changes{" + // "changes=" + changes + // '}'; // } // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Entity.java // public interface Entity<E extends Entity<E>> { // // Id<E> getId(); // // /** // * @return and immutable state of the entity // */ // EntityState<E> getState(); // // /** // * @return immutable entity properties. // */ // EntityProperties<E> getProperties(); // // /** // * @return the version of the entity sate. // */ // Version getVersion(); // // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/EntityStore.java // public interface EntityStore { // // /** // * Store assumes that for each id object there is corresponding entity. // * @throws RuntimeException if there is no entity for the given id. // */ // <E extends Entity<E>> E getEntity(Id<E> id); // // <E extends Entity<E>> void saveChange(Id<E> id, Change<E> change); // } // Path: state-synchronization-components/src/main/java/pl/marekpazik/state_synchronisation/component/store/BuildingFromChangesEntityStore.java import pl.marekpazik.state_synchronisation.Change; import pl.marekpazik.state_synchronisation.ChangesStore; import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.Changes; import pl.marekpazik.state_synchronisation.entity.Entity; import pl.marekpazik.state_synchronisation.entity.EntityStore; package pl.marekpazik.state_synchronisation.component.store; /** * Entity store that base on {@link Changes}. All saved changes are saved in the {@link ChangesStore}. * @see ChangesStore#saveChange(Id, Change) ChangesStore#saveChange */ public final class BuildingFromChangesEntityStore implements EntityStore { private final ChangesStore changesStore; public BuildingFromChangesEntityStore(ChangesStore changesStore) { this.changesStore = changesStore; } @Override public <E extends Entity<E>> E getEntity(Id<E> id) { Changes<E> changes = changesStore.getAllChanges(id); E entity = changes.getCreationChange().createEntity(id); changes.getUpdateChanges().forEach(change -> change.updateEntityState(entity)); return entity; } @Override
public <E extends Entity<E>> void saveChange(Id<E> id, Change<E> change) {
mpazik/State-synchronisation-protocol
state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/world/World.java
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/AbstractEntity.java // public abstract class AbstractEntity< // E extends Entity<E>, // P extends EntityProperties<E>, // S extends EntityState<E> // > implements Entity<E> { // private final Id<E> id; // private final P properties; // private Version version; // private S state; // // public AbstractEntity(Id<E> id, P properties, S state) { // this.id = id; // this.version = Version.first(); // this.properties = properties; // this.state = state; // } // // @Override // public Id<E> getId() { // return id; // } // // @Override // public S getState() { // return state; // } // // public void updateState(S newState) { // state = newState; // version = version.next(); // } // // @Override // public Version getVersion() { // return version; // } // // @Override // public P getProperties() { // return properties; // } // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/EntityProperties.java // public interface EntityProperties<E extends Entity<E>> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/EntityState.java // public interface EntityState<E extends Entity<E>> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/EntityType.java // public interface EntityType<E extends Entity<E>> { // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/StringEntityType.java // public class StringEntityType<E extends Entity<E>> implements EntityType<E> { // private final String type; // // public StringEntityType(String type) { // this.type = type; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // StringEntityType<?> that = (StringEntityType<?>) o; // return Objects.equals(type, that.type); // } // // @Override // public int hashCode() { // return Objects.hash(type); // } // }
import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.AbstractEntity; import pl.marekpazik.state_synchronisation.entity.EntityProperties; import pl.marekpazik.state_synchronisation.entity.EntityState; import pl.marekpazik.state_synchronisation.entity.EntityType; import pl.marekpazik.state_synchronisation.reference_implementation.StringEntityType; import java.util.Set;
package pl.marekpazik.state_synchronisation.reference_implementation.world; public class World extends AbstractEntity<World, World.Properties, World.State> { public static EntityType<World> entityType = new StringEntityType<>("world");
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/AbstractEntity.java // public abstract class AbstractEntity< // E extends Entity<E>, // P extends EntityProperties<E>, // S extends EntityState<E> // > implements Entity<E> { // private final Id<E> id; // private final P properties; // private Version version; // private S state; // // public AbstractEntity(Id<E> id, P properties, S state) { // this.id = id; // this.version = Version.first(); // this.properties = properties; // this.state = state; // } // // @Override // public Id<E> getId() { // return id; // } // // @Override // public S getState() { // return state; // } // // public void updateState(S newState) { // state = newState; // version = version.next(); // } // // @Override // public Version getVersion() { // return version; // } // // @Override // public P getProperties() { // return properties; // } // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/EntityProperties.java // public interface EntityProperties<E extends Entity<E>> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/EntityState.java // public interface EntityState<E extends Entity<E>> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/EntityType.java // public interface EntityType<E extends Entity<E>> { // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/StringEntityType.java // public class StringEntityType<E extends Entity<E>> implements EntityType<E> { // private final String type; // // public StringEntityType(String type) { // this.type = type; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // StringEntityType<?> that = (StringEntityType<?>) o; // return Objects.equals(type, that.type); // } // // @Override // public int hashCode() { // return Objects.hash(type); // } // } // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/world/World.java import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.AbstractEntity; import pl.marekpazik.state_synchronisation.entity.EntityProperties; import pl.marekpazik.state_synchronisation.entity.EntityState; import pl.marekpazik.state_synchronisation.entity.EntityType; import pl.marekpazik.state_synchronisation.reference_implementation.StringEntityType; import java.util.Set; package pl.marekpazik.state_synchronisation.reference_implementation.world; public class World extends AbstractEntity<World, World.Properties, World.State> { public static EntityType<World> entityType = new StringEntityType<>("world");
public World(Id<World> id, Properties properties, State state) {
mpazik/State-synchronisation-protocol
state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/world/World.java
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/AbstractEntity.java // public abstract class AbstractEntity< // E extends Entity<E>, // P extends EntityProperties<E>, // S extends EntityState<E> // > implements Entity<E> { // private final Id<E> id; // private final P properties; // private Version version; // private S state; // // public AbstractEntity(Id<E> id, P properties, S state) { // this.id = id; // this.version = Version.first(); // this.properties = properties; // this.state = state; // } // // @Override // public Id<E> getId() { // return id; // } // // @Override // public S getState() { // return state; // } // // public void updateState(S newState) { // state = newState; // version = version.next(); // } // // @Override // public Version getVersion() { // return version; // } // // @Override // public P getProperties() { // return properties; // } // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/EntityProperties.java // public interface EntityProperties<E extends Entity<E>> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/EntityState.java // public interface EntityState<E extends Entity<E>> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/EntityType.java // public interface EntityType<E extends Entity<E>> { // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/StringEntityType.java // public class StringEntityType<E extends Entity<E>> implements EntityType<E> { // private final String type; // // public StringEntityType(String type) { // this.type = type; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // StringEntityType<?> that = (StringEntityType<?>) o; // return Objects.equals(type, that.type); // } // // @Override // public int hashCode() { // return Objects.hash(type); // } // }
import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.AbstractEntity; import pl.marekpazik.state_synchronisation.entity.EntityProperties; import pl.marekpazik.state_synchronisation.entity.EntityState; import pl.marekpazik.state_synchronisation.entity.EntityType; import pl.marekpazik.state_synchronisation.reference_implementation.StringEntityType; import java.util.Set;
package pl.marekpazik.state_synchronisation.reference_implementation.world; public class World extends AbstractEntity<World, World.Properties, World.State> { public static EntityType<World> entityType = new StringEntityType<>("world"); public World(Id<World> id, Properties properties, State state) { super(id, properties, state); }
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/AbstractEntity.java // public abstract class AbstractEntity< // E extends Entity<E>, // P extends EntityProperties<E>, // S extends EntityState<E> // > implements Entity<E> { // private final Id<E> id; // private final P properties; // private Version version; // private S state; // // public AbstractEntity(Id<E> id, P properties, S state) { // this.id = id; // this.version = Version.first(); // this.properties = properties; // this.state = state; // } // // @Override // public Id<E> getId() { // return id; // } // // @Override // public S getState() { // return state; // } // // public void updateState(S newState) { // state = newState; // version = version.next(); // } // // @Override // public Version getVersion() { // return version; // } // // @Override // public P getProperties() { // return properties; // } // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/EntityProperties.java // public interface EntityProperties<E extends Entity<E>> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/EntityState.java // public interface EntityState<E extends Entity<E>> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/EntityType.java // public interface EntityType<E extends Entity<E>> { // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/StringEntityType.java // public class StringEntityType<E extends Entity<E>> implements EntityType<E> { // private final String type; // // public StringEntityType(String type) { // this.type = type; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // StringEntityType<?> that = (StringEntityType<?>) o; // return Objects.equals(type, that.type); // } // // @Override // public int hashCode() { // return Objects.hash(type); // } // } // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/world/World.java import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.AbstractEntity; import pl.marekpazik.state_synchronisation.entity.EntityProperties; import pl.marekpazik.state_synchronisation.entity.EntityState; import pl.marekpazik.state_synchronisation.entity.EntityType; import pl.marekpazik.state_synchronisation.reference_implementation.StringEntityType; import java.util.Set; package pl.marekpazik.state_synchronisation.reference_implementation.world; public class World extends AbstractEntity<World, World.Properties, World.State> { public static EntityType<World> entityType = new StringEntityType<>("world"); public World(Id<World> id, Properties properties, State state) { super(id, properties, state); }
public static class Properties implements EntityProperties<World> {
mpazik/State-synchronisation-protocol
state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/world/World.java
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/AbstractEntity.java // public abstract class AbstractEntity< // E extends Entity<E>, // P extends EntityProperties<E>, // S extends EntityState<E> // > implements Entity<E> { // private final Id<E> id; // private final P properties; // private Version version; // private S state; // // public AbstractEntity(Id<E> id, P properties, S state) { // this.id = id; // this.version = Version.first(); // this.properties = properties; // this.state = state; // } // // @Override // public Id<E> getId() { // return id; // } // // @Override // public S getState() { // return state; // } // // public void updateState(S newState) { // state = newState; // version = version.next(); // } // // @Override // public Version getVersion() { // return version; // } // // @Override // public P getProperties() { // return properties; // } // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/EntityProperties.java // public interface EntityProperties<E extends Entity<E>> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/EntityState.java // public interface EntityState<E extends Entity<E>> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/EntityType.java // public interface EntityType<E extends Entity<E>> { // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/StringEntityType.java // public class StringEntityType<E extends Entity<E>> implements EntityType<E> { // private final String type; // // public StringEntityType(String type) { // this.type = type; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // StringEntityType<?> that = (StringEntityType<?>) o; // return Objects.equals(type, that.type); // } // // @Override // public int hashCode() { // return Objects.hash(type); // } // }
import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.AbstractEntity; import pl.marekpazik.state_synchronisation.entity.EntityProperties; import pl.marekpazik.state_synchronisation.entity.EntityState; import pl.marekpazik.state_synchronisation.entity.EntityType; import pl.marekpazik.state_synchronisation.reference_implementation.StringEntityType; import java.util.Set;
package pl.marekpazik.state_synchronisation.reference_implementation.world; public class World extends AbstractEntity<World, World.Properties, World.State> { public static EntityType<World> entityType = new StringEntityType<>("world"); public World(Id<World> id, Properties properties, State state) { super(id, properties, state); } public static class Properties implements EntityProperties<World> { public final int weight; public final int height; public Properties(int weight, int height) { this.weight = weight; this.height = height; } }
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/AbstractEntity.java // public abstract class AbstractEntity< // E extends Entity<E>, // P extends EntityProperties<E>, // S extends EntityState<E> // > implements Entity<E> { // private final Id<E> id; // private final P properties; // private Version version; // private S state; // // public AbstractEntity(Id<E> id, P properties, S state) { // this.id = id; // this.version = Version.first(); // this.properties = properties; // this.state = state; // } // // @Override // public Id<E> getId() { // return id; // } // // @Override // public S getState() { // return state; // } // // public void updateState(S newState) { // state = newState; // version = version.next(); // } // // @Override // public Version getVersion() { // return version; // } // // @Override // public P getProperties() { // return properties; // } // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/EntityProperties.java // public interface EntityProperties<E extends Entity<E>> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/EntityState.java // public interface EntityState<E extends Entity<E>> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/EntityType.java // public interface EntityType<E extends Entity<E>> { // } // // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/StringEntityType.java // public class StringEntityType<E extends Entity<E>> implements EntityType<E> { // private final String type; // // public StringEntityType(String type) { // this.type = type; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // StringEntityType<?> that = (StringEntityType<?>) o; // return Objects.equals(type, that.type); // } // // @Override // public int hashCode() { // return Objects.hash(type); // } // } // Path: state-synchronization-reference-implementation/src/main/java/pl/marekpazik/state_synchronisation/reference_implementation/world/World.java import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.AbstractEntity; import pl.marekpazik.state_synchronisation.entity.EntityProperties; import pl.marekpazik.state_synchronisation.entity.EntityState; import pl.marekpazik.state_synchronisation.entity.EntityType; import pl.marekpazik.state_synchronisation.reference_implementation.StringEntityType; import java.util.Set; package pl.marekpazik.state_synchronisation.reference_implementation.world; public class World extends AbstractEntity<World, World.Properties, World.State> { public static EntityType<World> entityType = new StringEntityType<>("world"); public World(Id<World> id, Properties properties, State state) { super(id, properties, state); } public static class Properties implements EntityProperties<World> { public final int weight; public final int height; public Properties(int weight, int height) { this.weight = weight; this.height = height; } }
public static class State implements EntityState<World> {
mpazik/State-synchronisation-protocol
state-synchronization-api/src/test/java/pl/marekpazik/state_synchronisation/ChangesStoreTest.java
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Changes.java // public final class Changes<E extends Entity<E>> { // private final CreationChange<E> creationChange; // private final List<UpdateChange<E>> changes; // // public Changes(List<Change<E>> changes) { // assert changes.size() > 0; // assert changes.get(0) instanceof CreationChange; // creationChange = (CreationChange<E>) changes.get(0); // this.changes = changes.stream().skip(1).map(change -> (UpdateChange<E>) change).collect(Collectors.toList()); // } // // public CreationChange<E> getCreationChange() { // return creationChange; // } // // public List<UpdateChange<E>> getUpdateChanges() { // return changes; // } // // public List<Change<E>> getAsList() { // return ImmutableList.<Change<E>>builder().add(creationChange).addAll(changes).build(); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // Changes<?> changes1 = (Changes<?>) o; // return Objects.equals(changes, changes1.changes); // } // // @Override // public int hashCode() { // return Objects.hash(changes); // } // // @Override // public String toString() { // return "Changes{" + // "changes=" + changes + // '}'; // } // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/CreationChange.java // public interface CreationChange<E extends Entity<E>> extends Change<E> { // E createEntity(Id<E> entityId); // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Entity.java // public interface Entity<E extends Entity<E>> { // // Id<E> getId(); // // /** // * @return and immutable state of the entity // */ // EntityState<E> getState(); // // /** // * @return immutable entity properties. // */ // EntityProperties<E> getProperties(); // // /** // * @return the version of the entity sate. // */ // Version getVersion(); // // }
import com.google.common.collect.ImmutableList; import org.junit.Before; import org.junit.Test; import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.Changes; import pl.marekpazik.state_synchronisation.entity.CreationChange; import pl.marekpazik.state_synchronisation.entity.Entity; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.ThrowableAssert.catchThrowable;
package pl.marekpazik.state_synchronisation; public abstract class ChangesStoreTest<E extends Entity<E>> { ChangesStore changesStore; @Before public void setUp() throws Exception { changesStore = createSut(); } @Test public void getAllChanges_returnsAllChangesInOrder() {
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Changes.java // public final class Changes<E extends Entity<E>> { // private final CreationChange<E> creationChange; // private final List<UpdateChange<E>> changes; // // public Changes(List<Change<E>> changes) { // assert changes.size() > 0; // assert changes.get(0) instanceof CreationChange; // creationChange = (CreationChange<E>) changes.get(0); // this.changes = changes.stream().skip(1).map(change -> (UpdateChange<E>) change).collect(Collectors.toList()); // } // // public CreationChange<E> getCreationChange() { // return creationChange; // } // // public List<UpdateChange<E>> getUpdateChanges() { // return changes; // } // // public List<Change<E>> getAsList() { // return ImmutableList.<Change<E>>builder().add(creationChange).addAll(changes).build(); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // Changes<?> changes1 = (Changes<?>) o; // return Objects.equals(changes, changes1.changes); // } // // @Override // public int hashCode() { // return Objects.hash(changes); // } // // @Override // public String toString() { // return "Changes{" + // "changes=" + changes + // '}'; // } // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/CreationChange.java // public interface CreationChange<E extends Entity<E>> extends Change<E> { // E createEntity(Id<E> entityId); // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Entity.java // public interface Entity<E extends Entity<E>> { // // Id<E> getId(); // // /** // * @return and immutable state of the entity // */ // EntityState<E> getState(); // // /** // * @return immutable entity properties. // */ // EntityProperties<E> getProperties(); // // /** // * @return the version of the entity sate. // */ // Version getVersion(); // // } // Path: state-synchronization-api/src/test/java/pl/marekpazik/state_synchronisation/ChangesStoreTest.java import com.google.common.collect.ImmutableList; import org.junit.Before; import org.junit.Test; import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.Changes; import pl.marekpazik.state_synchronisation.entity.CreationChange; import pl.marekpazik.state_synchronisation.entity.Entity; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.ThrowableAssert.catchThrowable; package pl.marekpazik.state_synchronisation; public abstract class ChangesStoreTest<E extends Entity<E>> { ChangesStore changesStore; @Before public void setUp() throws Exception { changesStore = createSut(); } @Test public void getAllChanges_returnsAllChangesInOrder() {
Id<E> id = generateId();
mpazik/State-synchronisation-protocol
state-synchronization-api/src/test/java/pl/marekpazik/state_synchronisation/ChangesStoreTest.java
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Changes.java // public final class Changes<E extends Entity<E>> { // private final CreationChange<E> creationChange; // private final List<UpdateChange<E>> changes; // // public Changes(List<Change<E>> changes) { // assert changes.size() > 0; // assert changes.get(0) instanceof CreationChange; // creationChange = (CreationChange<E>) changes.get(0); // this.changes = changes.stream().skip(1).map(change -> (UpdateChange<E>) change).collect(Collectors.toList()); // } // // public CreationChange<E> getCreationChange() { // return creationChange; // } // // public List<UpdateChange<E>> getUpdateChanges() { // return changes; // } // // public List<Change<E>> getAsList() { // return ImmutableList.<Change<E>>builder().add(creationChange).addAll(changes).build(); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // Changes<?> changes1 = (Changes<?>) o; // return Objects.equals(changes, changes1.changes); // } // // @Override // public int hashCode() { // return Objects.hash(changes); // } // // @Override // public String toString() { // return "Changes{" + // "changes=" + changes + // '}'; // } // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/CreationChange.java // public interface CreationChange<E extends Entity<E>> extends Change<E> { // E createEntity(Id<E> entityId); // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Entity.java // public interface Entity<E extends Entity<E>> { // // Id<E> getId(); // // /** // * @return and immutable state of the entity // */ // EntityState<E> getState(); // // /** // * @return immutable entity properties. // */ // EntityProperties<E> getProperties(); // // /** // * @return the version of the entity sate. // */ // Version getVersion(); // // }
import com.google.common.collect.ImmutableList; import org.junit.Before; import org.junit.Test; import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.Changes; import pl.marekpazik.state_synchronisation.entity.CreationChange; import pl.marekpazik.state_synchronisation.entity.Entity; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.ThrowableAssert.catchThrowable;
package pl.marekpazik.state_synchronisation; public abstract class ChangesStoreTest<E extends Entity<E>> { ChangesStore changesStore; @Before public void setUp() throws Exception { changesStore = createSut(); } @Test public void getAllChanges_returnsAllChangesInOrder() { Id<E> id = generateId();
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Changes.java // public final class Changes<E extends Entity<E>> { // private final CreationChange<E> creationChange; // private final List<UpdateChange<E>> changes; // // public Changes(List<Change<E>> changes) { // assert changes.size() > 0; // assert changes.get(0) instanceof CreationChange; // creationChange = (CreationChange<E>) changes.get(0); // this.changes = changes.stream().skip(1).map(change -> (UpdateChange<E>) change).collect(Collectors.toList()); // } // // public CreationChange<E> getCreationChange() { // return creationChange; // } // // public List<UpdateChange<E>> getUpdateChanges() { // return changes; // } // // public List<Change<E>> getAsList() { // return ImmutableList.<Change<E>>builder().add(creationChange).addAll(changes).build(); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // Changes<?> changes1 = (Changes<?>) o; // return Objects.equals(changes, changes1.changes); // } // // @Override // public int hashCode() { // return Objects.hash(changes); // } // // @Override // public String toString() { // return "Changes{" + // "changes=" + changes + // '}'; // } // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/CreationChange.java // public interface CreationChange<E extends Entity<E>> extends Change<E> { // E createEntity(Id<E> entityId); // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Entity.java // public interface Entity<E extends Entity<E>> { // // Id<E> getId(); // // /** // * @return and immutable state of the entity // */ // EntityState<E> getState(); // // /** // * @return immutable entity properties. // */ // EntityProperties<E> getProperties(); // // /** // * @return the version of the entity sate. // */ // Version getVersion(); // // } // Path: state-synchronization-api/src/test/java/pl/marekpazik/state_synchronisation/ChangesStoreTest.java import com.google.common.collect.ImmutableList; import org.junit.Before; import org.junit.Test; import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.Changes; import pl.marekpazik.state_synchronisation.entity.CreationChange; import pl.marekpazik.state_synchronisation.entity.Entity; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.ThrowableAssert.catchThrowable; package pl.marekpazik.state_synchronisation; public abstract class ChangesStoreTest<E extends Entity<E>> { ChangesStore changesStore; @Before public void setUp() throws Exception { changesStore = createSut(); } @Test public void getAllChanges_returnsAllChangesInOrder() { Id<E> id = generateId();
CreationChange<E> creationChange = getCreationChange();
mpazik/State-synchronisation-protocol
state-synchronization-api/src/test/java/pl/marekpazik/state_synchronisation/ChangesStoreTest.java
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Changes.java // public final class Changes<E extends Entity<E>> { // private final CreationChange<E> creationChange; // private final List<UpdateChange<E>> changes; // // public Changes(List<Change<E>> changes) { // assert changes.size() > 0; // assert changes.get(0) instanceof CreationChange; // creationChange = (CreationChange<E>) changes.get(0); // this.changes = changes.stream().skip(1).map(change -> (UpdateChange<E>) change).collect(Collectors.toList()); // } // // public CreationChange<E> getCreationChange() { // return creationChange; // } // // public List<UpdateChange<E>> getUpdateChanges() { // return changes; // } // // public List<Change<E>> getAsList() { // return ImmutableList.<Change<E>>builder().add(creationChange).addAll(changes).build(); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // Changes<?> changes1 = (Changes<?>) o; // return Objects.equals(changes, changes1.changes); // } // // @Override // public int hashCode() { // return Objects.hash(changes); // } // // @Override // public String toString() { // return "Changes{" + // "changes=" + changes + // '}'; // } // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/CreationChange.java // public interface CreationChange<E extends Entity<E>> extends Change<E> { // E createEntity(Id<E> entityId); // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Entity.java // public interface Entity<E extends Entity<E>> { // // Id<E> getId(); // // /** // * @return and immutable state of the entity // */ // EntityState<E> getState(); // // /** // * @return immutable entity properties. // */ // EntityProperties<E> getProperties(); // // /** // * @return the version of the entity sate. // */ // Version getVersion(); // // }
import com.google.common.collect.ImmutableList; import org.junit.Before; import org.junit.Test; import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.Changes; import pl.marekpazik.state_synchronisation.entity.CreationChange; import pl.marekpazik.state_synchronisation.entity.Entity; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.ThrowableAssert.catchThrowable;
package pl.marekpazik.state_synchronisation; public abstract class ChangesStoreTest<E extends Entity<E>> { ChangesStore changesStore; @Before public void setUp() throws Exception { changesStore = createSut(); } @Test public void getAllChanges_returnsAllChangesInOrder() { Id<E> id = generateId(); CreationChange<E> creationChange = getCreationChange(); Change<E> change = getChange(); changesStore.saveChange(id, creationChange); changesStore.saveChange(id, change);
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Changes.java // public final class Changes<E extends Entity<E>> { // private final CreationChange<E> creationChange; // private final List<UpdateChange<E>> changes; // // public Changes(List<Change<E>> changes) { // assert changes.size() > 0; // assert changes.get(0) instanceof CreationChange; // creationChange = (CreationChange<E>) changes.get(0); // this.changes = changes.stream().skip(1).map(change -> (UpdateChange<E>) change).collect(Collectors.toList()); // } // // public CreationChange<E> getCreationChange() { // return creationChange; // } // // public List<UpdateChange<E>> getUpdateChanges() { // return changes; // } // // public List<Change<E>> getAsList() { // return ImmutableList.<Change<E>>builder().add(creationChange).addAll(changes).build(); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // Changes<?> changes1 = (Changes<?>) o; // return Objects.equals(changes, changes1.changes); // } // // @Override // public int hashCode() { // return Objects.hash(changes); // } // // @Override // public String toString() { // return "Changes{" + // "changes=" + changes + // '}'; // } // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/CreationChange.java // public interface CreationChange<E extends Entity<E>> extends Change<E> { // E createEntity(Id<E> entityId); // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/Entity.java // public interface Entity<E extends Entity<E>> { // // Id<E> getId(); // // /** // * @return and immutable state of the entity // */ // EntityState<E> getState(); // // /** // * @return immutable entity properties. // */ // EntityProperties<E> getProperties(); // // /** // * @return the version of the entity sate. // */ // Version getVersion(); // // } // Path: state-synchronization-api/src/test/java/pl/marekpazik/state_synchronisation/ChangesStoreTest.java import com.google.common.collect.ImmutableList; import org.junit.Before; import org.junit.Test; import pl.marekpazik.state_synchronisation.common.Id; import pl.marekpazik.state_synchronisation.entity.Changes; import pl.marekpazik.state_synchronisation.entity.CreationChange; import pl.marekpazik.state_synchronisation.entity.Entity; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.ThrowableAssert.catchThrowable; package pl.marekpazik.state_synchronisation; public abstract class ChangesStoreTest<E extends Entity<E>> { ChangesStore changesStore; @Before public void setUp() throws Exception { changesStore = createSut(); } @Test public void getAllChanges_returnsAllChangesInOrder() { Id<E> id = generateId(); CreationChange<E> creationChange = getCreationChange(); Change<E> change = getChange(); changesStore.saveChange(id, creationChange); changesStore.saveChange(id, change);
Changes<E> changes = changesStore.getAllChanges(id);
mpazik/State-synchronisation-protocol
state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/AbstractEntity.java
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/Version.java // public final class Version { // private final int version; // // private Version(int version) { // this.version = version; // } // // public Version next() { // return new Version(version + 1); // } // // public static Version first() { // return new Version(1); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // Version version1 = (Version) o; // return version == version1.version; // } // // @Override // public int hashCode() { // return Objects.hash(version); // } // // @Override // public String toString() { // return "Version{" + // "version=" + version + // '}'; // } // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // }
import pl.marekpazik.state_synchronisation.Version; import pl.marekpazik.state_synchronisation.common.Id;
package pl.marekpazik.state_synchronisation.entity; public abstract class AbstractEntity< E extends Entity<E>, P extends EntityProperties<E>, S extends EntityState<E> > implements Entity<E> {
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/Version.java // public final class Version { // private final int version; // // private Version(int version) { // this.version = version; // } // // public Version next() { // return new Version(version + 1); // } // // public static Version first() { // return new Version(1); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // Version version1 = (Version) o; // return version == version1.version; // } // // @Override // public int hashCode() { // return Objects.hash(version); // } // // @Override // public String toString() { // return "Version{" + // "version=" + version + // '}'; // } // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/AbstractEntity.java import pl.marekpazik.state_synchronisation.Version; import pl.marekpazik.state_synchronisation.common.Id; package pl.marekpazik.state_synchronisation.entity; public abstract class AbstractEntity< E extends Entity<E>, P extends EntityProperties<E>, S extends EntityState<E> > implements Entity<E> {
private final Id<E> id;
mpazik/State-synchronisation-protocol
state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/AbstractEntity.java
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/Version.java // public final class Version { // private final int version; // // private Version(int version) { // this.version = version; // } // // public Version next() { // return new Version(version + 1); // } // // public static Version first() { // return new Version(1); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // Version version1 = (Version) o; // return version == version1.version; // } // // @Override // public int hashCode() { // return Objects.hash(version); // } // // @Override // public String toString() { // return "Version{" + // "version=" + version + // '}'; // } // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // }
import pl.marekpazik.state_synchronisation.Version; import pl.marekpazik.state_synchronisation.common.Id;
package pl.marekpazik.state_synchronisation.entity; public abstract class AbstractEntity< E extends Entity<E>, P extends EntityProperties<E>, S extends EntityState<E> > implements Entity<E> { private final Id<E> id; private final P properties;
// Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/Version.java // public final class Version { // private final int version; // // private Version(int version) { // this.version = version; // } // // public Version next() { // return new Version(version + 1); // } // // public static Version first() { // return new Version(1); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // Version version1 = (Version) o; // return version == version1.version; // } // // @Override // public int hashCode() { // return Objects.hash(version); // } // // @Override // public String toString() { // return "Version{" + // "version=" + version + // '}'; // } // } // // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/common/Id.java // public interface Id<T> { // } // Path: state-synchronization-api/src/main/java/pl/marekpazik/state_synchronisation/entity/AbstractEntity.java import pl.marekpazik.state_synchronisation.Version; import pl.marekpazik.state_synchronisation.common.Id; package pl.marekpazik.state_synchronisation.entity; public abstract class AbstractEntity< E extends Entity<E>, P extends EntityProperties<E>, S extends EntityState<E> > implements Entity<E> { private final Id<E> id; private final P properties;
private Version version;
IncQueryLabs/smarthome-cep-demonstrator
runtime/com.incquerylabs.smarthome.eventbus.ruleengine.droolshomeio/src/main/java/com/incquerylabs/smarthome/eventbus/ruleengine/droolshomeio/DimmerCommand.java
// Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/IEventPublisher.java // public interface IEventPublisher { // public void postCommand(String itemName, Command command); // // public void postCommand(Item item, Command command); // // public void startComplexCommand(IComplexCommand complexCommand); // // public void stopComplexCommand(String itemName); // // public void stopComplexCommand(Item item); // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/IComplexCommand.java // public interface IComplexCommand { // // public void start(IEventPublisher publisher); // // public void stop(); // // public String getItemName(); // }
import java.util.Timer; import java.util.TimerTask; import org.eclipse.smarthome.core.items.Item; import org.eclipse.smarthome.core.library.types.IncreaseDecreaseType; import org.eclipse.smarthome.core.library.types.PercentType; import com.incquerylabs.smarthome.eventbus.api.IEventPublisher; import com.incquerylabs.smarthome.eventbus.api.IComplexCommand;
public static DimmerCommand create(Item item, IncreaseDecreaseType type, int value) { return new DimmerCommand(item, type, value, 50, 50); } public static DimmerCommand create(Item item, IncreaseDecreaseType type) { return new DimmerCommand(item, type, 2, 50, 50); } public DimmerCommand(Item item, IncreaseDecreaseType type, int value, long first, long period) { if (type != null && type == IncreaseDecreaseType.DECREASE) { if (value > 0) { value = value * (-1); } } this.item = item; this.value = value; this.first = first; this.period = period; this.timer = new Timer(); } @Override public String getItemName() { return item.getName(); } @Override
// Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/IEventPublisher.java // public interface IEventPublisher { // public void postCommand(String itemName, Command command); // // public void postCommand(Item item, Command command); // // public void startComplexCommand(IComplexCommand complexCommand); // // public void stopComplexCommand(String itemName); // // public void stopComplexCommand(Item item); // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/IComplexCommand.java // public interface IComplexCommand { // // public void start(IEventPublisher publisher); // // public void stop(); // // public String getItemName(); // } // Path: runtime/com.incquerylabs.smarthome.eventbus.ruleengine.droolshomeio/src/main/java/com/incquerylabs/smarthome/eventbus/ruleengine/droolshomeio/DimmerCommand.java import java.util.Timer; import java.util.TimerTask; import org.eclipse.smarthome.core.items.Item; import org.eclipse.smarthome.core.library.types.IncreaseDecreaseType; import org.eclipse.smarthome.core.library.types.PercentType; import com.incquerylabs.smarthome.eventbus.api.IEventPublisher; import com.incquerylabs.smarthome.eventbus.api.IComplexCommand; public static DimmerCommand create(Item item, IncreaseDecreaseType type, int value) { return new DimmerCommand(item, type, value, 50, 50); } public static DimmerCommand create(Item item, IncreaseDecreaseType type) { return new DimmerCommand(item, type, 2, 50, 50); } public DimmerCommand(Item item, IncreaseDecreaseType type, int value, long first, long period) { if (type != null && type == IncreaseDecreaseType.DECREASE) { if (value > 0) { value = value * (-1); } } this.item = item; this.value = value; this.first = first; this.period = period; this.timer = new Timer(); } @Override public String getItemName() { return item.getName(); } @Override
public void start(final IEventPublisher eventBus) {
IncQueryLabs/smarthome-cep-demonstrator
runtime/com.incquerylabs.smarthome.eventbus.logger/src/com/incquerylabs/iot/eventbus/logger/ExampleEventSubscriber.java
// Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/IEventSubscriber.java // public interface IEventSubscriber { // public void stateUpdated(ItemStateEvent event); // // public void stateChanged(ItemStateChangedEvent event); // // public void groupStateChanged(GroupItemStateChangedEvent event); // // public void commandReceived(ItemCommandEvent event); // // public void initItems(Collection<Item> items); // // public void itemAdded(ItemAddedEvent event); // // public void itemRemoved(ItemRemovedEvent event); // // public void itemUpdated(ItemUpdatedEvent event); // // public String getSubscriberName(); // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/GroupItemStateChangedEvent.java // public class GroupItemStateChangedEvent extends ItemStateChangedEvent { // // public GroupItemStateChangedEvent(Item item, State newState, State oldState) { // super(item, newState, oldState); // } // // @Override // public String toString() { // return String.format("%s group state changed from %s to %s", item.getName(), oldState, newState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemAddedEvent.java // public class ItemAddedEvent implements ItemEvent { // protected final Item item; // // public ItemAddedEvent(Item item) { // super(); // this.item = item; // } // // public Item getItem() { // return item; // } // // public String getName() { // return item.getName(); // } // // @Override // public String toString() { // return "Item '" + item.getName() + "' has been added."; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemCommandEvent.java // public class ItemCommandEvent extends ItemCommandBase implements ItemEvent { // // public ItemCommandEvent(Item item, Command command) { // super(item, command); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemRemovedEvent.java // public class ItemRemovedEvent implements ItemEvent { // protected final String itemName; // // public ItemRemovedEvent(String itemName) { // super(); // this.itemName = itemName; // } // // public String getName() { // return itemName; // } // // @Override // public String toString() { // return "Item '" + itemName + "' has been removed."; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemStateChangedEvent.java // public class ItemStateChangedEvent extends ItemStateChangedBase implements ItemEvent { // // public ItemStateChangedEvent(Item item, State newState, State oldState) { // super(item, newState, oldState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemStateEvent.java // public class ItemStateEvent implements ItemEvent { // protected final Item item; // protected final State itemState; // // public ItemStateEvent(Item item, State itemState) { // super(); // this.item = item; // this.itemState = itemState; // } // // public Item getItem() { // return item; // } // // public String getName() { // return this.item.getName(); // } // // public State getItemState() { // return itemState; // } // // @Override // public String toString() { // return String.format("%s updated to %s", item.getName(), itemState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemUpdatedEvent.java // public class ItemUpdatedEvent { // protected final Item newItem; // protected final String oldItemName; // // public ItemUpdatedEvent(Item newItem, String oldItemName) { // super(); // this.newItem = newItem; // this.oldItemName = oldItemName; // } // // public Item getNewItem() { // return newItem; // } // // public String getOldItemName() { // return oldItemName; // } // // @Override // public String toString() { // return "Item '" + oldItemName + "' has been updated."; // } // }
import java.util.Collection; import org.eclipse.smarthome.core.items.Item; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.incquerylabs.smarthome.eventbus.api.IEventSubscriber; import com.incquerylabs.smarthome.eventbus.api.events.GroupItemStateChangedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemAddedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemCommandEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemRemovedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemStateChangedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemStateEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemUpdatedEvent;
package com.incquerylabs.iot.eventbus.logger; public class ExampleEventSubscriber implements IEventSubscriber { static Logger logger = LoggerFactory.getLogger(ExampleEventSubscriber.class); private static final String subscriberName = "Extended event bus logger"; @Override
// Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/IEventSubscriber.java // public interface IEventSubscriber { // public void stateUpdated(ItemStateEvent event); // // public void stateChanged(ItemStateChangedEvent event); // // public void groupStateChanged(GroupItemStateChangedEvent event); // // public void commandReceived(ItemCommandEvent event); // // public void initItems(Collection<Item> items); // // public void itemAdded(ItemAddedEvent event); // // public void itemRemoved(ItemRemovedEvent event); // // public void itemUpdated(ItemUpdatedEvent event); // // public String getSubscriberName(); // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/GroupItemStateChangedEvent.java // public class GroupItemStateChangedEvent extends ItemStateChangedEvent { // // public GroupItemStateChangedEvent(Item item, State newState, State oldState) { // super(item, newState, oldState); // } // // @Override // public String toString() { // return String.format("%s group state changed from %s to %s", item.getName(), oldState, newState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemAddedEvent.java // public class ItemAddedEvent implements ItemEvent { // protected final Item item; // // public ItemAddedEvent(Item item) { // super(); // this.item = item; // } // // public Item getItem() { // return item; // } // // public String getName() { // return item.getName(); // } // // @Override // public String toString() { // return "Item '" + item.getName() + "' has been added."; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemCommandEvent.java // public class ItemCommandEvent extends ItemCommandBase implements ItemEvent { // // public ItemCommandEvent(Item item, Command command) { // super(item, command); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemRemovedEvent.java // public class ItemRemovedEvent implements ItemEvent { // protected final String itemName; // // public ItemRemovedEvent(String itemName) { // super(); // this.itemName = itemName; // } // // public String getName() { // return itemName; // } // // @Override // public String toString() { // return "Item '" + itemName + "' has been removed."; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemStateChangedEvent.java // public class ItemStateChangedEvent extends ItemStateChangedBase implements ItemEvent { // // public ItemStateChangedEvent(Item item, State newState, State oldState) { // super(item, newState, oldState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemStateEvent.java // public class ItemStateEvent implements ItemEvent { // protected final Item item; // protected final State itemState; // // public ItemStateEvent(Item item, State itemState) { // super(); // this.item = item; // this.itemState = itemState; // } // // public Item getItem() { // return item; // } // // public String getName() { // return this.item.getName(); // } // // public State getItemState() { // return itemState; // } // // @Override // public String toString() { // return String.format("%s updated to %s", item.getName(), itemState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemUpdatedEvent.java // public class ItemUpdatedEvent { // protected final Item newItem; // protected final String oldItemName; // // public ItemUpdatedEvent(Item newItem, String oldItemName) { // super(); // this.newItem = newItem; // this.oldItemName = oldItemName; // } // // public Item getNewItem() { // return newItem; // } // // public String getOldItemName() { // return oldItemName; // } // // @Override // public String toString() { // return "Item '" + oldItemName + "' has been updated."; // } // } // Path: runtime/com.incquerylabs.smarthome.eventbus.logger/src/com/incquerylabs/iot/eventbus/logger/ExampleEventSubscriber.java import java.util.Collection; import org.eclipse.smarthome.core.items.Item; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.incquerylabs.smarthome.eventbus.api.IEventSubscriber; import com.incquerylabs.smarthome.eventbus.api.events.GroupItemStateChangedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemAddedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemCommandEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemRemovedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemStateChangedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemStateEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemUpdatedEvent; package com.incquerylabs.iot.eventbus.logger; public class ExampleEventSubscriber implements IEventSubscriber { static Logger logger = LoggerFactory.getLogger(ExampleEventSubscriber.class); private static final String subscriberName = "Extended event bus logger"; @Override
public void stateUpdated(ItemStateEvent event) {
IncQueryLabs/smarthome-cep-demonstrator
runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/IEventSubscriber.java
// Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/GroupItemStateChangedEvent.java // public class GroupItemStateChangedEvent extends ItemStateChangedEvent { // // public GroupItemStateChangedEvent(Item item, State newState, State oldState) { // super(item, newState, oldState); // } // // @Override // public String toString() { // return String.format("%s group state changed from %s to %s", item.getName(), oldState, newState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemAddedEvent.java // public class ItemAddedEvent implements ItemEvent { // protected final Item item; // // public ItemAddedEvent(Item item) { // super(); // this.item = item; // } // // public Item getItem() { // return item; // } // // public String getName() { // return item.getName(); // } // // @Override // public String toString() { // return "Item '" + item.getName() + "' has been added."; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemCommandEvent.java // public class ItemCommandEvent extends ItemCommandBase implements ItemEvent { // // public ItemCommandEvent(Item item, Command command) { // super(item, command); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemRemovedEvent.java // public class ItemRemovedEvent implements ItemEvent { // protected final String itemName; // // public ItemRemovedEvent(String itemName) { // super(); // this.itemName = itemName; // } // // public String getName() { // return itemName; // } // // @Override // public String toString() { // return "Item '" + itemName + "' has been removed."; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemStateChangedEvent.java // public class ItemStateChangedEvent extends ItemStateChangedBase implements ItemEvent { // // public ItemStateChangedEvent(Item item, State newState, State oldState) { // super(item, newState, oldState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemStateEvent.java // public class ItemStateEvent implements ItemEvent { // protected final Item item; // protected final State itemState; // // public ItemStateEvent(Item item, State itemState) { // super(); // this.item = item; // this.itemState = itemState; // } // // public Item getItem() { // return item; // } // // public String getName() { // return this.item.getName(); // } // // public State getItemState() { // return itemState; // } // // @Override // public String toString() { // return String.format("%s updated to %s", item.getName(), itemState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemUpdatedEvent.java // public class ItemUpdatedEvent { // protected final Item newItem; // protected final String oldItemName; // // public ItemUpdatedEvent(Item newItem, String oldItemName) { // super(); // this.newItem = newItem; // this.oldItemName = oldItemName; // } // // public Item getNewItem() { // return newItem; // } // // public String getOldItemName() { // return oldItemName; // } // // @Override // public String toString() { // return "Item '" + oldItemName + "' has been updated."; // } // }
import java.util.Collection; import org.eclipse.smarthome.core.items.Item; import com.incquerylabs.smarthome.eventbus.api.events.GroupItemStateChangedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemAddedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemCommandEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemRemovedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemStateChangedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemStateEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemUpdatedEvent;
package com.incquerylabs.smarthome.eventbus.api; public interface IEventSubscriber { public void stateUpdated(ItemStateEvent event);
// Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/GroupItemStateChangedEvent.java // public class GroupItemStateChangedEvent extends ItemStateChangedEvent { // // public GroupItemStateChangedEvent(Item item, State newState, State oldState) { // super(item, newState, oldState); // } // // @Override // public String toString() { // return String.format("%s group state changed from %s to %s", item.getName(), oldState, newState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemAddedEvent.java // public class ItemAddedEvent implements ItemEvent { // protected final Item item; // // public ItemAddedEvent(Item item) { // super(); // this.item = item; // } // // public Item getItem() { // return item; // } // // public String getName() { // return item.getName(); // } // // @Override // public String toString() { // return "Item '" + item.getName() + "' has been added."; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemCommandEvent.java // public class ItemCommandEvent extends ItemCommandBase implements ItemEvent { // // public ItemCommandEvent(Item item, Command command) { // super(item, command); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemRemovedEvent.java // public class ItemRemovedEvent implements ItemEvent { // protected final String itemName; // // public ItemRemovedEvent(String itemName) { // super(); // this.itemName = itemName; // } // // public String getName() { // return itemName; // } // // @Override // public String toString() { // return "Item '" + itemName + "' has been removed."; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemStateChangedEvent.java // public class ItemStateChangedEvent extends ItemStateChangedBase implements ItemEvent { // // public ItemStateChangedEvent(Item item, State newState, State oldState) { // super(item, newState, oldState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemStateEvent.java // public class ItemStateEvent implements ItemEvent { // protected final Item item; // protected final State itemState; // // public ItemStateEvent(Item item, State itemState) { // super(); // this.item = item; // this.itemState = itemState; // } // // public Item getItem() { // return item; // } // // public String getName() { // return this.item.getName(); // } // // public State getItemState() { // return itemState; // } // // @Override // public String toString() { // return String.format("%s updated to %s", item.getName(), itemState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemUpdatedEvent.java // public class ItemUpdatedEvent { // protected final Item newItem; // protected final String oldItemName; // // public ItemUpdatedEvent(Item newItem, String oldItemName) { // super(); // this.newItem = newItem; // this.oldItemName = oldItemName; // } // // public Item getNewItem() { // return newItem; // } // // public String getOldItemName() { // return oldItemName; // } // // @Override // public String toString() { // return "Item '" + oldItemName + "' has been updated."; // } // } // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/IEventSubscriber.java import java.util.Collection; import org.eclipse.smarthome.core.items.Item; import com.incquerylabs.smarthome.eventbus.api.events.GroupItemStateChangedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemAddedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemCommandEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemRemovedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemStateChangedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemStateEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemUpdatedEvent; package com.incquerylabs.smarthome.eventbus.api; public interface IEventSubscriber { public void stateUpdated(ItemStateEvent event);
public void stateChanged(ItemStateChangedEvent event);
IncQueryLabs/smarthome-cep-demonstrator
runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/IEventSubscriber.java
// Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/GroupItemStateChangedEvent.java // public class GroupItemStateChangedEvent extends ItemStateChangedEvent { // // public GroupItemStateChangedEvent(Item item, State newState, State oldState) { // super(item, newState, oldState); // } // // @Override // public String toString() { // return String.format("%s group state changed from %s to %s", item.getName(), oldState, newState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemAddedEvent.java // public class ItemAddedEvent implements ItemEvent { // protected final Item item; // // public ItemAddedEvent(Item item) { // super(); // this.item = item; // } // // public Item getItem() { // return item; // } // // public String getName() { // return item.getName(); // } // // @Override // public String toString() { // return "Item '" + item.getName() + "' has been added."; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemCommandEvent.java // public class ItemCommandEvent extends ItemCommandBase implements ItemEvent { // // public ItemCommandEvent(Item item, Command command) { // super(item, command); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemRemovedEvent.java // public class ItemRemovedEvent implements ItemEvent { // protected final String itemName; // // public ItemRemovedEvent(String itemName) { // super(); // this.itemName = itemName; // } // // public String getName() { // return itemName; // } // // @Override // public String toString() { // return "Item '" + itemName + "' has been removed."; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemStateChangedEvent.java // public class ItemStateChangedEvent extends ItemStateChangedBase implements ItemEvent { // // public ItemStateChangedEvent(Item item, State newState, State oldState) { // super(item, newState, oldState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemStateEvent.java // public class ItemStateEvent implements ItemEvent { // protected final Item item; // protected final State itemState; // // public ItemStateEvent(Item item, State itemState) { // super(); // this.item = item; // this.itemState = itemState; // } // // public Item getItem() { // return item; // } // // public String getName() { // return this.item.getName(); // } // // public State getItemState() { // return itemState; // } // // @Override // public String toString() { // return String.format("%s updated to %s", item.getName(), itemState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemUpdatedEvent.java // public class ItemUpdatedEvent { // protected final Item newItem; // protected final String oldItemName; // // public ItemUpdatedEvent(Item newItem, String oldItemName) { // super(); // this.newItem = newItem; // this.oldItemName = oldItemName; // } // // public Item getNewItem() { // return newItem; // } // // public String getOldItemName() { // return oldItemName; // } // // @Override // public String toString() { // return "Item '" + oldItemName + "' has been updated."; // } // }
import java.util.Collection; import org.eclipse.smarthome.core.items.Item; import com.incquerylabs.smarthome.eventbus.api.events.GroupItemStateChangedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemAddedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemCommandEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemRemovedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemStateChangedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemStateEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemUpdatedEvent;
package com.incquerylabs.smarthome.eventbus.api; public interface IEventSubscriber { public void stateUpdated(ItemStateEvent event); public void stateChanged(ItemStateChangedEvent event);
// Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/GroupItemStateChangedEvent.java // public class GroupItemStateChangedEvent extends ItemStateChangedEvent { // // public GroupItemStateChangedEvent(Item item, State newState, State oldState) { // super(item, newState, oldState); // } // // @Override // public String toString() { // return String.format("%s group state changed from %s to %s", item.getName(), oldState, newState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemAddedEvent.java // public class ItemAddedEvent implements ItemEvent { // protected final Item item; // // public ItemAddedEvent(Item item) { // super(); // this.item = item; // } // // public Item getItem() { // return item; // } // // public String getName() { // return item.getName(); // } // // @Override // public String toString() { // return "Item '" + item.getName() + "' has been added."; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemCommandEvent.java // public class ItemCommandEvent extends ItemCommandBase implements ItemEvent { // // public ItemCommandEvent(Item item, Command command) { // super(item, command); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemRemovedEvent.java // public class ItemRemovedEvent implements ItemEvent { // protected final String itemName; // // public ItemRemovedEvent(String itemName) { // super(); // this.itemName = itemName; // } // // public String getName() { // return itemName; // } // // @Override // public String toString() { // return "Item '" + itemName + "' has been removed."; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemStateChangedEvent.java // public class ItemStateChangedEvent extends ItemStateChangedBase implements ItemEvent { // // public ItemStateChangedEvent(Item item, State newState, State oldState) { // super(item, newState, oldState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemStateEvent.java // public class ItemStateEvent implements ItemEvent { // protected final Item item; // protected final State itemState; // // public ItemStateEvent(Item item, State itemState) { // super(); // this.item = item; // this.itemState = itemState; // } // // public Item getItem() { // return item; // } // // public String getName() { // return this.item.getName(); // } // // public State getItemState() { // return itemState; // } // // @Override // public String toString() { // return String.format("%s updated to %s", item.getName(), itemState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemUpdatedEvent.java // public class ItemUpdatedEvent { // protected final Item newItem; // protected final String oldItemName; // // public ItemUpdatedEvent(Item newItem, String oldItemName) { // super(); // this.newItem = newItem; // this.oldItemName = oldItemName; // } // // public Item getNewItem() { // return newItem; // } // // public String getOldItemName() { // return oldItemName; // } // // @Override // public String toString() { // return "Item '" + oldItemName + "' has been updated."; // } // } // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/IEventSubscriber.java import java.util.Collection; import org.eclipse.smarthome.core.items.Item; import com.incquerylabs.smarthome.eventbus.api.events.GroupItemStateChangedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemAddedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemCommandEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemRemovedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemStateChangedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemStateEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemUpdatedEvent; package com.incquerylabs.smarthome.eventbus.api; public interface IEventSubscriber { public void stateUpdated(ItemStateEvent event); public void stateChanged(ItemStateChangedEvent event);
public void groupStateChanged(GroupItemStateChangedEvent event);
IncQueryLabs/smarthome-cep-demonstrator
runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/IEventSubscriber.java
// Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/GroupItemStateChangedEvent.java // public class GroupItemStateChangedEvent extends ItemStateChangedEvent { // // public GroupItemStateChangedEvent(Item item, State newState, State oldState) { // super(item, newState, oldState); // } // // @Override // public String toString() { // return String.format("%s group state changed from %s to %s", item.getName(), oldState, newState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemAddedEvent.java // public class ItemAddedEvent implements ItemEvent { // protected final Item item; // // public ItemAddedEvent(Item item) { // super(); // this.item = item; // } // // public Item getItem() { // return item; // } // // public String getName() { // return item.getName(); // } // // @Override // public String toString() { // return "Item '" + item.getName() + "' has been added."; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemCommandEvent.java // public class ItemCommandEvent extends ItemCommandBase implements ItemEvent { // // public ItemCommandEvent(Item item, Command command) { // super(item, command); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemRemovedEvent.java // public class ItemRemovedEvent implements ItemEvent { // protected final String itemName; // // public ItemRemovedEvent(String itemName) { // super(); // this.itemName = itemName; // } // // public String getName() { // return itemName; // } // // @Override // public String toString() { // return "Item '" + itemName + "' has been removed."; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemStateChangedEvent.java // public class ItemStateChangedEvent extends ItemStateChangedBase implements ItemEvent { // // public ItemStateChangedEvent(Item item, State newState, State oldState) { // super(item, newState, oldState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemStateEvent.java // public class ItemStateEvent implements ItemEvent { // protected final Item item; // protected final State itemState; // // public ItemStateEvent(Item item, State itemState) { // super(); // this.item = item; // this.itemState = itemState; // } // // public Item getItem() { // return item; // } // // public String getName() { // return this.item.getName(); // } // // public State getItemState() { // return itemState; // } // // @Override // public String toString() { // return String.format("%s updated to %s", item.getName(), itemState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemUpdatedEvent.java // public class ItemUpdatedEvent { // protected final Item newItem; // protected final String oldItemName; // // public ItemUpdatedEvent(Item newItem, String oldItemName) { // super(); // this.newItem = newItem; // this.oldItemName = oldItemName; // } // // public Item getNewItem() { // return newItem; // } // // public String getOldItemName() { // return oldItemName; // } // // @Override // public String toString() { // return "Item '" + oldItemName + "' has been updated."; // } // }
import java.util.Collection; import org.eclipse.smarthome.core.items.Item; import com.incquerylabs.smarthome.eventbus.api.events.GroupItemStateChangedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemAddedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemCommandEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemRemovedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemStateChangedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemStateEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemUpdatedEvent;
package com.incquerylabs.smarthome.eventbus.api; public interface IEventSubscriber { public void stateUpdated(ItemStateEvent event); public void stateChanged(ItemStateChangedEvent event); public void groupStateChanged(GroupItemStateChangedEvent event);
// Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/GroupItemStateChangedEvent.java // public class GroupItemStateChangedEvent extends ItemStateChangedEvent { // // public GroupItemStateChangedEvent(Item item, State newState, State oldState) { // super(item, newState, oldState); // } // // @Override // public String toString() { // return String.format("%s group state changed from %s to %s", item.getName(), oldState, newState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemAddedEvent.java // public class ItemAddedEvent implements ItemEvent { // protected final Item item; // // public ItemAddedEvent(Item item) { // super(); // this.item = item; // } // // public Item getItem() { // return item; // } // // public String getName() { // return item.getName(); // } // // @Override // public String toString() { // return "Item '" + item.getName() + "' has been added."; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemCommandEvent.java // public class ItemCommandEvent extends ItemCommandBase implements ItemEvent { // // public ItemCommandEvent(Item item, Command command) { // super(item, command); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemRemovedEvent.java // public class ItemRemovedEvent implements ItemEvent { // protected final String itemName; // // public ItemRemovedEvent(String itemName) { // super(); // this.itemName = itemName; // } // // public String getName() { // return itemName; // } // // @Override // public String toString() { // return "Item '" + itemName + "' has been removed."; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemStateChangedEvent.java // public class ItemStateChangedEvent extends ItemStateChangedBase implements ItemEvent { // // public ItemStateChangedEvent(Item item, State newState, State oldState) { // super(item, newState, oldState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemStateEvent.java // public class ItemStateEvent implements ItemEvent { // protected final Item item; // protected final State itemState; // // public ItemStateEvent(Item item, State itemState) { // super(); // this.item = item; // this.itemState = itemState; // } // // public Item getItem() { // return item; // } // // public String getName() { // return this.item.getName(); // } // // public State getItemState() { // return itemState; // } // // @Override // public String toString() { // return String.format("%s updated to %s", item.getName(), itemState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemUpdatedEvent.java // public class ItemUpdatedEvent { // protected final Item newItem; // protected final String oldItemName; // // public ItemUpdatedEvent(Item newItem, String oldItemName) { // super(); // this.newItem = newItem; // this.oldItemName = oldItemName; // } // // public Item getNewItem() { // return newItem; // } // // public String getOldItemName() { // return oldItemName; // } // // @Override // public String toString() { // return "Item '" + oldItemName + "' has been updated."; // } // } // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/IEventSubscriber.java import java.util.Collection; import org.eclipse.smarthome.core.items.Item; import com.incquerylabs.smarthome.eventbus.api.events.GroupItemStateChangedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemAddedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemCommandEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemRemovedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemStateChangedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemStateEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemUpdatedEvent; package com.incquerylabs.smarthome.eventbus.api; public interface IEventSubscriber { public void stateUpdated(ItemStateEvent event); public void stateChanged(ItemStateChangedEvent event); public void groupStateChanged(GroupItemStateChangedEvent event);
public void commandReceived(ItemCommandEvent event);
IncQueryLabs/smarthome-cep-demonstrator
runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/IEventSubscriber.java
// Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/GroupItemStateChangedEvent.java // public class GroupItemStateChangedEvent extends ItemStateChangedEvent { // // public GroupItemStateChangedEvent(Item item, State newState, State oldState) { // super(item, newState, oldState); // } // // @Override // public String toString() { // return String.format("%s group state changed from %s to %s", item.getName(), oldState, newState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemAddedEvent.java // public class ItemAddedEvent implements ItemEvent { // protected final Item item; // // public ItemAddedEvent(Item item) { // super(); // this.item = item; // } // // public Item getItem() { // return item; // } // // public String getName() { // return item.getName(); // } // // @Override // public String toString() { // return "Item '" + item.getName() + "' has been added."; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemCommandEvent.java // public class ItemCommandEvent extends ItemCommandBase implements ItemEvent { // // public ItemCommandEvent(Item item, Command command) { // super(item, command); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemRemovedEvent.java // public class ItemRemovedEvent implements ItemEvent { // protected final String itemName; // // public ItemRemovedEvent(String itemName) { // super(); // this.itemName = itemName; // } // // public String getName() { // return itemName; // } // // @Override // public String toString() { // return "Item '" + itemName + "' has been removed."; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemStateChangedEvent.java // public class ItemStateChangedEvent extends ItemStateChangedBase implements ItemEvent { // // public ItemStateChangedEvent(Item item, State newState, State oldState) { // super(item, newState, oldState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemStateEvent.java // public class ItemStateEvent implements ItemEvent { // protected final Item item; // protected final State itemState; // // public ItemStateEvent(Item item, State itemState) { // super(); // this.item = item; // this.itemState = itemState; // } // // public Item getItem() { // return item; // } // // public String getName() { // return this.item.getName(); // } // // public State getItemState() { // return itemState; // } // // @Override // public String toString() { // return String.format("%s updated to %s", item.getName(), itemState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemUpdatedEvent.java // public class ItemUpdatedEvent { // protected final Item newItem; // protected final String oldItemName; // // public ItemUpdatedEvent(Item newItem, String oldItemName) { // super(); // this.newItem = newItem; // this.oldItemName = oldItemName; // } // // public Item getNewItem() { // return newItem; // } // // public String getOldItemName() { // return oldItemName; // } // // @Override // public String toString() { // return "Item '" + oldItemName + "' has been updated."; // } // }
import java.util.Collection; import org.eclipse.smarthome.core.items.Item; import com.incquerylabs.smarthome.eventbus.api.events.GroupItemStateChangedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemAddedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemCommandEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemRemovedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemStateChangedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemStateEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemUpdatedEvent;
package com.incquerylabs.smarthome.eventbus.api; public interface IEventSubscriber { public void stateUpdated(ItemStateEvent event); public void stateChanged(ItemStateChangedEvent event); public void groupStateChanged(GroupItemStateChangedEvent event); public void commandReceived(ItemCommandEvent event); public void initItems(Collection<Item> items);
// Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/GroupItemStateChangedEvent.java // public class GroupItemStateChangedEvent extends ItemStateChangedEvent { // // public GroupItemStateChangedEvent(Item item, State newState, State oldState) { // super(item, newState, oldState); // } // // @Override // public String toString() { // return String.format("%s group state changed from %s to %s", item.getName(), oldState, newState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemAddedEvent.java // public class ItemAddedEvent implements ItemEvent { // protected final Item item; // // public ItemAddedEvent(Item item) { // super(); // this.item = item; // } // // public Item getItem() { // return item; // } // // public String getName() { // return item.getName(); // } // // @Override // public String toString() { // return "Item '" + item.getName() + "' has been added."; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemCommandEvent.java // public class ItemCommandEvent extends ItemCommandBase implements ItemEvent { // // public ItemCommandEvent(Item item, Command command) { // super(item, command); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemRemovedEvent.java // public class ItemRemovedEvent implements ItemEvent { // protected final String itemName; // // public ItemRemovedEvent(String itemName) { // super(); // this.itemName = itemName; // } // // public String getName() { // return itemName; // } // // @Override // public String toString() { // return "Item '" + itemName + "' has been removed."; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemStateChangedEvent.java // public class ItemStateChangedEvent extends ItemStateChangedBase implements ItemEvent { // // public ItemStateChangedEvent(Item item, State newState, State oldState) { // super(item, newState, oldState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemStateEvent.java // public class ItemStateEvent implements ItemEvent { // protected final Item item; // protected final State itemState; // // public ItemStateEvent(Item item, State itemState) { // super(); // this.item = item; // this.itemState = itemState; // } // // public Item getItem() { // return item; // } // // public String getName() { // return this.item.getName(); // } // // public State getItemState() { // return itemState; // } // // @Override // public String toString() { // return String.format("%s updated to %s", item.getName(), itemState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemUpdatedEvent.java // public class ItemUpdatedEvent { // protected final Item newItem; // protected final String oldItemName; // // public ItemUpdatedEvent(Item newItem, String oldItemName) { // super(); // this.newItem = newItem; // this.oldItemName = oldItemName; // } // // public Item getNewItem() { // return newItem; // } // // public String getOldItemName() { // return oldItemName; // } // // @Override // public String toString() { // return "Item '" + oldItemName + "' has been updated."; // } // } // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/IEventSubscriber.java import java.util.Collection; import org.eclipse.smarthome.core.items.Item; import com.incquerylabs.smarthome.eventbus.api.events.GroupItemStateChangedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemAddedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemCommandEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemRemovedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemStateChangedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemStateEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemUpdatedEvent; package com.incquerylabs.smarthome.eventbus.api; public interface IEventSubscriber { public void stateUpdated(ItemStateEvent event); public void stateChanged(ItemStateChangedEvent event); public void groupStateChanged(GroupItemStateChangedEvent event); public void commandReceived(ItemCommandEvent event); public void initItems(Collection<Item> items);
public void itemAdded(ItemAddedEvent event);
IncQueryLabs/smarthome-cep-demonstrator
runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/IEventSubscriber.java
// Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/GroupItemStateChangedEvent.java // public class GroupItemStateChangedEvent extends ItemStateChangedEvent { // // public GroupItemStateChangedEvent(Item item, State newState, State oldState) { // super(item, newState, oldState); // } // // @Override // public String toString() { // return String.format("%s group state changed from %s to %s", item.getName(), oldState, newState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemAddedEvent.java // public class ItemAddedEvent implements ItemEvent { // protected final Item item; // // public ItemAddedEvent(Item item) { // super(); // this.item = item; // } // // public Item getItem() { // return item; // } // // public String getName() { // return item.getName(); // } // // @Override // public String toString() { // return "Item '" + item.getName() + "' has been added."; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemCommandEvent.java // public class ItemCommandEvent extends ItemCommandBase implements ItemEvent { // // public ItemCommandEvent(Item item, Command command) { // super(item, command); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemRemovedEvent.java // public class ItemRemovedEvent implements ItemEvent { // protected final String itemName; // // public ItemRemovedEvent(String itemName) { // super(); // this.itemName = itemName; // } // // public String getName() { // return itemName; // } // // @Override // public String toString() { // return "Item '" + itemName + "' has been removed."; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemStateChangedEvent.java // public class ItemStateChangedEvent extends ItemStateChangedBase implements ItemEvent { // // public ItemStateChangedEvent(Item item, State newState, State oldState) { // super(item, newState, oldState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemStateEvent.java // public class ItemStateEvent implements ItemEvent { // protected final Item item; // protected final State itemState; // // public ItemStateEvent(Item item, State itemState) { // super(); // this.item = item; // this.itemState = itemState; // } // // public Item getItem() { // return item; // } // // public String getName() { // return this.item.getName(); // } // // public State getItemState() { // return itemState; // } // // @Override // public String toString() { // return String.format("%s updated to %s", item.getName(), itemState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemUpdatedEvent.java // public class ItemUpdatedEvent { // protected final Item newItem; // protected final String oldItemName; // // public ItemUpdatedEvent(Item newItem, String oldItemName) { // super(); // this.newItem = newItem; // this.oldItemName = oldItemName; // } // // public Item getNewItem() { // return newItem; // } // // public String getOldItemName() { // return oldItemName; // } // // @Override // public String toString() { // return "Item '" + oldItemName + "' has been updated."; // } // }
import java.util.Collection; import org.eclipse.smarthome.core.items.Item; import com.incquerylabs.smarthome.eventbus.api.events.GroupItemStateChangedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemAddedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemCommandEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemRemovedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemStateChangedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemStateEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemUpdatedEvent;
package com.incquerylabs.smarthome.eventbus.api; public interface IEventSubscriber { public void stateUpdated(ItemStateEvent event); public void stateChanged(ItemStateChangedEvent event); public void groupStateChanged(GroupItemStateChangedEvent event); public void commandReceived(ItemCommandEvent event); public void initItems(Collection<Item> items); public void itemAdded(ItemAddedEvent event);
// Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/GroupItemStateChangedEvent.java // public class GroupItemStateChangedEvent extends ItemStateChangedEvent { // // public GroupItemStateChangedEvent(Item item, State newState, State oldState) { // super(item, newState, oldState); // } // // @Override // public String toString() { // return String.format("%s group state changed from %s to %s", item.getName(), oldState, newState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemAddedEvent.java // public class ItemAddedEvent implements ItemEvent { // protected final Item item; // // public ItemAddedEvent(Item item) { // super(); // this.item = item; // } // // public Item getItem() { // return item; // } // // public String getName() { // return item.getName(); // } // // @Override // public String toString() { // return "Item '" + item.getName() + "' has been added."; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemCommandEvent.java // public class ItemCommandEvent extends ItemCommandBase implements ItemEvent { // // public ItemCommandEvent(Item item, Command command) { // super(item, command); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemRemovedEvent.java // public class ItemRemovedEvent implements ItemEvent { // protected final String itemName; // // public ItemRemovedEvent(String itemName) { // super(); // this.itemName = itemName; // } // // public String getName() { // return itemName; // } // // @Override // public String toString() { // return "Item '" + itemName + "' has been removed."; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemStateChangedEvent.java // public class ItemStateChangedEvent extends ItemStateChangedBase implements ItemEvent { // // public ItemStateChangedEvent(Item item, State newState, State oldState) { // super(item, newState, oldState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemStateEvent.java // public class ItemStateEvent implements ItemEvent { // protected final Item item; // protected final State itemState; // // public ItemStateEvent(Item item, State itemState) { // super(); // this.item = item; // this.itemState = itemState; // } // // public Item getItem() { // return item; // } // // public String getName() { // return this.item.getName(); // } // // public State getItemState() { // return itemState; // } // // @Override // public String toString() { // return String.format("%s updated to %s", item.getName(), itemState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemUpdatedEvent.java // public class ItemUpdatedEvent { // protected final Item newItem; // protected final String oldItemName; // // public ItemUpdatedEvent(Item newItem, String oldItemName) { // super(); // this.newItem = newItem; // this.oldItemName = oldItemName; // } // // public Item getNewItem() { // return newItem; // } // // public String getOldItemName() { // return oldItemName; // } // // @Override // public String toString() { // return "Item '" + oldItemName + "' has been updated."; // } // } // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/IEventSubscriber.java import java.util.Collection; import org.eclipse.smarthome.core.items.Item; import com.incquerylabs.smarthome.eventbus.api.events.GroupItemStateChangedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemAddedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemCommandEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemRemovedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemStateChangedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemStateEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemUpdatedEvent; package com.incquerylabs.smarthome.eventbus.api; public interface IEventSubscriber { public void stateUpdated(ItemStateEvent event); public void stateChanged(ItemStateChangedEvent event); public void groupStateChanged(GroupItemStateChangedEvent event); public void commandReceived(ItemCommandEvent event); public void initItems(Collection<Item> items); public void itemAdded(ItemAddedEvent event);
public void itemRemoved(ItemRemovedEvent event);
IncQueryLabs/smarthome-cep-demonstrator
runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/IEventSubscriber.java
// Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/GroupItemStateChangedEvent.java // public class GroupItemStateChangedEvent extends ItemStateChangedEvent { // // public GroupItemStateChangedEvent(Item item, State newState, State oldState) { // super(item, newState, oldState); // } // // @Override // public String toString() { // return String.format("%s group state changed from %s to %s", item.getName(), oldState, newState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemAddedEvent.java // public class ItemAddedEvent implements ItemEvent { // protected final Item item; // // public ItemAddedEvent(Item item) { // super(); // this.item = item; // } // // public Item getItem() { // return item; // } // // public String getName() { // return item.getName(); // } // // @Override // public String toString() { // return "Item '" + item.getName() + "' has been added."; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemCommandEvent.java // public class ItemCommandEvent extends ItemCommandBase implements ItemEvent { // // public ItemCommandEvent(Item item, Command command) { // super(item, command); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemRemovedEvent.java // public class ItemRemovedEvent implements ItemEvent { // protected final String itemName; // // public ItemRemovedEvent(String itemName) { // super(); // this.itemName = itemName; // } // // public String getName() { // return itemName; // } // // @Override // public String toString() { // return "Item '" + itemName + "' has been removed."; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemStateChangedEvent.java // public class ItemStateChangedEvent extends ItemStateChangedBase implements ItemEvent { // // public ItemStateChangedEvent(Item item, State newState, State oldState) { // super(item, newState, oldState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemStateEvent.java // public class ItemStateEvent implements ItemEvent { // protected final Item item; // protected final State itemState; // // public ItemStateEvent(Item item, State itemState) { // super(); // this.item = item; // this.itemState = itemState; // } // // public Item getItem() { // return item; // } // // public String getName() { // return this.item.getName(); // } // // public State getItemState() { // return itemState; // } // // @Override // public String toString() { // return String.format("%s updated to %s", item.getName(), itemState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemUpdatedEvent.java // public class ItemUpdatedEvent { // protected final Item newItem; // protected final String oldItemName; // // public ItemUpdatedEvent(Item newItem, String oldItemName) { // super(); // this.newItem = newItem; // this.oldItemName = oldItemName; // } // // public Item getNewItem() { // return newItem; // } // // public String getOldItemName() { // return oldItemName; // } // // @Override // public String toString() { // return "Item '" + oldItemName + "' has been updated."; // } // }
import java.util.Collection; import org.eclipse.smarthome.core.items.Item; import com.incquerylabs.smarthome.eventbus.api.events.GroupItemStateChangedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemAddedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemCommandEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemRemovedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemStateChangedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemStateEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemUpdatedEvent;
package com.incquerylabs.smarthome.eventbus.api; public interface IEventSubscriber { public void stateUpdated(ItemStateEvent event); public void stateChanged(ItemStateChangedEvent event); public void groupStateChanged(GroupItemStateChangedEvent event); public void commandReceived(ItemCommandEvent event); public void initItems(Collection<Item> items); public void itemAdded(ItemAddedEvent event); public void itemRemoved(ItemRemovedEvent event);
// Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/GroupItemStateChangedEvent.java // public class GroupItemStateChangedEvent extends ItemStateChangedEvent { // // public GroupItemStateChangedEvent(Item item, State newState, State oldState) { // super(item, newState, oldState); // } // // @Override // public String toString() { // return String.format("%s group state changed from %s to %s", item.getName(), oldState, newState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemAddedEvent.java // public class ItemAddedEvent implements ItemEvent { // protected final Item item; // // public ItemAddedEvent(Item item) { // super(); // this.item = item; // } // // public Item getItem() { // return item; // } // // public String getName() { // return item.getName(); // } // // @Override // public String toString() { // return "Item '" + item.getName() + "' has been added."; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemCommandEvent.java // public class ItemCommandEvent extends ItemCommandBase implements ItemEvent { // // public ItemCommandEvent(Item item, Command command) { // super(item, command); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemRemovedEvent.java // public class ItemRemovedEvent implements ItemEvent { // protected final String itemName; // // public ItemRemovedEvent(String itemName) { // super(); // this.itemName = itemName; // } // // public String getName() { // return itemName; // } // // @Override // public String toString() { // return "Item '" + itemName + "' has been removed."; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemStateChangedEvent.java // public class ItemStateChangedEvent extends ItemStateChangedBase implements ItemEvent { // // public ItemStateChangedEvent(Item item, State newState, State oldState) { // super(item, newState, oldState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemStateEvent.java // public class ItemStateEvent implements ItemEvent { // protected final Item item; // protected final State itemState; // // public ItemStateEvent(Item item, State itemState) { // super(); // this.item = item; // this.itemState = itemState; // } // // public Item getItem() { // return item; // } // // public String getName() { // return this.item.getName(); // } // // public State getItemState() { // return itemState; // } // // @Override // public String toString() { // return String.format("%s updated to %s", item.getName(), itemState); // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/events/ItemUpdatedEvent.java // public class ItemUpdatedEvent { // protected final Item newItem; // protected final String oldItemName; // // public ItemUpdatedEvent(Item newItem, String oldItemName) { // super(); // this.newItem = newItem; // this.oldItemName = oldItemName; // } // // public Item getNewItem() { // return newItem; // } // // public String getOldItemName() { // return oldItemName; // } // // @Override // public String toString() { // return "Item '" + oldItemName + "' has been updated."; // } // } // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/IEventSubscriber.java import java.util.Collection; import org.eclipse.smarthome.core.items.Item; import com.incquerylabs.smarthome.eventbus.api.events.GroupItemStateChangedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemAddedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemCommandEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemRemovedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemStateChangedEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemStateEvent; import com.incquerylabs.smarthome.eventbus.api.events.ItemUpdatedEvent; package com.incquerylabs.smarthome.eventbus.api; public interface IEventSubscriber { public void stateUpdated(ItemStateEvent event); public void stateChanged(ItemStateChangedEvent event); public void groupStateChanged(GroupItemStateChangedEvent event); public void commandReceived(ItemCommandEvent event); public void initItems(Collection<Item> items); public void itemAdded(ItemAddedEvent event); public void itemRemoved(ItemRemovedEvent event);
public void itemUpdated(ItemUpdatedEvent event);
IncQueryLabs/smarthome-cep-demonstrator
sensors/com.incquerylabs.smarthome.binding.simple-motion-sensor/src/main/java/com/incquerylabs/smarthome/binding/simplemotionsensor/internal/SimpleMotionSensorHandlerFactory.java
// Path: sensors/com.incquerylabs.smarthome.binding.simple-motion-sensor/src/main/java/com/incquerylabs/smarthome/binding/simplemotionsensor/SimpleMotionSensorBindingConstants.java // public static final ThingTypeUID THING_TYPE_SIMPLE_MOTION_SENSOR = new ThingTypeUID(BINDING_ID, THING_TYPE_ID); // // Path: sensors/com.incquerylabs.smarthome.binding.simple-motion-sensor/src/main/java/com/incquerylabs/smarthome/binding/simplemotionsensor/handler/SimpleMotionSensorHandler.java // public class SimpleMotionSensorHandler extends BaseThingHandler { // // private final Logger logger = LoggerFactory.getLogger(SimpleMotionSensorHandler.class); // // public SimpleMotionSensorHandler(Thing thing) { // super(thing); // } // // @Override // public void handleCommand(ChannelUID channelUID, Command command) { // if (channelUID.getId().equals(ALLOW_PIR_SWITCH)) { // // TODO: handle command // // // Note: if communication with thing fails for some reason, // // indicate that by setting the status with detail information // // updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, // // "Could not control device at IP address x.x.x.x"); // } else if (channelUID.getId().equals(PIR_SWITCH)) { // if ((OnOffType) command == OnOffType.ON) { // triggerChannel(getThing().getChannel(EVENT_CHANNEL_ID_MOTION).getUID(), EVENT_MOTION_START); // triggerChannel(getThing().getChannel(EVENT_CHANNEL_ID_MOTION_START).getUID(), EVENT_MOTION_START); // } else if ((OnOffType) command == OnOffType.OFF) { // triggerChannel(getThing().getChannel(EVENT_CHANNEL_ID_MOTION).getUID(), EVENT_MOTION_STOP); // triggerChannel(getThing().getChannel(EVENT_CHANNEL_ID_MOTION_STOP).getUID(), EVENT_MOTION_STOP); // } // } else if (channelUID.getId().equals(MQTT_SWITCH)) { // // } else if (channelUID.getId().equals(MOTION)) { // // } // } // // @Override // public void initialize() { // // TODO: Initialize the thing. If done set status to ONLINE to indicate proper working. // // Long running initialization should be done asynchronously in background. // updateStatus(ThingStatus.ONLINE); // // // Note: When initialization can NOT be done set the status with more details for further // // analysis. See also class ThingStatusDetail for all available status details. // // Add a description to give user information to understand why thing does not work // // as expected. E.g. // // updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, // // "Can not access device as username and/or password are invalid"); // } // }
import static com.incquerylabs.smarthome.binding.simplemotionsensor.SimpleMotionSensorBindingConstants.THING_TYPE_SIMPLE_MOTION_SENSOR; import java.util.Collections; import java.util.Set; import org.eclipse.smarthome.core.thing.Thing; import org.eclipse.smarthome.core.thing.ThingTypeUID; import org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory; import org.eclipse.smarthome.core.thing.binding.ThingHandler; import com.incquerylabs.smarthome.binding.simplemotionsensor.handler.SimpleMotionSensorHandler;
/** * Copyright (c) 2010-2017 by the respective copyright holders. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ package com.incquerylabs.smarthome.binding.simplemotionsensor.internal; /** * The {@link SimpleMotionSensorHandlerFactory} is responsible for creating things and thing * handlers. * * @author dandrid - Initial contribution */ public class SimpleMotionSensorHandlerFactory extends BaseThingHandlerFactory { private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_SIMPLE_MOTION_SENSOR); @Override public boolean supportsThingType(ThingTypeUID thingTypeUID) { return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID); } @Override protected ThingHandler createHandler(Thing thing) { ThingTypeUID thingTypeUID = thing.getThingTypeUID(); if (thingTypeUID.equals(THING_TYPE_SIMPLE_MOTION_SENSOR)) {
// Path: sensors/com.incquerylabs.smarthome.binding.simple-motion-sensor/src/main/java/com/incquerylabs/smarthome/binding/simplemotionsensor/SimpleMotionSensorBindingConstants.java // public static final ThingTypeUID THING_TYPE_SIMPLE_MOTION_SENSOR = new ThingTypeUID(BINDING_ID, THING_TYPE_ID); // // Path: sensors/com.incquerylabs.smarthome.binding.simple-motion-sensor/src/main/java/com/incquerylabs/smarthome/binding/simplemotionsensor/handler/SimpleMotionSensorHandler.java // public class SimpleMotionSensorHandler extends BaseThingHandler { // // private final Logger logger = LoggerFactory.getLogger(SimpleMotionSensorHandler.class); // // public SimpleMotionSensorHandler(Thing thing) { // super(thing); // } // // @Override // public void handleCommand(ChannelUID channelUID, Command command) { // if (channelUID.getId().equals(ALLOW_PIR_SWITCH)) { // // TODO: handle command // // // Note: if communication with thing fails for some reason, // // indicate that by setting the status with detail information // // updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, // // "Could not control device at IP address x.x.x.x"); // } else if (channelUID.getId().equals(PIR_SWITCH)) { // if ((OnOffType) command == OnOffType.ON) { // triggerChannel(getThing().getChannel(EVENT_CHANNEL_ID_MOTION).getUID(), EVENT_MOTION_START); // triggerChannel(getThing().getChannel(EVENT_CHANNEL_ID_MOTION_START).getUID(), EVENT_MOTION_START); // } else if ((OnOffType) command == OnOffType.OFF) { // triggerChannel(getThing().getChannel(EVENT_CHANNEL_ID_MOTION).getUID(), EVENT_MOTION_STOP); // triggerChannel(getThing().getChannel(EVENT_CHANNEL_ID_MOTION_STOP).getUID(), EVENT_MOTION_STOP); // } // } else if (channelUID.getId().equals(MQTT_SWITCH)) { // // } else if (channelUID.getId().equals(MOTION)) { // // } // } // // @Override // public void initialize() { // // TODO: Initialize the thing. If done set status to ONLINE to indicate proper working. // // Long running initialization should be done asynchronously in background. // updateStatus(ThingStatus.ONLINE); // // // Note: When initialization can NOT be done set the status with more details for further // // analysis. See also class ThingStatusDetail for all available status details. // // Add a description to give user information to understand why thing does not work // // as expected. E.g. // // updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, // // "Can not access device as username and/or password are invalid"); // } // } // Path: sensors/com.incquerylabs.smarthome.binding.simple-motion-sensor/src/main/java/com/incquerylabs/smarthome/binding/simplemotionsensor/internal/SimpleMotionSensorHandlerFactory.java import static com.incquerylabs.smarthome.binding.simplemotionsensor.SimpleMotionSensorBindingConstants.THING_TYPE_SIMPLE_MOTION_SENSOR; import java.util.Collections; import java.util.Set; import org.eclipse.smarthome.core.thing.Thing; import org.eclipse.smarthome.core.thing.ThingTypeUID; import org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory; import org.eclipse.smarthome.core.thing.binding.ThingHandler; import com.incquerylabs.smarthome.binding.simplemotionsensor.handler.SimpleMotionSensorHandler; /** * Copyright (c) 2010-2017 by the respective copyright holders. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ package com.incquerylabs.smarthome.binding.simplemotionsensor.internal; /** * The {@link SimpleMotionSensorHandlerFactory} is responsible for creating things and thing * handlers. * * @author dandrid - Initial contribution */ public class SimpleMotionSensorHandlerFactory extends BaseThingHandlerFactory { private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_SIMPLE_MOTION_SENSOR); @Override public boolean supportsThingType(ThingTypeUID thingTypeUID) { return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID); } @Override protected ThingHandler createHandler(Thing thing) { ThingTypeUID thingTypeUID = thing.getThingTypeUID(); if (thingTypeUID.equals(THING_TYPE_SIMPLE_MOTION_SENSOR)) {
return new SimpleMotionSensorHandler(thing);
IncQueryLabs/smarthome-cep-demonstrator
runtime/com.incquerylabs.smarthome.eventbus.service/src/main/java/com/incquerylabs/smarthome/eventbus/service/handler/EventBusHandler.java
// Path: runtime/com.incquerylabs.smarthome.eventbus.service/src/main/java/com/incquerylabs/smarthome/eventbus/service/EventBusBindingConstants.java // public static final String CHANNEL_1 = "channel1";
import static com.incquerylabs.smarthome.eventbus.service.EventBusBindingConstants.CHANNEL_1; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.smarthome.core.thing.ChannelUID; import org.eclipse.smarthome.core.thing.Thing; import org.eclipse.smarthome.core.thing.ThingStatus; import org.eclipse.smarthome.core.thing.binding.BaseThingHandler; import org.eclipse.smarthome.core.types.Command; import org.slf4j.Logger; import org.slf4j.LoggerFactory;
/** * Copyright (c) 2010-2017 by the respective copyright holders. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ package com.incquerylabs.smarthome.eventbus.service.handler; /** * The {@link EventBusHandler} is responsible for handling commands, which are * sent to one of the channels. * * @author dandrid - Initial contribution */ public class EventBusHandler extends BaseThingHandler { @SuppressWarnings("unused") private final Logger logger = LoggerFactory.getLogger(EventBusHandler.class); public EventBusHandler(@NonNull Thing thing) { super(thing); } @Override public void handleCommand(ChannelUID channelUID, Command command) {
// Path: runtime/com.incquerylabs.smarthome.eventbus.service/src/main/java/com/incquerylabs/smarthome/eventbus/service/EventBusBindingConstants.java // public static final String CHANNEL_1 = "channel1"; // Path: runtime/com.incquerylabs.smarthome.eventbus.service/src/main/java/com/incquerylabs/smarthome/eventbus/service/handler/EventBusHandler.java import static com.incquerylabs.smarthome.eventbus.service.EventBusBindingConstants.CHANNEL_1; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.smarthome.core.thing.ChannelUID; import org.eclipse.smarthome.core.thing.Thing; import org.eclipse.smarthome.core.thing.ThingStatus; import org.eclipse.smarthome.core.thing.binding.BaseThingHandler; import org.eclipse.smarthome.core.types.Command; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Copyright (c) 2010-2017 by the respective copyright holders. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ package com.incquerylabs.smarthome.eventbus.service.handler; /** * The {@link EventBusHandler} is responsible for handling commands, which are * sent to one of the channels. * * @author dandrid - Initial contribution */ public class EventBusHandler extends BaseThingHandler { @SuppressWarnings("unused") private final Logger logger = LoggerFactory.getLogger(EventBusHandler.class); public EventBusHandler(@NonNull Thing thing) { super(thing); } @Override public void handleCommand(ChannelUID channelUID, Command command) {
if (channelUID.getId().equals(CHANNEL_1)) {
IncQueryLabs/smarthome-cep-demonstrator
tests/com.incquerylabs.smarthome.eventbus.ruleengine.droolshomeio/src/com/incquerylabs/smarthome/eventbus/ruleengine/droolshomeio/tests/internal/EventBusMock.java
// Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/IEventPublisher.java // public interface IEventPublisher { // public void postCommand(String itemName, Command command); // // public void postCommand(Item item, Command command); // // public void startComplexCommand(IComplexCommand complexCommand); // // public void stopComplexCommand(String itemName); // // public void stopComplexCommand(Item item); // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/IComplexCommand.java // public interface IComplexCommand { // // public void start(IEventPublisher publisher); // // public void stop(); // // public String getItemName(); // }
import java.util.HashMap; import java.util.LinkedList; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.eclipse.smarthome.core.items.GenericItem; import org.eclipse.smarthome.core.items.Item; import org.eclipse.smarthome.core.types.Command; import org.eclipse.smarthome.core.types.State; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.incquerylabs.smarthome.eventbus.api.IEventPublisher; import com.incquerylabs.smarthome.eventbus.api.IComplexCommand;
package com.incquerylabs.smarthome.eventbus.ruleengine.droolshomeio.tests.internal; public class EventBusMock implements IEventPublisher { static Logger logger = LoggerFactory.getLogger(EventBusMock.class); Map<Item, LinkedList<Command>> commands = new HashMap<Item, LinkedList<Command>>(); Map<String, Item> items = new HashMap<String, Item>();
// Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/IEventPublisher.java // public interface IEventPublisher { // public void postCommand(String itemName, Command command); // // public void postCommand(Item item, Command command); // // public void startComplexCommand(IComplexCommand complexCommand); // // public void stopComplexCommand(String itemName); // // public void stopComplexCommand(Item item); // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/IComplexCommand.java // public interface IComplexCommand { // // public void start(IEventPublisher publisher); // // public void stop(); // // public String getItemName(); // } // Path: tests/com.incquerylabs.smarthome.eventbus.ruleengine.droolshomeio/src/com/incquerylabs/smarthome/eventbus/ruleengine/droolshomeio/tests/internal/EventBusMock.java import java.util.HashMap; import java.util.LinkedList; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.eclipse.smarthome.core.items.GenericItem; import org.eclipse.smarthome.core.items.Item; import org.eclipse.smarthome.core.types.Command; import org.eclipse.smarthome.core.types.State; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.incquerylabs.smarthome.eventbus.api.IEventPublisher; import com.incquerylabs.smarthome.eventbus.api.IComplexCommand; package com.incquerylabs.smarthome.eventbus.ruleengine.droolshomeio.tests.internal; public class EventBusMock implements IEventPublisher { static Logger logger = LoggerFactory.getLogger(EventBusMock.class); Map<Item, LinkedList<Command>> commands = new HashMap<Item, LinkedList<Command>>(); Map<String, Item> items = new HashMap<String, Item>();
private ConcurrentHashMap<String, IComplexCommand> complexCommands = new ConcurrentHashMap<String, IComplexCommand>();
IncQueryLabs/smarthome-cep-demonstrator
demo/com.incquerylabs.smarthome.demorules.homeio/src/main/java/com/incquerylabs/smarthome/demorules/homeio/RuleLoader.java
// Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/DrlConfiguration.java // public class DrlConfiguration { // protected final InputStream drl; // protected final String path; // // public DrlConfiguration(InputStream drl, String path) { // this.drl = drl; // this.path = path; // } // // public InputStream getDrl() { // return drl; // } // // public String getPath() { // return path; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/DtableConfiguration.java // public class DtableConfiguration { // protected final InputStream dtable; // protected final String path; // // public DtableConfiguration(InputStream dtable, String path) { // this.dtable = dtable; // this.path = path; // } // // public InputStream getDtable() { // return dtable; // } // // public String getPath() { // return path; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/IRuleLoader.java // public interface IRuleLoader { // public List<DrlConfiguration> getDrls(); // public List<DtableConfiguration> getDtables(); // public List<RuleTemplateConfiguration> getRuleTemplates(); // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/RuleTemplateConfiguration.java // public class RuleTemplateConfiguration { // // Table of data // protected final InputStream templateData; // protected final String path; // protected final String worksheetName; // // //parameters where the data starts in the table // protected final int startRow; // protected final int startColumn; // // // The template data can be applied on many template rules // protected final List<DrlConfiguration> templateRules; // // public RuleTemplateConfiguration(InputStream templateData, String path, String worksheetName, int startRow, // int startColumn, List<DrlConfiguration> templateRules) { // this.templateData = templateData; // this.path = path; // this.worksheetName = worksheetName; // this.startRow = startRow; // this.startColumn = startColumn; // this.templateRules = templateRules; // } // // public InputStream getTemplateData() { // return templateData; // } // // public String getPath() { // return path; // } // // public String getWorksheetName() { // return worksheetName; // } // // public int getStartRow() { // return startRow; // } // // public int getStartColumn() { // return startColumn; // } // // public List<DrlConfiguration> getTemplateRules() { // return templateRules; // } // }
import java.io.IOException; import java.net.URL; import java.util.Collections; import java.util.LinkedList; import java.util.List; import org.osgi.framework.FrameworkUtil; import com.incquerylabs.smarthome.eventbus.api.DrlConfiguration; import com.incquerylabs.smarthome.eventbus.api.DtableConfiguration; import com.incquerylabs.smarthome.eventbus.api.IRuleLoader; import com.incquerylabs.smarthome.eventbus.api.RuleTemplateConfiguration;
package com.incquerylabs.smarthome.demorules.homeio; public class RuleLoader implements IRuleLoader { List<String> drlPaths = null; @Override
// Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/DrlConfiguration.java // public class DrlConfiguration { // protected final InputStream drl; // protected final String path; // // public DrlConfiguration(InputStream drl, String path) { // this.drl = drl; // this.path = path; // } // // public InputStream getDrl() { // return drl; // } // // public String getPath() { // return path; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/DtableConfiguration.java // public class DtableConfiguration { // protected final InputStream dtable; // protected final String path; // // public DtableConfiguration(InputStream dtable, String path) { // this.dtable = dtable; // this.path = path; // } // // public InputStream getDtable() { // return dtable; // } // // public String getPath() { // return path; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/IRuleLoader.java // public interface IRuleLoader { // public List<DrlConfiguration> getDrls(); // public List<DtableConfiguration> getDtables(); // public List<RuleTemplateConfiguration> getRuleTemplates(); // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/RuleTemplateConfiguration.java // public class RuleTemplateConfiguration { // // Table of data // protected final InputStream templateData; // protected final String path; // protected final String worksheetName; // // //parameters where the data starts in the table // protected final int startRow; // protected final int startColumn; // // // The template data can be applied on many template rules // protected final List<DrlConfiguration> templateRules; // // public RuleTemplateConfiguration(InputStream templateData, String path, String worksheetName, int startRow, // int startColumn, List<DrlConfiguration> templateRules) { // this.templateData = templateData; // this.path = path; // this.worksheetName = worksheetName; // this.startRow = startRow; // this.startColumn = startColumn; // this.templateRules = templateRules; // } // // public InputStream getTemplateData() { // return templateData; // } // // public String getPath() { // return path; // } // // public String getWorksheetName() { // return worksheetName; // } // // public int getStartRow() { // return startRow; // } // // public int getStartColumn() { // return startColumn; // } // // public List<DrlConfiguration> getTemplateRules() { // return templateRules; // } // } // Path: demo/com.incquerylabs.smarthome.demorules.homeio/src/main/java/com/incquerylabs/smarthome/demorules/homeio/RuleLoader.java import java.io.IOException; import java.net.URL; import java.util.Collections; import java.util.LinkedList; import java.util.List; import org.osgi.framework.FrameworkUtil; import com.incquerylabs.smarthome.eventbus.api.DrlConfiguration; import com.incquerylabs.smarthome.eventbus.api.DtableConfiguration; import com.incquerylabs.smarthome.eventbus.api.IRuleLoader; import com.incquerylabs.smarthome.eventbus.api.RuleTemplateConfiguration; package com.incquerylabs.smarthome.demorules.homeio; public class RuleLoader implements IRuleLoader { List<String> drlPaths = null; @Override
public List<DrlConfiguration> getDrls() {
IncQueryLabs/smarthome-cep-demonstrator
demo/com.incquerylabs.smarthome.demorules.homeio/src/main/java/com/incquerylabs/smarthome/demorules/homeio/RuleLoader.java
// Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/DrlConfiguration.java // public class DrlConfiguration { // protected final InputStream drl; // protected final String path; // // public DrlConfiguration(InputStream drl, String path) { // this.drl = drl; // this.path = path; // } // // public InputStream getDrl() { // return drl; // } // // public String getPath() { // return path; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/DtableConfiguration.java // public class DtableConfiguration { // protected final InputStream dtable; // protected final String path; // // public DtableConfiguration(InputStream dtable, String path) { // this.dtable = dtable; // this.path = path; // } // // public InputStream getDtable() { // return dtable; // } // // public String getPath() { // return path; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/IRuleLoader.java // public interface IRuleLoader { // public List<DrlConfiguration> getDrls(); // public List<DtableConfiguration> getDtables(); // public List<RuleTemplateConfiguration> getRuleTemplates(); // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/RuleTemplateConfiguration.java // public class RuleTemplateConfiguration { // // Table of data // protected final InputStream templateData; // protected final String path; // protected final String worksheetName; // // //parameters where the data starts in the table // protected final int startRow; // protected final int startColumn; // // // The template data can be applied on many template rules // protected final List<DrlConfiguration> templateRules; // // public RuleTemplateConfiguration(InputStream templateData, String path, String worksheetName, int startRow, // int startColumn, List<DrlConfiguration> templateRules) { // this.templateData = templateData; // this.path = path; // this.worksheetName = worksheetName; // this.startRow = startRow; // this.startColumn = startColumn; // this.templateRules = templateRules; // } // // public InputStream getTemplateData() { // return templateData; // } // // public String getPath() { // return path; // } // // public String getWorksheetName() { // return worksheetName; // } // // public int getStartRow() { // return startRow; // } // // public int getStartColumn() { // return startColumn; // } // // public List<DrlConfiguration> getTemplateRules() { // return templateRules; // } // }
import java.io.IOException; import java.net.URL; import java.util.Collections; import java.util.LinkedList; import java.util.List; import org.osgi.framework.FrameworkUtil; import com.incquerylabs.smarthome.eventbus.api.DrlConfiguration; import com.incquerylabs.smarthome.eventbus.api.DtableConfiguration; import com.incquerylabs.smarthome.eventbus.api.IRuleLoader; import com.incquerylabs.smarthome.eventbus.api.RuleTemplateConfiguration;
package com.incquerylabs.smarthome.demorules.homeio; public class RuleLoader implements IRuleLoader { List<String> drlPaths = null; @Override public List<DrlConfiguration> getDrls() { List<DrlConfiguration> drlList = new LinkedList<DrlConfiguration>(); List<URL> urls = Collections .list(FrameworkUtil.getBundle(getClass()).findEntries("/src/main/resources/", "*.drl", true)); for (URL url : urls) { addInputStreamToList(url, drlList); } return drlList; } @Override
// Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/DrlConfiguration.java // public class DrlConfiguration { // protected final InputStream drl; // protected final String path; // // public DrlConfiguration(InputStream drl, String path) { // this.drl = drl; // this.path = path; // } // // public InputStream getDrl() { // return drl; // } // // public String getPath() { // return path; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/DtableConfiguration.java // public class DtableConfiguration { // protected final InputStream dtable; // protected final String path; // // public DtableConfiguration(InputStream dtable, String path) { // this.dtable = dtable; // this.path = path; // } // // public InputStream getDtable() { // return dtable; // } // // public String getPath() { // return path; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/IRuleLoader.java // public interface IRuleLoader { // public List<DrlConfiguration> getDrls(); // public List<DtableConfiguration> getDtables(); // public List<RuleTemplateConfiguration> getRuleTemplates(); // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/RuleTemplateConfiguration.java // public class RuleTemplateConfiguration { // // Table of data // protected final InputStream templateData; // protected final String path; // protected final String worksheetName; // // //parameters where the data starts in the table // protected final int startRow; // protected final int startColumn; // // // The template data can be applied on many template rules // protected final List<DrlConfiguration> templateRules; // // public RuleTemplateConfiguration(InputStream templateData, String path, String worksheetName, int startRow, // int startColumn, List<DrlConfiguration> templateRules) { // this.templateData = templateData; // this.path = path; // this.worksheetName = worksheetName; // this.startRow = startRow; // this.startColumn = startColumn; // this.templateRules = templateRules; // } // // public InputStream getTemplateData() { // return templateData; // } // // public String getPath() { // return path; // } // // public String getWorksheetName() { // return worksheetName; // } // // public int getStartRow() { // return startRow; // } // // public int getStartColumn() { // return startColumn; // } // // public List<DrlConfiguration> getTemplateRules() { // return templateRules; // } // } // Path: demo/com.incquerylabs.smarthome.demorules.homeio/src/main/java/com/incquerylabs/smarthome/demorules/homeio/RuleLoader.java import java.io.IOException; import java.net.URL; import java.util.Collections; import java.util.LinkedList; import java.util.List; import org.osgi.framework.FrameworkUtil; import com.incquerylabs.smarthome.eventbus.api.DrlConfiguration; import com.incquerylabs.smarthome.eventbus.api.DtableConfiguration; import com.incquerylabs.smarthome.eventbus.api.IRuleLoader; import com.incquerylabs.smarthome.eventbus.api.RuleTemplateConfiguration; package com.incquerylabs.smarthome.demorules.homeio; public class RuleLoader implements IRuleLoader { List<String> drlPaths = null; @Override public List<DrlConfiguration> getDrls() { List<DrlConfiguration> drlList = new LinkedList<DrlConfiguration>(); List<URL> urls = Collections .list(FrameworkUtil.getBundle(getClass()).findEntries("/src/main/resources/", "*.drl", true)); for (URL url : urls) { addInputStreamToList(url, drlList); } return drlList; } @Override
public List<DtableConfiguration> getDtables() {
IncQueryLabs/smarthome-cep-demonstrator
demo/com.incquerylabs.smarthome.demorules.homeio/src/main/java/com/incquerylabs/smarthome/demorules/homeio/RuleLoader.java
// Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/DrlConfiguration.java // public class DrlConfiguration { // protected final InputStream drl; // protected final String path; // // public DrlConfiguration(InputStream drl, String path) { // this.drl = drl; // this.path = path; // } // // public InputStream getDrl() { // return drl; // } // // public String getPath() { // return path; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/DtableConfiguration.java // public class DtableConfiguration { // protected final InputStream dtable; // protected final String path; // // public DtableConfiguration(InputStream dtable, String path) { // this.dtable = dtable; // this.path = path; // } // // public InputStream getDtable() { // return dtable; // } // // public String getPath() { // return path; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/IRuleLoader.java // public interface IRuleLoader { // public List<DrlConfiguration> getDrls(); // public List<DtableConfiguration> getDtables(); // public List<RuleTemplateConfiguration> getRuleTemplates(); // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/RuleTemplateConfiguration.java // public class RuleTemplateConfiguration { // // Table of data // protected final InputStream templateData; // protected final String path; // protected final String worksheetName; // // //parameters where the data starts in the table // protected final int startRow; // protected final int startColumn; // // // The template data can be applied on many template rules // protected final List<DrlConfiguration> templateRules; // // public RuleTemplateConfiguration(InputStream templateData, String path, String worksheetName, int startRow, // int startColumn, List<DrlConfiguration> templateRules) { // this.templateData = templateData; // this.path = path; // this.worksheetName = worksheetName; // this.startRow = startRow; // this.startColumn = startColumn; // this.templateRules = templateRules; // } // // public InputStream getTemplateData() { // return templateData; // } // // public String getPath() { // return path; // } // // public String getWorksheetName() { // return worksheetName; // } // // public int getStartRow() { // return startRow; // } // // public int getStartColumn() { // return startColumn; // } // // public List<DrlConfiguration> getTemplateRules() { // return templateRules; // } // }
import java.io.IOException; import java.net.URL; import java.util.Collections; import java.util.LinkedList; import java.util.List; import org.osgi.framework.FrameworkUtil; import com.incquerylabs.smarthome.eventbus.api.DrlConfiguration; import com.incquerylabs.smarthome.eventbus.api.DtableConfiguration; import com.incquerylabs.smarthome.eventbus.api.IRuleLoader; import com.incquerylabs.smarthome.eventbus.api.RuleTemplateConfiguration;
package com.incquerylabs.smarthome.demorules.homeio; public class RuleLoader implements IRuleLoader { List<String> drlPaths = null; @Override public List<DrlConfiguration> getDrls() { List<DrlConfiguration> drlList = new LinkedList<DrlConfiguration>(); List<URL> urls = Collections .list(FrameworkUtil.getBundle(getClass()).findEntries("/src/main/resources/", "*.drl", true)); for (URL url : urls) { addInputStreamToList(url, drlList); } return drlList; } @Override public List<DtableConfiguration> getDtables() { List<DtableConfiguration> dtableList = new LinkedList<DtableConfiguration>(); List<URL> urls = Collections .list(FrameworkUtil.getBundle(getClass()).findEntries("/src/main/resources/dtables/", "*.xlsx", true)); for (URL url : urls) { try { dtableList.add(new DtableConfiguration(url.openStream(), url.getFile())); } catch (IOException e) { e.printStackTrace(); } } return dtableList; } @Override
// Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/DrlConfiguration.java // public class DrlConfiguration { // protected final InputStream drl; // protected final String path; // // public DrlConfiguration(InputStream drl, String path) { // this.drl = drl; // this.path = path; // } // // public InputStream getDrl() { // return drl; // } // // public String getPath() { // return path; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/DtableConfiguration.java // public class DtableConfiguration { // protected final InputStream dtable; // protected final String path; // // public DtableConfiguration(InputStream dtable, String path) { // this.dtable = dtable; // this.path = path; // } // // public InputStream getDtable() { // return dtable; // } // // public String getPath() { // return path; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/IRuleLoader.java // public interface IRuleLoader { // public List<DrlConfiguration> getDrls(); // public List<DtableConfiguration> getDtables(); // public List<RuleTemplateConfiguration> getRuleTemplates(); // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/RuleTemplateConfiguration.java // public class RuleTemplateConfiguration { // // Table of data // protected final InputStream templateData; // protected final String path; // protected final String worksheetName; // // //parameters where the data starts in the table // protected final int startRow; // protected final int startColumn; // // // The template data can be applied on many template rules // protected final List<DrlConfiguration> templateRules; // // public RuleTemplateConfiguration(InputStream templateData, String path, String worksheetName, int startRow, // int startColumn, List<DrlConfiguration> templateRules) { // this.templateData = templateData; // this.path = path; // this.worksheetName = worksheetName; // this.startRow = startRow; // this.startColumn = startColumn; // this.templateRules = templateRules; // } // // public InputStream getTemplateData() { // return templateData; // } // // public String getPath() { // return path; // } // // public String getWorksheetName() { // return worksheetName; // } // // public int getStartRow() { // return startRow; // } // // public int getStartColumn() { // return startColumn; // } // // public List<DrlConfiguration> getTemplateRules() { // return templateRules; // } // } // Path: demo/com.incquerylabs.smarthome.demorules.homeio/src/main/java/com/incquerylabs/smarthome/demorules/homeio/RuleLoader.java import java.io.IOException; import java.net.URL; import java.util.Collections; import java.util.LinkedList; import java.util.List; import org.osgi.framework.FrameworkUtil; import com.incquerylabs.smarthome.eventbus.api.DrlConfiguration; import com.incquerylabs.smarthome.eventbus.api.DtableConfiguration; import com.incquerylabs.smarthome.eventbus.api.IRuleLoader; import com.incquerylabs.smarthome.eventbus.api.RuleTemplateConfiguration; package com.incquerylabs.smarthome.demorules.homeio; public class RuleLoader implements IRuleLoader { List<String> drlPaths = null; @Override public List<DrlConfiguration> getDrls() { List<DrlConfiguration> drlList = new LinkedList<DrlConfiguration>(); List<URL> urls = Collections .list(FrameworkUtil.getBundle(getClass()).findEntries("/src/main/resources/", "*.drl", true)); for (URL url : urls) { addInputStreamToList(url, drlList); } return drlList; } @Override public List<DtableConfiguration> getDtables() { List<DtableConfiguration> dtableList = new LinkedList<DtableConfiguration>(); List<URL> urls = Collections .list(FrameworkUtil.getBundle(getClass()).findEntries("/src/main/resources/dtables/", "*.xlsx", true)); for (URL url : urls) { try { dtableList.add(new DtableConfiguration(url.openStream(), url.getFile())); } catch (IOException e) { e.printStackTrace(); } } return dtableList; } @Override
public List<RuleTemplateConfiguration> getRuleTemplates() {
IncQueryLabs/smarthome-cep-demonstrator
runtime/com.incquerylabs.smarthome.eventbus.service/src/main/java/com/incquerylabs/smarthome/eventbus/service/internal/EventBusHandlerFactory.java
// Path: runtime/com.incquerylabs.smarthome.eventbus.service/src/main/java/com/incquerylabs/smarthome/eventbus/service/EventBusBindingConstants.java // public static final ThingTypeUID THING_TYPE_SAMPLE = new ThingTypeUID(BINDING_ID, "sample"); // // Path: runtime/com.incquerylabs.smarthome.eventbus.service/src/main/java/com/incquerylabs/smarthome/eventbus/service/handler/EventBusHandler.java // public class EventBusHandler extends BaseThingHandler { // // @SuppressWarnings("unused") // private final Logger logger = LoggerFactory.getLogger(EventBusHandler.class); // // public EventBusHandler(@NonNull Thing thing) { // super(thing); // } // // @Override // public void handleCommand(ChannelUID channelUID, Command command) { // if (channelUID.getId().equals(CHANNEL_1)) { // // TODO: handle command // // // Note: if communication with thing fails for some reason, // // indicate that by setting the status with detail information // // updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, // // "Could not control device at IP address x.x.x.x"); // } // } // // @Override // public void initialize() { // // TODO: Initialize the thing. If done set status to ONLINE to indicate proper working. // // Long running initialization should be done asynchronously in background. // updateStatus(ThingStatus.ONLINE); // // // Note: When initialization can NOT be done set the status with more details for further // // analysis. See also class ThingStatusDetail for all available status details. // // Add a description to give user information to understand why thing does not work // // as expected. E.g. // // updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, // // "Can not access device as username and/or password are invalid"); // } // }
import static com.incquerylabs.smarthome.eventbus.service.EventBusBindingConstants.THING_TYPE_SAMPLE; import java.util.Collections; import java.util.Set; import org.eclipse.smarthome.core.thing.Thing; import org.eclipse.smarthome.core.thing.ThingTypeUID; import org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory; import org.eclipse.smarthome.core.thing.binding.ThingHandler; import com.incquerylabs.smarthome.eventbus.service.handler.EventBusHandler;
/** * Copyright (c) 2010-2017 by the respective copyright holders. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ package com.incquerylabs.smarthome.eventbus.service.internal; /** * The {@link EventBusHandlerFactory} is responsible for creating things and thing * handlers. * * @author dandrid - Initial contribution */ public class EventBusHandlerFactory extends BaseThingHandlerFactory { private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_SAMPLE); @Override public boolean supportsThingType(ThingTypeUID thingTypeUID) { return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID); } @Override protected ThingHandler createHandler(Thing thing) { ThingTypeUID thingTypeUID = thing.getThingTypeUID(); if (thingTypeUID.equals(THING_TYPE_SAMPLE)) {
// Path: runtime/com.incquerylabs.smarthome.eventbus.service/src/main/java/com/incquerylabs/smarthome/eventbus/service/EventBusBindingConstants.java // public static final ThingTypeUID THING_TYPE_SAMPLE = new ThingTypeUID(BINDING_ID, "sample"); // // Path: runtime/com.incquerylabs.smarthome.eventbus.service/src/main/java/com/incquerylabs/smarthome/eventbus/service/handler/EventBusHandler.java // public class EventBusHandler extends BaseThingHandler { // // @SuppressWarnings("unused") // private final Logger logger = LoggerFactory.getLogger(EventBusHandler.class); // // public EventBusHandler(@NonNull Thing thing) { // super(thing); // } // // @Override // public void handleCommand(ChannelUID channelUID, Command command) { // if (channelUID.getId().equals(CHANNEL_1)) { // // TODO: handle command // // // Note: if communication with thing fails for some reason, // // indicate that by setting the status with detail information // // updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, // // "Could not control device at IP address x.x.x.x"); // } // } // // @Override // public void initialize() { // // TODO: Initialize the thing. If done set status to ONLINE to indicate proper working. // // Long running initialization should be done asynchronously in background. // updateStatus(ThingStatus.ONLINE); // // // Note: When initialization can NOT be done set the status with more details for further // // analysis. See also class ThingStatusDetail for all available status details. // // Add a description to give user information to understand why thing does not work // // as expected. E.g. // // updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, // // "Can not access device as username and/or password are invalid"); // } // } // Path: runtime/com.incquerylabs.smarthome.eventbus.service/src/main/java/com/incquerylabs/smarthome/eventbus/service/internal/EventBusHandlerFactory.java import static com.incquerylabs.smarthome.eventbus.service.EventBusBindingConstants.THING_TYPE_SAMPLE; import java.util.Collections; import java.util.Set; import org.eclipse.smarthome.core.thing.Thing; import org.eclipse.smarthome.core.thing.ThingTypeUID; import org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory; import org.eclipse.smarthome.core.thing.binding.ThingHandler; import com.incquerylabs.smarthome.eventbus.service.handler.EventBusHandler; /** * Copyright (c) 2010-2017 by the respective copyright holders. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ package com.incquerylabs.smarthome.eventbus.service.internal; /** * The {@link EventBusHandlerFactory} is responsible for creating things and thing * handlers. * * @author dandrid - Initial contribution */ public class EventBusHandlerFactory extends BaseThingHandlerFactory { private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_SAMPLE); @Override public boolean supportsThingType(ThingTypeUID thingTypeUID) { return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID); } @Override protected ThingHandler createHandler(Thing thing) { ThingTypeUID thingTypeUID = thing.getThingTypeUID(); if (thingTypeUID.equals(THING_TYPE_SAMPLE)) {
return new EventBusHandler(thing);
IncQueryLabs/smarthome-cep-demonstrator
runtime/com.incquerylabs.smarthome.eventbus.service/src/main/java/com/incquerylabs/smarthome/eventbus/service/internal/EventBusImpl.java
// Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/IEventSubscriber.java // public interface IEventSubscriber { // public void stateUpdated(ItemStateEvent event); // // public void stateChanged(ItemStateChangedEvent event); // // public void groupStateChanged(GroupItemStateChangedEvent event); // // public void commandReceived(ItemCommandEvent event); // // public void initItems(Collection<Item> items); // // public void itemAdded(ItemAddedEvent event); // // public void itemRemoved(ItemRemovedEvent event); // // public void itemUpdated(ItemUpdatedEvent event); // // public String getSubscriberName(); // }
import java.util.HashSet; import java.util.LinkedList; import java.util.Set; import org.eclipse.smarthome.core.events.Event; import org.eclipse.smarthome.core.events.EventFilter; import org.eclipse.smarthome.core.items.Item; import org.eclipse.smarthome.core.items.ItemNotFoundException; import org.eclipse.smarthome.core.items.ItemRegistry; import org.eclipse.smarthome.core.items.events.GroupItemStateChangedEvent; import org.eclipse.smarthome.core.items.events.ItemAddedEvent; import org.eclipse.smarthome.core.items.events.ItemCommandEvent; import org.eclipse.smarthome.core.items.events.ItemRemovedEvent; import org.eclipse.smarthome.core.items.events.ItemStateChangedEvent; import org.eclipse.smarthome.core.items.events.ItemStateEvent; import org.eclipse.smarthome.core.items.events.ItemUpdatedEvent; import org.eclipse.smarthome.core.types.Command; import org.eclipse.smarthome.core.types.State; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.incquerylabs.smarthome.eventbus.api.IEventSubscriber;
package com.incquerylabs.smarthome.eventbus.service.internal; public class EventBusImpl implements org.eclipse.smarthome.core.events.EventSubscriber { private class EventSubscriberStruct {
// Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/IEventSubscriber.java // public interface IEventSubscriber { // public void stateUpdated(ItemStateEvent event); // // public void stateChanged(ItemStateChangedEvent event); // // public void groupStateChanged(GroupItemStateChangedEvent event); // // public void commandReceived(ItemCommandEvent event); // // public void initItems(Collection<Item> items); // // public void itemAdded(ItemAddedEvent event); // // public void itemRemoved(ItemRemovedEvent event); // // public void itemUpdated(ItemUpdatedEvent event); // // public String getSubscriberName(); // } // Path: runtime/com.incquerylabs.smarthome.eventbus.service/src/main/java/com/incquerylabs/smarthome/eventbus/service/internal/EventBusImpl.java import java.util.HashSet; import java.util.LinkedList; import java.util.Set; import org.eclipse.smarthome.core.events.Event; import org.eclipse.smarthome.core.events.EventFilter; import org.eclipse.smarthome.core.items.Item; import org.eclipse.smarthome.core.items.ItemNotFoundException; import org.eclipse.smarthome.core.items.ItemRegistry; import org.eclipse.smarthome.core.items.events.GroupItemStateChangedEvent; import org.eclipse.smarthome.core.items.events.ItemAddedEvent; import org.eclipse.smarthome.core.items.events.ItemCommandEvent; import org.eclipse.smarthome.core.items.events.ItemRemovedEvent; import org.eclipse.smarthome.core.items.events.ItemStateChangedEvent; import org.eclipse.smarthome.core.items.events.ItemStateEvent; import org.eclipse.smarthome.core.items.events.ItemUpdatedEvent; import org.eclipse.smarthome.core.types.Command; import org.eclipse.smarthome.core.types.State; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.incquerylabs.smarthome.eventbus.api.IEventSubscriber; package com.incquerylabs.smarthome.eventbus.service.internal; public class EventBusImpl implements org.eclipse.smarthome.core.events.EventSubscriber { private class EventSubscriberStruct {
IEventSubscriber eventSubscriber;
IncQueryLabs/smarthome-cep-demonstrator
runtime/com.incquerylabs.smarthome.eventbus.service/src/main/java/com/incquerylabs/smarthome/eventbus/service/internal/EventBusPublisher.java
// Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/IEventPublisher.java // public interface IEventPublisher { // public void postCommand(String itemName, Command command); // // public void postCommand(Item item, Command command); // // public void startComplexCommand(IComplexCommand complexCommand); // // public void stopComplexCommand(String itemName); // // public void stopComplexCommand(Item item); // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/IComplexCommand.java // public interface IComplexCommand { // // public void start(IEventPublisher publisher); // // public void stop(); // // public String getItemName(); // }
import java.util.concurrent.ConcurrentHashMap; import org.eclipse.smarthome.core.items.Item; import org.eclipse.smarthome.core.items.events.ItemEventFactory; import org.eclipse.smarthome.core.types.Command; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.incquerylabs.smarthome.eventbus.api.IEventPublisher; import com.incquerylabs.smarthome.eventbus.api.IComplexCommand;
package com.incquerylabs.smarthome.eventbus.service.internal; public class EventBusPublisher implements IEventPublisher { static Logger logger = LoggerFactory.getLogger(EventBusPublisher.class); private org.eclipse.smarthome.core.events.EventPublisher eventPublisher;
// Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/IEventPublisher.java // public interface IEventPublisher { // public void postCommand(String itemName, Command command); // // public void postCommand(Item item, Command command); // // public void startComplexCommand(IComplexCommand complexCommand); // // public void stopComplexCommand(String itemName); // // public void stopComplexCommand(Item item); // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/IComplexCommand.java // public interface IComplexCommand { // // public void start(IEventPublisher publisher); // // public void stop(); // // public String getItemName(); // } // Path: runtime/com.incquerylabs.smarthome.eventbus.service/src/main/java/com/incquerylabs/smarthome/eventbus/service/internal/EventBusPublisher.java import java.util.concurrent.ConcurrentHashMap; import org.eclipse.smarthome.core.items.Item; import org.eclipse.smarthome.core.items.events.ItemEventFactory; import org.eclipse.smarthome.core.types.Command; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.incquerylabs.smarthome.eventbus.api.IEventPublisher; import com.incquerylabs.smarthome.eventbus.api.IComplexCommand; package com.incquerylabs.smarthome.eventbus.service.internal; public class EventBusPublisher implements IEventPublisher { static Logger logger = LoggerFactory.getLogger(EventBusPublisher.class); private org.eclipse.smarthome.core.events.EventPublisher eventPublisher;
private ConcurrentHashMap<String, IComplexCommand> complexCommands = new ConcurrentHashMap<String, IComplexCommand>();
IncQueryLabs/smarthome-cep-demonstrator
demo/com.incquerylabs.smarthome.demorules.generated/src/main/java/com/incquerylabs/smarthome/model/rules/RuleLoader.java
// Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/DrlConfiguration.java // public class DrlConfiguration { // protected final InputStream drl; // protected final String path; // // public DrlConfiguration(InputStream drl, String path) { // this.drl = drl; // this.path = path; // } // // public InputStream getDrl() { // return drl; // } // // public String getPath() { // return path; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/DtableConfiguration.java // public class DtableConfiguration { // protected final InputStream dtable; // protected final String path; // // public DtableConfiguration(InputStream dtable, String path) { // this.dtable = dtable; // this.path = path; // } // // public InputStream getDtable() { // return dtable; // } // // public String getPath() { // return path; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/IRuleLoader.java // public interface IRuleLoader { // public List<DrlConfiguration> getDrls(); // public List<DtableConfiguration> getDtables(); // public List<RuleTemplateConfiguration> getRuleTemplates(); // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/RuleTemplateConfiguration.java // public class RuleTemplateConfiguration { // // Table of data // protected final InputStream templateData; // protected final String path; // protected final String worksheetName; // // //parameters where the data starts in the table // protected final int startRow; // protected final int startColumn; // // // The template data can be applied on many template rules // protected final List<DrlConfiguration> templateRules; // // public RuleTemplateConfiguration(InputStream templateData, String path, String worksheetName, int startRow, // int startColumn, List<DrlConfiguration> templateRules) { // this.templateData = templateData; // this.path = path; // this.worksheetName = worksheetName; // this.startRow = startRow; // this.startColumn = startColumn; // this.templateRules = templateRules; // } // // public InputStream getTemplateData() { // return templateData; // } // // public String getPath() { // return path; // } // // public String getWorksheetName() { // return worksheetName; // } // // public int getStartRow() { // return startRow; // } // // public int getStartColumn() { // return startColumn; // } // // public List<DrlConfiguration> getTemplateRules() { // return templateRules; // } // }
import java.io.IOException; import java.net.URL; import java.util.Collections; import java.util.Enumeration; import java.util.LinkedList; import java.util.List; import org.osgi.framework.FrameworkUtil; import com.incquerylabs.smarthome.eventbus.api.DrlConfiguration; import com.incquerylabs.smarthome.eventbus.api.DtableConfiguration; import com.incquerylabs.smarthome.eventbus.api.IRuleLoader; import com.incquerylabs.smarthome.eventbus.api.RuleTemplateConfiguration;
package com.incquerylabs.smarthome.model.rules; public class RuleLoader implements IRuleLoader { List<String> drlPaths = null; @Override
// Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/DrlConfiguration.java // public class DrlConfiguration { // protected final InputStream drl; // protected final String path; // // public DrlConfiguration(InputStream drl, String path) { // this.drl = drl; // this.path = path; // } // // public InputStream getDrl() { // return drl; // } // // public String getPath() { // return path; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/DtableConfiguration.java // public class DtableConfiguration { // protected final InputStream dtable; // protected final String path; // // public DtableConfiguration(InputStream dtable, String path) { // this.dtable = dtable; // this.path = path; // } // // public InputStream getDtable() { // return dtable; // } // // public String getPath() { // return path; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/IRuleLoader.java // public interface IRuleLoader { // public List<DrlConfiguration> getDrls(); // public List<DtableConfiguration> getDtables(); // public List<RuleTemplateConfiguration> getRuleTemplates(); // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/RuleTemplateConfiguration.java // public class RuleTemplateConfiguration { // // Table of data // protected final InputStream templateData; // protected final String path; // protected final String worksheetName; // // //parameters where the data starts in the table // protected final int startRow; // protected final int startColumn; // // // The template data can be applied on many template rules // protected final List<DrlConfiguration> templateRules; // // public RuleTemplateConfiguration(InputStream templateData, String path, String worksheetName, int startRow, // int startColumn, List<DrlConfiguration> templateRules) { // this.templateData = templateData; // this.path = path; // this.worksheetName = worksheetName; // this.startRow = startRow; // this.startColumn = startColumn; // this.templateRules = templateRules; // } // // public InputStream getTemplateData() { // return templateData; // } // // public String getPath() { // return path; // } // // public String getWorksheetName() { // return worksheetName; // } // // public int getStartRow() { // return startRow; // } // // public int getStartColumn() { // return startColumn; // } // // public List<DrlConfiguration> getTemplateRules() { // return templateRules; // } // } // Path: demo/com.incquerylabs.smarthome.demorules.generated/src/main/java/com/incquerylabs/smarthome/model/rules/RuleLoader.java import java.io.IOException; import java.net.URL; import java.util.Collections; import java.util.Enumeration; import java.util.LinkedList; import java.util.List; import org.osgi.framework.FrameworkUtil; import com.incquerylabs.smarthome.eventbus.api.DrlConfiguration; import com.incquerylabs.smarthome.eventbus.api.DtableConfiguration; import com.incquerylabs.smarthome.eventbus.api.IRuleLoader; import com.incquerylabs.smarthome.eventbus.api.RuleTemplateConfiguration; package com.incquerylabs.smarthome.model.rules; public class RuleLoader implements IRuleLoader { List<String> drlPaths = null; @Override
public List<DrlConfiguration> getDrls() {
IncQueryLabs/smarthome-cep-demonstrator
demo/com.incquerylabs.smarthome.demorules.generated/src/main/java/com/incquerylabs/smarthome/model/rules/RuleLoader.java
// Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/DrlConfiguration.java // public class DrlConfiguration { // protected final InputStream drl; // protected final String path; // // public DrlConfiguration(InputStream drl, String path) { // this.drl = drl; // this.path = path; // } // // public InputStream getDrl() { // return drl; // } // // public String getPath() { // return path; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/DtableConfiguration.java // public class DtableConfiguration { // protected final InputStream dtable; // protected final String path; // // public DtableConfiguration(InputStream dtable, String path) { // this.dtable = dtable; // this.path = path; // } // // public InputStream getDtable() { // return dtable; // } // // public String getPath() { // return path; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/IRuleLoader.java // public interface IRuleLoader { // public List<DrlConfiguration> getDrls(); // public List<DtableConfiguration> getDtables(); // public List<RuleTemplateConfiguration> getRuleTemplates(); // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/RuleTemplateConfiguration.java // public class RuleTemplateConfiguration { // // Table of data // protected final InputStream templateData; // protected final String path; // protected final String worksheetName; // // //parameters where the data starts in the table // protected final int startRow; // protected final int startColumn; // // // The template data can be applied on many template rules // protected final List<DrlConfiguration> templateRules; // // public RuleTemplateConfiguration(InputStream templateData, String path, String worksheetName, int startRow, // int startColumn, List<DrlConfiguration> templateRules) { // this.templateData = templateData; // this.path = path; // this.worksheetName = worksheetName; // this.startRow = startRow; // this.startColumn = startColumn; // this.templateRules = templateRules; // } // // public InputStream getTemplateData() { // return templateData; // } // // public String getPath() { // return path; // } // // public String getWorksheetName() { // return worksheetName; // } // // public int getStartRow() { // return startRow; // } // // public int getStartColumn() { // return startColumn; // } // // public List<DrlConfiguration> getTemplateRules() { // return templateRules; // } // }
import java.io.IOException; import java.net.URL; import java.util.Collections; import java.util.Enumeration; import java.util.LinkedList; import java.util.List; import org.osgi.framework.FrameworkUtil; import com.incquerylabs.smarthome.eventbus.api.DrlConfiguration; import com.incquerylabs.smarthome.eventbus.api.DtableConfiguration; import com.incquerylabs.smarthome.eventbus.api.IRuleLoader; import com.incquerylabs.smarthome.eventbus.api.RuleTemplateConfiguration;
package com.incquerylabs.smarthome.model.rules; public class RuleLoader implements IRuleLoader { List<String> drlPaths = null; @Override public List<DrlConfiguration> getDrls() { List<DrlConfiguration> list = new LinkedList<DrlConfiguration>(); Enumeration<URL> baseRules = FrameworkUtil.getBundle(getClass()).findEntries("/src/main/resources/base-rules", "*.drl", true); Enumeration<URL> genRules = FrameworkUtil.getBundle(getClass()).findEntries("/src/main/resources/gen-rules", "*.drl", true); if(baseRules == null) { throw new RuntimeException("Error, base-rules folder shouldn't be empty."); } if(genRules == null) { throw new RuntimeException("Error, gen-rules folder shouldn't be empty. Have you forget to generate the rules?"); } List<URL> loadedDrls = Collections.list(baseRules); loadedDrls.addAll(Collections.list(genRules)); for (URL url : loadedDrls) { addInputStreamToList(url, list); } return list; } private void addInputStreamToList(URL url, List<DrlConfiguration> list) { try { list.add(new DrlConfiguration(url.openStream(),url.getFile())); } catch (IOException e) { e.printStackTrace(); } } @Override
// Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/DrlConfiguration.java // public class DrlConfiguration { // protected final InputStream drl; // protected final String path; // // public DrlConfiguration(InputStream drl, String path) { // this.drl = drl; // this.path = path; // } // // public InputStream getDrl() { // return drl; // } // // public String getPath() { // return path; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/DtableConfiguration.java // public class DtableConfiguration { // protected final InputStream dtable; // protected final String path; // // public DtableConfiguration(InputStream dtable, String path) { // this.dtable = dtable; // this.path = path; // } // // public InputStream getDtable() { // return dtable; // } // // public String getPath() { // return path; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/IRuleLoader.java // public interface IRuleLoader { // public List<DrlConfiguration> getDrls(); // public List<DtableConfiguration> getDtables(); // public List<RuleTemplateConfiguration> getRuleTemplates(); // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/RuleTemplateConfiguration.java // public class RuleTemplateConfiguration { // // Table of data // protected final InputStream templateData; // protected final String path; // protected final String worksheetName; // // //parameters where the data starts in the table // protected final int startRow; // protected final int startColumn; // // // The template data can be applied on many template rules // protected final List<DrlConfiguration> templateRules; // // public RuleTemplateConfiguration(InputStream templateData, String path, String worksheetName, int startRow, // int startColumn, List<DrlConfiguration> templateRules) { // this.templateData = templateData; // this.path = path; // this.worksheetName = worksheetName; // this.startRow = startRow; // this.startColumn = startColumn; // this.templateRules = templateRules; // } // // public InputStream getTemplateData() { // return templateData; // } // // public String getPath() { // return path; // } // // public String getWorksheetName() { // return worksheetName; // } // // public int getStartRow() { // return startRow; // } // // public int getStartColumn() { // return startColumn; // } // // public List<DrlConfiguration> getTemplateRules() { // return templateRules; // } // } // Path: demo/com.incquerylabs.smarthome.demorules.generated/src/main/java/com/incquerylabs/smarthome/model/rules/RuleLoader.java import java.io.IOException; import java.net.URL; import java.util.Collections; import java.util.Enumeration; import java.util.LinkedList; import java.util.List; import org.osgi.framework.FrameworkUtil; import com.incquerylabs.smarthome.eventbus.api.DrlConfiguration; import com.incquerylabs.smarthome.eventbus.api.DtableConfiguration; import com.incquerylabs.smarthome.eventbus.api.IRuleLoader; import com.incquerylabs.smarthome.eventbus.api.RuleTemplateConfiguration; package com.incquerylabs.smarthome.model.rules; public class RuleLoader implements IRuleLoader { List<String> drlPaths = null; @Override public List<DrlConfiguration> getDrls() { List<DrlConfiguration> list = new LinkedList<DrlConfiguration>(); Enumeration<URL> baseRules = FrameworkUtil.getBundle(getClass()).findEntries("/src/main/resources/base-rules", "*.drl", true); Enumeration<URL> genRules = FrameworkUtil.getBundle(getClass()).findEntries("/src/main/resources/gen-rules", "*.drl", true); if(baseRules == null) { throw new RuntimeException("Error, base-rules folder shouldn't be empty."); } if(genRules == null) { throw new RuntimeException("Error, gen-rules folder shouldn't be empty. Have you forget to generate the rules?"); } List<URL> loadedDrls = Collections.list(baseRules); loadedDrls.addAll(Collections.list(genRules)); for (URL url : loadedDrls) { addInputStreamToList(url, list); } return list; } private void addInputStreamToList(URL url, List<DrlConfiguration> list) { try { list.add(new DrlConfiguration(url.openStream(),url.getFile())); } catch (IOException e) { e.printStackTrace(); } } @Override
public List<DtableConfiguration> getDtables() {
IncQueryLabs/smarthome-cep-demonstrator
demo/com.incquerylabs.smarthome.demorules.generated/src/main/java/com/incquerylabs/smarthome/model/rules/RuleLoader.java
// Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/DrlConfiguration.java // public class DrlConfiguration { // protected final InputStream drl; // protected final String path; // // public DrlConfiguration(InputStream drl, String path) { // this.drl = drl; // this.path = path; // } // // public InputStream getDrl() { // return drl; // } // // public String getPath() { // return path; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/DtableConfiguration.java // public class DtableConfiguration { // protected final InputStream dtable; // protected final String path; // // public DtableConfiguration(InputStream dtable, String path) { // this.dtable = dtable; // this.path = path; // } // // public InputStream getDtable() { // return dtable; // } // // public String getPath() { // return path; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/IRuleLoader.java // public interface IRuleLoader { // public List<DrlConfiguration> getDrls(); // public List<DtableConfiguration> getDtables(); // public List<RuleTemplateConfiguration> getRuleTemplates(); // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/RuleTemplateConfiguration.java // public class RuleTemplateConfiguration { // // Table of data // protected final InputStream templateData; // protected final String path; // protected final String worksheetName; // // //parameters where the data starts in the table // protected final int startRow; // protected final int startColumn; // // // The template data can be applied on many template rules // protected final List<DrlConfiguration> templateRules; // // public RuleTemplateConfiguration(InputStream templateData, String path, String worksheetName, int startRow, // int startColumn, List<DrlConfiguration> templateRules) { // this.templateData = templateData; // this.path = path; // this.worksheetName = worksheetName; // this.startRow = startRow; // this.startColumn = startColumn; // this.templateRules = templateRules; // } // // public InputStream getTemplateData() { // return templateData; // } // // public String getPath() { // return path; // } // // public String getWorksheetName() { // return worksheetName; // } // // public int getStartRow() { // return startRow; // } // // public int getStartColumn() { // return startColumn; // } // // public List<DrlConfiguration> getTemplateRules() { // return templateRules; // } // }
import java.io.IOException; import java.net.URL; import java.util.Collections; import java.util.Enumeration; import java.util.LinkedList; import java.util.List; import org.osgi.framework.FrameworkUtil; import com.incquerylabs.smarthome.eventbus.api.DrlConfiguration; import com.incquerylabs.smarthome.eventbus.api.DtableConfiguration; import com.incquerylabs.smarthome.eventbus.api.IRuleLoader; import com.incquerylabs.smarthome.eventbus.api.RuleTemplateConfiguration;
if(baseRules == null) { throw new RuntimeException("Error, base-rules folder shouldn't be empty."); } if(genRules == null) { throw new RuntimeException("Error, gen-rules folder shouldn't be empty. Have you forget to generate the rules?"); } List<URL> loadedDrls = Collections.list(baseRules); loadedDrls.addAll(Collections.list(genRules)); for (URL url : loadedDrls) { addInputStreamToList(url, list); } return list; } private void addInputStreamToList(URL url, List<DrlConfiguration> list) { try { list.add(new DrlConfiguration(url.openStream(),url.getFile())); } catch (IOException e) { e.printStackTrace(); } } @Override public List<DtableConfiguration> getDtables() { return null; } @Override
// Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/DrlConfiguration.java // public class DrlConfiguration { // protected final InputStream drl; // protected final String path; // // public DrlConfiguration(InputStream drl, String path) { // this.drl = drl; // this.path = path; // } // // public InputStream getDrl() { // return drl; // } // // public String getPath() { // return path; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/DtableConfiguration.java // public class DtableConfiguration { // protected final InputStream dtable; // protected final String path; // // public DtableConfiguration(InputStream dtable, String path) { // this.dtable = dtable; // this.path = path; // } // // public InputStream getDtable() { // return dtable; // } // // public String getPath() { // return path; // } // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/IRuleLoader.java // public interface IRuleLoader { // public List<DrlConfiguration> getDrls(); // public List<DtableConfiguration> getDtables(); // public List<RuleTemplateConfiguration> getRuleTemplates(); // } // // Path: runtime/com.incquerylabs.smarthome.eventbus.api/src/main/java/com/incquerylabs/smarthome/eventbus/api/RuleTemplateConfiguration.java // public class RuleTemplateConfiguration { // // Table of data // protected final InputStream templateData; // protected final String path; // protected final String worksheetName; // // //parameters where the data starts in the table // protected final int startRow; // protected final int startColumn; // // // The template data can be applied on many template rules // protected final List<DrlConfiguration> templateRules; // // public RuleTemplateConfiguration(InputStream templateData, String path, String worksheetName, int startRow, // int startColumn, List<DrlConfiguration> templateRules) { // this.templateData = templateData; // this.path = path; // this.worksheetName = worksheetName; // this.startRow = startRow; // this.startColumn = startColumn; // this.templateRules = templateRules; // } // // public InputStream getTemplateData() { // return templateData; // } // // public String getPath() { // return path; // } // // public String getWorksheetName() { // return worksheetName; // } // // public int getStartRow() { // return startRow; // } // // public int getStartColumn() { // return startColumn; // } // // public List<DrlConfiguration> getTemplateRules() { // return templateRules; // } // } // Path: demo/com.incquerylabs.smarthome.demorules.generated/src/main/java/com/incquerylabs/smarthome/model/rules/RuleLoader.java import java.io.IOException; import java.net.URL; import java.util.Collections; import java.util.Enumeration; import java.util.LinkedList; import java.util.List; import org.osgi.framework.FrameworkUtil; import com.incquerylabs.smarthome.eventbus.api.DrlConfiguration; import com.incquerylabs.smarthome.eventbus.api.DtableConfiguration; import com.incquerylabs.smarthome.eventbus.api.IRuleLoader; import com.incquerylabs.smarthome.eventbus.api.RuleTemplateConfiguration; if(baseRules == null) { throw new RuntimeException("Error, base-rules folder shouldn't be empty."); } if(genRules == null) { throw new RuntimeException("Error, gen-rules folder shouldn't be empty. Have you forget to generate the rules?"); } List<URL> loadedDrls = Collections.list(baseRules); loadedDrls.addAll(Collections.list(genRules)); for (URL url : loadedDrls) { addInputStreamToList(url, list); } return list; } private void addInputStreamToList(URL url, List<DrlConfiguration> list) { try { list.add(new DrlConfiguration(url.openStream(),url.getFile())); } catch (IOException e) { e.printStackTrace(); } } @Override public List<DtableConfiguration> getDtables() { return null; } @Override
public List<RuleTemplateConfiguration> getRuleTemplates() {
CypherCove/gdx-cclibs
examples/android/src/com/cyphercove/gdx/flexbatch/examples/AndroidLauncher.java
// Path: examples/core/src/com/cyphercove/gdx/ExampleRunner.java // public class ExampleRunner extends Game { // // public static final Array<Class<? extends Example>> examples = new Array<Class<? extends Example>>(); // static { // examples.add(AssignmentAssetManagerTest.class); // examples.add(FlexBatchTest.class); // } // // SpriteBatch spriteBatch; // Stage stage; // Skin skin; // SelectBox<Class<? extends Example>> selectBox; // String[] arg; // // public ExampleRunner (String[] arg){ // this.arg = arg; // } // // @Override // public void create() { // spriteBatch = new SpriteBatch(); // stage = new Stage(new ScreenViewport()); // skin = new Skin(Gdx.files.internal("uiskin.json")); // Table table = new Table(skin); // table.setFillParent(true); // selectBox = new SelectBox<Class<? extends Example>>(skin){ // protected String toString (Class<? extends Example> obj) { // return obj.getSimpleName(); // } // }; // selectBox.setItems(examples); // table.add(selectBox).fillX().space(20).row(); // stage.addActor(table); // TextButton startButton = new TextButton("Start example", skin); // startButton.addListener(new ChangeListener() { // @Override // public void changed(ChangeEvent event, Actor actor) { // runSelectedExample(); // } // }); // table.add(startButton).fillX(); // // if (arg != null && arg.length > 0) { // Class<? extends Example> specifiedExample = getExample(arg[0]); // if (specifiedExample != null){ // startExample(specifiedExample); // return; // } // } // // setScreen(menuScreen); // } // // @Override // public void render (){ // if (getScreen() instanceof Example && Gdx.input.isKeyJustPressed(Input.Keys.BACKSPACE)) // exitCurrentExample(); // super.render(); // } // // private Class<? extends Example> getExample (String simpleName){ // for (Class<? extends Example> example : examples){ // if (example.getSimpleName().equals(simpleName)) // return example; // } // return null; // } // // private void runSelectedExample (){ // Class<? extends Example> exampleClass = selectBox.getSelected(); // if (exampleClass == null) // return; // startExample(exampleClass); // } // // private void startExample (Class<? extends Example> exampleClass){ // try { // Example example = exampleClass.newInstance(); // setScreen(example); // } catch (InstantiationException e) { // e.printStackTrace(); // } catch (IllegalAccessException e) { // e.printStackTrace(); // } // } // // public void exitCurrentExample (){ // Screen exitedScreen = getScreen(); // setScreen(menuScreen); // if (exitedScreen != null) // exitedScreen.dispose(); // selectBox.setSelected(((Example)exitedScreen).getClass()); // } // // @Override // public void dispose (){ // Screen exitedScreen = getScreen(); // if (exitedScreen != null) // exitedScreen.dispose(); // setScreen(null); // spriteBatch.dispose(); // skin.dispose(); // } // // private Screen menuScreen = new Screen() { // @Override // public void show() { // Gdx.input.setInputProcessor(stage); // } // // @Override // public void render(float delta) { // Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); // stage.act(); // stage.draw(); // if (Gdx.input.isKeyJustPressed(Input.Keys.ENTER)) // runSelectedExample(); // if (Gdx.input.isKeyJustPressed(Input.Keys.UP)) // selectBox.setSelectedIndex((selectBox.getSelectedIndex() + examples.size - 1) % examples.size); // if (Gdx.input.isKeyJustPressed(Input.Keys.DOWN)) // selectBox.setSelectedIndex((selectBox.getSelectedIndex() + 1) % examples.size); // } // // @Override // public void resize(int width, int height) { // stage.getViewport().update(width, height, true); // } // // @Override // public void pause() { // // } // // @Override // public void resume() { // // } // // @Override // public void hide() { // // } // // @Override // public void dispose() { // // } // }; // }
import android.os.Bundle; import com.badlogic.gdx.backends.android.AndroidApplication; import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration; import com.cyphercove.gdx.ExampleRunner;
/******************************************************************************* * Copyright 2017 See AUTHORS file. * * 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.cyphercove.gdx.flexbatch.examples; public class AndroidLauncher extends AndroidApplication { @Override protected void onCreate (Bundle savedInstanceState) { super.onCreate(savedInstanceState); AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
// Path: examples/core/src/com/cyphercove/gdx/ExampleRunner.java // public class ExampleRunner extends Game { // // public static final Array<Class<? extends Example>> examples = new Array<Class<? extends Example>>(); // static { // examples.add(AssignmentAssetManagerTest.class); // examples.add(FlexBatchTest.class); // } // // SpriteBatch spriteBatch; // Stage stage; // Skin skin; // SelectBox<Class<? extends Example>> selectBox; // String[] arg; // // public ExampleRunner (String[] arg){ // this.arg = arg; // } // // @Override // public void create() { // spriteBatch = new SpriteBatch(); // stage = new Stage(new ScreenViewport()); // skin = new Skin(Gdx.files.internal("uiskin.json")); // Table table = new Table(skin); // table.setFillParent(true); // selectBox = new SelectBox<Class<? extends Example>>(skin){ // protected String toString (Class<? extends Example> obj) { // return obj.getSimpleName(); // } // }; // selectBox.setItems(examples); // table.add(selectBox).fillX().space(20).row(); // stage.addActor(table); // TextButton startButton = new TextButton("Start example", skin); // startButton.addListener(new ChangeListener() { // @Override // public void changed(ChangeEvent event, Actor actor) { // runSelectedExample(); // } // }); // table.add(startButton).fillX(); // // if (arg != null && arg.length > 0) { // Class<? extends Example> specifiedExample = getExample(arg[0]); // if (specifiedExample != null){ // startExample(specifiedExample); // return; // } // } // // setScreen(menuScreen); // } // // @Override // public void render (){ // if (getScreen() instanceof Example && Gdx.input.isKeyJustPressed(Input.Keys.BACKSPACE)) // exitCurrentExample(); // super.render(); // } // // private Class<? extends Example> getExample (String simpleName){ // for (Class<? extends Example> example : examples){ // if (example.getSimpleName().equals(simpleName)) // return example; // } // return null; // } // // private void runSelectedExample (){ // Class<? extends Example> exampleClass = selectBox.getSelected(); // if (exampleClass == null) // return; // startExample(exampleClass); // } // // private void startExample (Class<? extends Example> exampleClass){ // try { // Example example = exampleClass.newInstance(); // setScreen(example); // } catch (InstantiationException e) { // e.printStackTrace(); // } catch (IllegalAccessException e) { // e.printStackTrace(); // } // } // // public void exitCurrentExample (){ // Screen exitedScreen = getScreen(); // setScreen(menuScreen); // if (exitedScreen != null) // exitedScreen.dispose(); // selectBox.setSelected(((Example)exitedScreen).getClass()); // } // // @Override // public void dispose (){ // Screen exitedScreen = getScreen(); // if (exitedScreen != null) // exitedScreen.dispose(); // setScreen(null); // spriteBatch.dispose(); // skin.dispose(); // } // // private Screen menuScreen = new Screen() { // @Override // public void show() { // Gdx.input.setInputProcessor(stage); // } // // @Override // public void render(float delta) { // Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); // stage.act(); // stage.draw(); // if (Gdx.input.isKeyJustPressed(Input.Keys.ENTER)) // runSelectedExample(); // if (Gdx.input.isKeyJustPressed(Input.Keys.UP)) // selectBox.setSelectedIndex((selectBox.getSelectedIndex() + examples.size - 1) % examples.size); // if (Gdx.input.isKeyJustPressed(Input.Keys.DOWN)) // selectBox.setSelectedIndex((selectBox.getSelectedIndex() + 1) % examples.size); // } // // @Override // public void resize(int width, int height) { // stage.getViewport().update(width, height, true); // } // // @Override // public void pause() { // // } // // @Override // public void resume() { // // } // // @Override // public void hide() { // // } // // @Override // public void dispose() { // // } // }; // } // Path: examples/android/src/com/cyphercove/gdx/flexbatch/examples/AndroidLauncher.java import android.os.Bundle; import com.badlogic.gdx.backends.android.AndroidApplication; import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration; import com.cyphercove.gdx.ExampleRunner; /******************************************************************************* * Copyright 2017 See AUTHORS file. * * 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.cyphercove.gdx.flexbatch.examples; public class AndroidLauncher extends AndroidApplication { @Override protected void onCreate (Bundle savedInstanceState) { super.onCreate(savedInstanceState); AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
initialize(new ExampleRunner(null), config);
CypherCove/gdx-cclibs
examples/html/src/com/cyphercove/gdx/examples/client/HtmlLauncher.java
// Path: examples/core/src/com/cyphercove/gdx/ExampleRunner.java // public class ExampleRunner extends Game { // // public static final Array<Class<? extends Example>> examples = new Array<Class<? extends Example>>(); // static { // examples.add(AssignmentAssetManagerTest.class); // examples.add(FlexBatchTest.class); // } // // SpriteBatch spriteBatch; // Stage stage; // Skin skin; // SelectBox<Class<? extends Example>> selectBox; // String[] arg; // // public ExampleRunner (String[] arg){ // this.arg = arg; // } // // @Override // public void create() { // spriteBatch = new SpriteBatch(); // stage = new Stage(new ScreenViewport()); // skin = new Skin(Gdx.files.internal("uiskin.json")); // Table table = new Table(skin); // table.setFillParent(true); // selectBox = new SelectBox<Class<? extends Example>>(skin){ // protected String toString (Class<? extends Example> obj) { // return obj.getSimpleName(); // } // }; // selectBox.setItems(examples); // table.add(selectBox).fillX().space(20).row(); // stage.addActor(table); // TextButton startButton = new TextButton("Start example", skin); // startButton.addListener(new ChangeListener() { // @Override // public void changed(ChangeEvent event, Actor actor) { // runSelectedExample(); // } // }); // table.add(startButton).fillX(); // // if (arg != null && arg.length > 0) { // Class<? extends Example> specifiedExample = getExample(arg[0]); // if (specifiedExample != null){ // startExample(specifiedExample); // return; // } // } // // setScreen(menuScreen); // } // // @Override // public void render (){ // if (getScreen() instanceof Example && Gdx.input.isKeyJustPressed(Input.Keys.BACKSPACE)) // exitCurrentExample(); // super.render(); // } // // private Class<? extends Example> getExample (String simpleName){ // for (Class<? extends Example> example : examples){ // if (example.getSimpleName().equals(simpleName)) // return example; // } // return null; // } // // private void runSelectedExample (){ // Class<? extends Example> exampleClass = selectBox.getSelected(); // if (exampleClass == null) // return; // startExample(exampleClass); // } // // private void startExample (Class<? extends Example> exampleClass){ // try { // Example example = exampleClass.newInstance(); // setScreen(example); // } catch (InstantiationException e) { // e.printStackTrace(); // } catch (IllegalAccessException e) { // e.printStackTrace(); // } // } // // public void exitCurrentExample (){ // Screen exitedScreen = getScreen(); // setScreen(menuScreen); // if (exitedScreen != null) // exitedScreen.dispose(); // selectBox.setSelected(((Example)exitedScreen).getClass()); // } // // @Override // public void dispose (){ // Screen exitedScreen = getScreen(); // if (exitedScreen != null) // exitedScreen.dispose(); // setScreen(null); // spriteBatch.dispose(); // skin.dispose(); // } // // private Screen menuScreen = new Screen() { // @Override // public void show() { // Gdx.input.setInputProcessor(stage); // } // // @Override // public void render(float delta) { // Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); // stage.act(); // stage.draw(); // if (Gdx.input.isKeyJustPressed(Input.Keys.ENTER)) // runSelectedExample(); // if (Gdx.input.isKeyJustPressed(Input.Keys.UP)) // selectBox.setSelectedIndex((selectBox.getSelectedIndex() + examples.size - 1) % examples.size); // if (Gdx.input.isKeyJustPressed(Input.Keys.DOWN)) // selectBox.setSelectedIndex((selectBox.getSelectedIndex() + 1) % examples.size); // } // // @Override // public void resize(int width, int height) { // stage.getViewport().update(width, height, true); // } // // @Override // public void pause() { // // } // // @Override // public void resume() { // // } // // @Override // public void hide() { // // } // // @Override // public void dispose() { // // } // }; // }
import com.badlogic.gdx.ApplicationListener; import com.badlogic.gdx.backends.gwt.GwtApplication; import com.badlogic.gdx.backends.gwt.GwtApplicationConfiguration; import com.cyphercove.gdx.ExampleRunner;
/******************************************************************************* * Copyright 2017 See AUTHORS file. * * 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.cyphercove.gdx.examples.client; public class HtmlLauncher extends GwtApplication { @Override public GwtApplicationConfiguration getConfig () { return new GwtApplicationConfiguration(480, 320); } @Override public ApplicationListener createApplicationListener () {
// Path: examples/core/src/com/cyphercove/gdx/ExampleRunner.java // public class ExampleRunner extends Game { // // public static final Array<Class<? extends Example>> examples = new Array<Class<? extends Example>>(); // static { // examples.add(AssignmentAssetManagerTest.class); // examples.add(FlexBatchTest.class); // } // // SpriteBatch spriteBatch; // Stage stage; // Skin skin; // SelectBox<Class<? extends Example>> selectBox; // String[] arg; // // public ExampleRunner (String[] arg){ // this.arg = arg; // } // // @Override // public void create() { // spriteBatch = new SpriteBatch(); // stage = new Stage(new ScreenViewport()); // skin = new Skin(Gdx.files.internal("uiskin.json")); // Table table = new Table(skin); // table.setFillParent(true); // selectBox = new SelectBox<Class<? extends Example>>(skin){ // protected String toString (Class<? extends Example> obj) { // return obj.getSimpleName(); // } // }; // selectBox.setItems(examples); // table.add(selectBox).fillX().space(20).row(); // stage.addActor(table); // TextButton startButton = new TextButton("Start example", skin); // startButton.addListener(new ChangeListener() { // @Override // public void changed(ChangeEvent event, Actor actor) { // runSelectedExample(); // } // }); // table.add(startButton).fillX(); // // if (arg != null && arg.length > 0) { // Class<? extends Example> specifiedExample = getExample(arg[0]); // if (specifiedExample != null){ // startExample(specifiedExample); // return; // } // } // // setScreen(menuScreen); // } // // @Override // public void render (){ // if (getScreen() instanceof Example && Gdx.input.isKeyJustPressed(Input.Keys.BACKSPACE)) // exitCurrentExample(); // super.render(); // } // // private Class<? extends Example> getExample (String simpleName){ // for (Class<? extends Example> example : examples){ // if (example.getSimpleName().equals(simpleName)) // return example; // } // return null; // } // // private void runSelectedExample (){ // Class<? extends Example> exampleClass = selectBox.getSelected(); // if (exampleClass == null) // return; // startExample(exampleClass); // } // // private void startExample (Class<? extends Example> exampleClass){ // try { // Example example = exampleClass.newInstance(); // setScreen(example); // } catch (InstantiationException e) { // e.printStackTrace(); // } catch (IllegalAccessException e) { // e.printStackTrace(); // } // } // // public void exitCurrentExample (){ // Screen exitedScreen = getScreen(); // setScreen(menuScreen); // if (exitedScreen != null) // exitedScreen.dispose(); // selectBox.setSelected(((Example)exitedScreen).getClass()); // } // // @Override // public void dispose (){ // Screen exitedScreen = getScreen(); // if (exitedScreen != null) // exitedScreen.dispose(); // setScreen(null); // spriteBatch.dispose(); // skin.dispose(); // } // // private Screen menuScreen = new Screen() { // @Override // public void show() { // Gdx.input.setInputProcessor(stage); // } // // @Override // public void render(float delta) { // Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); // stage.act(); // stage.draw(); // if (Gdx.input.isKeyJustPressed(Input.Keys.ENTER)) // runSelectedExample(); // if (Gdx.input.isKeyJustPressed(Input.Keys.UP)) // selectBox.setSelectedIndex((selectBox.getSelectedIndex() + examples.size - 1) % examples.size); // if (Gdx.input.isKeyJustPressed(Input.Keys.DOWN)) // selectBox.setSelectedIndex((selectBox.getSelectedIndex() + 1) % examples.size); // } // // @Override // public void resize(int width, int height) { // stage.getViewport().update(width, height, true); // } // // @Override // public void pause() { // // } // // @Override // public void resume() { // // } // // @Override // public void hide() { // // } // // @Override // public void dispose() { // // } // }; // } // Path: examples/html/src/com/cyphercove/gdx/examples/client/HtmlLauncher.java import com.badlogic.gdx.ApplicationListener; import com.badlogic.gdx.backends.gwt.GwtApplication; import com.badlogic.gdx.backends.gwt.GwtApplicationConfiguration; import com.cyphercove.gdx.ExampleRunner; /******************************************************************************* * Copyright 2017 See AUTHORS file. * * 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.cyphercove.gdx.examples.client; public class HtmlLauncher extends GwtApplication { @Override public GwtApplicationConfiguration getConfig () { return new GwtApplicationConfiguration(480, 320); } @Override public ApplicationListener createApplicationListener () {
return new ExampleRunner(null);
CypherCove/gdx-cclibs
examples/desktop/src/com/cyphercove/gdx/flexbatch/examples/desktop/DesktopLauncher.java
// Path: examples/core/src/com/cyphercove/gdx/ExampleRunner.java // public class ExampleRunner extends Game { // // public static final Array<Class<? extends Example>> examples = new Array<Class<? extends Example>>(); // static { // examples.add(AssignmentAssetManagerTest.class); // examples.add(FlexBatchTest.class); // } // // SpriteBatch spriteBatch; // Stage stage; // Skin skin; // SelectBox<Class<? extends Example>> selectBox; // String[] arg; // // public ExampleRunner (String[] arg){ // this.arg = arg; // } // // @Override // public void create() { // spriteBatch = new SpriteBatch(); // stage = new Stage(new ScreenViewport()); // skin = new Skin(Gdx.files.internal("uiskin.json")); // Table table = new Table(skin); // table.setFillParent(true); // selectBox = new SelectBox<Class<? extends Example>>(skin){ // protected String toString (Class<? extends Example> obj) { // return obj.getSimpleName(); // } // }; // selectBox.setItems(examples); // table.add(selectBox).fillX().space(20).row(); // stage.addActor(table); // TextButton startButton = new TextButton("Start example", skin); // startButton.addListener(new ChangeListener() { // @Override // public void changed(ChangeEvent event, Actor actor) { // runSelectedExample(); // } // }); // table.add(startButton).fillX(); // // if (arg != null && arg.length > 0) { // Class<? extends Example> specifiedExample = getExample(arg[0]); // if (specifiedExample != null){ // startExample(specifiedExample); // return; // } // } // // setScreen(menuScreen); // } // // @Override // public void render (){ // if (getScreen() instanceof Example && Gdx.input.isKeyJustPressed(Input.Keys.BACKSPACE)) // exitCurrentExample(); // super.render(); // } // // private Class<? extends Example> getExample (String simpleName){ // for (Class<? extends Example> example : examples){ // if (example.getSimpleName().equals(simpleName)) // return example; // } // return null; // } // // private void runSelectedExample (){ // Class<? extends Example> exampleClass = selectBox.getSelected(); // if (exampleClass == null) // return; // startExample(exampleClass); // } // // private void startExample (Class<? extends Example> exampleClass){ // try { // Example example = exampleClass.newInstance(); // setScreen(example); // } catch (InstantiationException e) { // e.printStackTrace(); // } catch (IllegalAccessException e) { // e.printStackTrace(); // } // } // // public void exitCurrentExample (){ // Screen exitedScreen = getScreen(); // setScreen(menuScreen); // if (exitedScreen != null) // exitedScreen.dispose(); // selectBox.setSelected(((Example)exitedScreen).getClass()); // } // // @Override // public void dispose (){ // Screen exitedScreen = getScreen(); // if (exitedScreen != null) // exitedScreen.dispose(); // setScreen(null); // spriteBatch.dispose(); // skin.dispose(); // } // // private Screen menuScreen = new Screen() { // @Override // public void show() { // Gdx.input.setInputProcessor(stage); // } // // @Override // public void render(float delta) { // Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); // stage.act(); // stage.draw(); // if (Gdx.input.isKeyJustPressed(Input.Keys.ENTER)) // runSelectedExample(); // if (Gdx.input.isKeyJustPressed(Input.Keys.UP)) // selectBox.setSelectedIndex((selectBox.getSelectedIndex() + examples.size - 1) % examples.size); // if (Gdx.input.isKeyJustPressed(Input.Keys.DOWN)) // selectBox.setSelectedIndex((selectBox.getSelectedIndex() + 1) % examples.size); // } // // @Override // public void resize(int width, int height) { // stage.getViewport().update(width, height, true); // } // // @Override // public void pause() { // // } // // @Override // public void resume() { // // } // // @Override // public void hide() { // // } // // @Override // public void dispose() { // // } // }; // }
import com.badlogic.gdx.backends.lwjgl.LwjglApplication; import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration; import com.cyphercove.gdx.ExampleRunner;
/******************************************************************************* * Copyright 2017 See AUTHORS file. * * 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.cyphercove.gdx.flexbatch.examples.desktop; public class DesktopLauncher { public static void main (String[] arg) { LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
// Path: examples/core/src/com/cyphercove/gdx/ExampleRunner.java // public class ExampleRunner extends Game { // // public static final Array<Class<? extends Example>> examples = new Array<Class<? extends Example>>(); // static { // examples.add(AssignmentAssetManagerTest.class); // examples.add(FlexBatchTest.class); // } // // SpriteBatch spriteBatch; // Stage stage; // Skin skin; // SelectBox<Class<? extends Example>> selectBox; // String[] arg; // // public ExampleRunner (String[] arg){ // this.arg = arg; // } // // @Override // public void create() { // spriteBatch = new SpriteBatch(); // stage = new Stage(new ScreenViewport()); // skin = new Skin(Gdx.files.internal("uiskin.json")); // Table table = new Table(skin); // table.setFillParent(true); // selectBox = new SelectBox<Class<? extends Example>>(skin){ // protected String toString (Class<? extends Example> obj) { // return obj.getSimpleName(); // } // }; // selectBox.setItems(examples); // table.add(selectBox).fillX().space(20).row(); // stage.addActor(table); // TextButton startButton = new TextButton("Start example", skin); // startButton.addListener(new ChangeListener() { // @Override // public void changed(ChangeEvent event, Actor actor) { // runSelectedExample(); // } // }); // table.add(startButton).fillX(); // // if (arg != null && arg.length > 0) { // Class<? extends Example> specifiedExample = getExample(arg[0]); // if (specifiedExample != null){ // startExample(specifiedExample); // return; // } // } // // setScreen(menuScreen); // } // // @Override // public void render (){ // if (getScreen() instanceof Example && Gdx.input.isKeyJustPressed(Input.Keys.BACKSPACE)) // exitCurrentExample(); // super.render(); // } // // private Class<? extends Example> getExample (String simpleName){ // for (Class<? extends Example> example : examples){ // if (example.getSimpleName().equals(simpleName)) // return example; // } // return null; // } // // private void runSelectedExample (){ // Class<? extends Example> exampleClass = selectBox.getSelected(); // if (exampleClass == null) // return; // startExample(exampleClass); // } // // private void startExample (Class<? extends Example> exampleClass){ // try { // Example example = exampleClass.newInstance(); // setScreen(example); // } catch (InstantiationException e) { // e.printStackTrace(); // } catch (IllegalAccessException e) { // e.printStackTrace(); // } // } // // public void exitCurrentExample (){ // Screen exitedScreen = getScreen(); // setScreen(menuScreen); // if (exitedScreen != null) // exitedScreen.dispose(); // selectBox.setSelected(((Example)exitedScreen).getClass()); // } // // @Override // public void dispose (){ // Screen exitedScreen = getScreen(); // if (exitedScreen != null) // exitedScreen.dispose(); // setScreen(null); // spriteBatch.dispose(); // skin.dispose(); // } // // private Screen menuScreen = new Screen() { // @Override // public void show() { // Gdx.input.setInputProcessor(stage); // } // // @Override // public void render(float delta) { // Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); // stage.act(); // stage.draw(); // if (Gdx.input.isKeyJustPressed(Input.Keys.ENTER)) // runSelectedExample(); // if (Gdx.input.isKeyJustPressed(Input.Keys.UP)) // selectBox.setSelectedIndex((selectBox.getSelectedIndex() + examples.size - 1) % examples.size); // if (Gdx.input.isKeyJustPressed(Input.Keys.DOWN)) // selectBox.setSelectedIndex((selectBox.getSelectedIndex() + 1) % examples.size); // } // // @Override // public void resize(int width, int height) { // stage.getViewport().update(width, height, true); // } // // @Override // public void pause() { // // } // // @Override // public void resume() { // // } // // @Override // public void hide() { // // } // // @Override // public void dispose() { // // } // }; // } // Path: examples/desktop/src/com/cyphercove/gdx/flexbatch/examples/desktop/DesktopLauncher.java import com.badlogic.gdx.backends.lwjgl.LwjglApplication; import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration; import com.cyphercove.gdx.ExampleRunner; /******************************************************************************* * Copyright 2017 See AUTHORS file. * * 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.cyphercove.gdx.flexbatch.examples.desktop; public class DesktopLauncher { public static void main (String[] arg) { LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
new LwjglApplication(new ExampleRunner(arg), config);
boybeak/BeMusic
media/src/main/java/com/nulldreams/media/manager/ruler/Rulers.java
// Path: media/src/main/java/com/nulldreams/media/model/Song.java // public class Song { // private String title, titleKey, artist, artistKey, // album, albumKey, displayName, mimeType, path; // private int id, albumId, artistId, duration, size, year, track; // private boolean isRingtone, isPodcast, isAlarm, isMusic, isNotification; // // //private File mCoverFile; // // private Album albumObj; // // public Song (Bundle bundle) { // id = bundle.getInt(MediaStore.Audio.Media._ID); // title = bundle.getString(MediaStore.Audio.Media.TITLE); // titleKey = bundle.getString(MediaStore.Audio.Media.TITLE_KEY); // artist = bundle.getString(MediaStore.Audio.Media.ARTIST); // artistKey = bundle.getString(MediaStore.Audio.Media.ARTIST_KEY); // album = bundle.getString(MediaStore.Audio.Media.ALBUM); // albumKey = bundle.getString(MediaStore.Audio.Media.ALBUM_KEY); // displayName = bundle.getString(MediaStore.Audio.Media.DISPLAY_NAME); // year = bundle.getInt(MediaStore.Audio.Media.YEAR); // mimeType = bundle.getString(MediaStore.Audio.Media.MIME_TYPE); // path = bundle.getString(MediaStore.Audio.Media.DATA); // // artistId = bundle.getInt(MediaStore.Audio.Media.ARTIST_ID); // albumId = bundle.getInt(MediaStore.Audio.Media.ALBUM_ID); // track = bundle.getInt(MediaStore.Audio.Media.TRACK); // duration = bundle.getInt(MediaStore.Audio.Media.DURATION); // size = bundle.getInt(MediaStore.Audio.Media.SIZE); // isRingtone = bundle.getInt(MediaStore.Audio.Media.IS_RINGTONE) == 1; // isPodcast = bundle.getInt(MediaStore.Audio.Media.IS_PODCAST) == 1; // isAlarm = bundle.getInt(MediaStore.Audio.Media.IS_ALARM) == 1; // isMusic = bundle.getInt(MediaStore.Audio.Media.IS_MUSIC) == 1; // isNotification = bundle.getInt(MediaStore.Audio.Media.IS_NOTIFICATION) == 1; // } // // public int getId() { // return id; // } // // public String getTitle() { // return title; // } // // public String getArtist() { // return artist; // } // // public String getAlbum() { // return album; // } // // public String getDisplayName() { // return displayName; // } // // public String getMimeType() { // return mimeType; // } // // public String getPath() { // return path; // } // // public int getDuration() { // return duration; // } // // public String getTitleKey() { // return titleKey; // } // // public String getArtistKey() { // return artistKey; // } // // public String getAlbumKey() { // return albumKey; // } // // public int getAlbumId() { // return albumId; // } // // public int getArtistId() { // return artistId; // } // // public int getYear() { // return year; // } // // public int getTrack() { // return track; // } // // public int getSize() { // return size; // } // // public boolean isRingtone() { // return isRingtone; // } // // public boolean isPodcast() { // return isPodcast; // } // // public boolean isAlarm() { // return isAlarm; // } // // public boolean isMusic() { // return isMusic; // } // // public boolean isNotification() { // return isNotification; // } // // @Override // public boolean equals(Object obj) { // if (obj != null && obj instanceof Song) { // return ((Song) obj).id == id; // } // return false; // } // // /*public File getCoverFile (Context context) { // if (mCoverFile == null) { // mCoverFile = new File(context.getExternalCacheDir(), "covers" + File.separator + getTitle() + "_" + getArtist() + "_" + getAlbum() + ".jpg"); // } // return mCoverFile; // }*/ // // public String getArtistAlbum () { // return getArtist() + " - " + getAlbum(); // } // // public Album getAlbumObj() { // return albumObj; // } // // public void setAlbumObj(Album albumObj) { // this.albumObj = albumObj; // } // }
import com.nulldreams.media.model.Song; import java.util.List; import java.util.Random; import java.util.Stack;
package com.nulldreams.media.manager.ruler; /** * Created by gaoyunfei on 2016/12/28. * Some rules often use */ public class Rulers { public static final Rule RULER_SINGLE_LOOP = new SingleLoopRuler(), RULER_LIST_LOOP = new ListLoopRuler(), RULER_RANDOM = new RandomRuler(); public static class SingleLoopRuler implements Rule { private SingleLoopRuler () { } @Override
// Path: media/src/main/java/com/nulldreams/media/model/Song.java // public class Song { // private String title, titleKey, artist, artistKey, // album, albumKey, displayName, mimeType, path; // private int id, albumId, artistId, duration, size, year, track; // private boolean isRingtone, isPodcast, isAlarm, isMusic, isNotification; // // //private File mCoverFile; // // private Album albumObj; // // public Song (Bundle bundle) { // id = bundle.getInt(MediaStore.Audio.Media._ID); // title = bundle.getString(MediaStore.Audio.Media.TITLE); // titleKey = bundle.getString(MediaStore.Audio.Media.TITLE_KEY); // artist = bundle.getString(MediaStore.Audio.Media.ARTIST); // artistKey = bundle.getString(MediaStore.Audio.Media.ARTIST_KEY); // album = bundle.getString(MediaStore.Audio.Media.ALBUM); // albumKey = bundle.getString(MediaStore.Audio.Media.ALBUM_KEY); // displayName = bundle.getString(MediaStore.Audio.Media.DISPLAY_NAME); // year = bundle.getInt(MediaStore.Audio.Media.YEAR); // mimeType = bundle.getString(MediaStore.Audio.Media.MIME_TYPE); // path = bundle.getString(MediaStore.Audio.Media.DATA); // // artistId = bundle.getInt(MediaStore.Audio.Media.ARTIST_ID); // albumId = bundle.getInt(MediaStore.Audio.Media.ALBUM_ID); // track = bundle.getInt(MediaStore.Audio.Media.TRACK); // duration = bundle.getInt(MediaStore.Audio.Media.DURATION); // size = bundle.getInt(MediaStore.Audio.Media.SIZE); // isRingtone = bundle.getInt(MediaStore.Audio.Media.IS_RINGTONE) == 1; // isPodcast = bundle.getInt(MediaStore.Audio.Media.IS_PODCAST) == 1; // isAlarm = bundle.getInt(MediaStore.Audio.Media.IS_ALARM) == 1; // isMusic = bundle.getInt(MediaStore.Audio.Media.IS_MUSIC) == 1; // isNotification = bundle.getInt(MediaStore.Audio.Media.IS_NOTIFICATION) == 1; // } // // public int getId() { // return id; // } // // public String getTitle() { // return title; // } // // public String getArtist() { // return artist; // } // // public String getAlbum() { // return album; // } // // public String getDisplayName() { // return displayName; // } // // public String getMimeType() { // return mimeType; // } // // public String getPath() { // return path; // } // // public int getDuration() { // return duration; // } // // public String getTitleKey() { // return titleKey; // } // // public String getArtistKey() { // return artistKey; // } // // public String getAlbumKey() { // return albumKey; // } // // public int getAlbumId() { // return albumId; // } // // public int getArtistId() { // return artistId; // } // // public int getYear() { // return year; // } // // public int getTrack() { // return track; // } // // public int getSize() { // return size; // } // // public boolean isRingtone() { // return isRingtone; // } // // public boolean isPodcast() { // return isPodcast; // } // // public boolean isAlarm() { // return isAlarm; // } // // public boolean isMusic() { // return isMusic; // } // // public boolean isNotification() { // return isNotification; // } // // @Override // public boolean equals(Object obj) { // if (obj != null && obj instanceof Song) { // return ((Song) obj).id == id; // } // return false; // } // // /*public File getCoverFile (Context context) { // if (mCoverFile == null) { // mCoverFile = new File(context.getExternalCacheDir(), "covers" + File.separator + getTitle() + "_" + getArtist() + "_" + getAlbum() + ".jpg"); // } // return mCoverFile; // }*/ // // public String getArtistAlbum () { // return getArtist() + " - " + getAlbum(); // } // // public Album getAlbumObj() { // return albumObj; // } // // public void setAlbumObj(Album albumObj) { // this.albumObj = albumObj; // } // } // Path: media/src/main/java/com/nulldreams/media/manager/ruler/Rulers.java import com.nulldreams.media.model.Song; import java.util.List; import java.util.Random; import java.util.Stack; package com.nulldreams.media.manager.ruler; /** * Created by gaoyunfei on 2016/12/28. * Some rules often use */ public class Rulers { public static final Rule RULER_SINGLE_LOOP = new SingleLoopRuler(), RULER_LIST_LOOP = new ListLoopRuler(), RULER_RANDOM = new RandomRuler(); public static class SingleLoopRuler implements Rule { private SingleLoopRuler () { } @Override
public Song previous(Song song, List<Song> songList, boolean isUserAction) {
boybeak/BeMusic
app/src/main/java/com/nulldreams/bemusic/adapter/AlbumHolder.java
// Path: app/src/main/java/com/nulldreams/bemusic/activity/AlbumActivity.java // public class AlbumActivity extends AppCompatActivity { // // private CollapsingToolbarLayout mColTbLayout; // private Toolbar mTb; // private ImageView mThumbIv; // private RecyclerView mRv; // private FloatingActionButton mFab; // // private Album mAlbum; // // private DelegateAdapter mAdapter; // // private View.OnClickListener mClickListener = new View.OnClickListener() { // @Override // public void onClick(View v) { // final int id = v.getId(); // if (id == mFab.getId()) { // //PlayManager.getInstance(v.getContext()).dispatch(mAlbum); // } // } // }; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // setContentView(R.layout.activity_album); // // mAlbum = (Album)getIntent().getSerializableExtra("album"); // // mColTbLayout = (CollapsingToolbarLayout)findViewById(R.id.album_col_toolbar_layout); // mTb = (Toolbar)findViewById(R.id.album_toolbar); // mThumbIv = (ImageView)findViewById(R.id.album_thumb); // mRv = (RecyclerView)findViewById(R.id.album_rv); // mFab = (FloatingActionButton)findViewById(R.id.album_start); // // mRv.setLayoutManager(new LinearLayoutManager(this)); // // mAdapter = new DelegateAdapter(this); // mRv.setAdapter(mAdapter); // // mFab.setOnClickListener(mClickListener); // // setSupportActionBar(mTb); // getSupportActionBar().setDisplayShowHomeEnabled(true); // getSupportActionBar().setDisplayHomeAsUpEnabled(true); // // mColTbLayout.setTitle(mAlbum.getAlbum()); // Glide.with(this).load(mAlbum.getAlbumArt()).into(mThumbIv); // // List<Song> songList = PlayManager.getInstance(this).getAlbumSongList(mAlbum.getId()); // if (songList != null) { // mAdapter.addAll(songList, new DelegateParser<Song>() { // @Override // public LayoutImpl parse(DelegateAdapter adapter, Song data) { // return new SongDelegate(data); // } // }); // mAdapter.notifyDataSetChanged(); // } // } // // @Override // public boolean onOptionsItemSelected(MenuItem item) { // final int id = item.getItemId(); // if (id == android.R.id.home) { // onBackPressed(); // return true; // } // return super.onOptionsItemSelected(item); // } // } // // Path: media/src/main/java/com/nulldreams/media/model/Album.java // public class Album implements Serializable{ // private int id, minYear, maxYear, numSongs; // private String album, albumKey, artist, albumArt; // // public Album(int id, int minYear, int maxYear, int numSongs, String album, String albumKey, String artist, String albumArt) { // this.id = id; // this.minYear = minYear; // this.maxYear = maxYear; // this.numSongs = numSongs; // this.album = album; // this.albumKey = albumKey; // this.artist = artist; // this.albumArt = albumArt; // } // // public int getId() { // return id; // } // // public int getMinYear() { // return minYear; // } // // public int getMaxYear() { // return maxYear; // } // // public int getNumSongs() { // return numSongs; // } // // public String getAlbum() { // return album; // } // // public String getAlbumKey() { // return albumKey; // } // // public String getArtist() { // return artist; // } // // public String getAlbumArt() { // return albumArt; // } // }
import android.app.Activity; import android.app.ActivityOptions; import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.os.Build; import android.support.v4.app.ActivityOptionsCompat; import android.support.v7.graphics.Palette; import android.view.View; import android.widget.ImageView; import android.widget.TextView; import com.bumptech.glide.Glide; import com.bumptech.glide.request.animation.GlideAnimation; import com.bumptech.glide.request.target.SimpleTarget; import com.nulldreams.adapter.AbsViewHolder; import com.nulldreams.adapter.DelegateAdapter; import com.nulldreams.bemusic.R; import com.nulldreams.bemusic.activity.AlbumActivity; import com.nulldreams.media.model.Album;
package com.nulldreams.bemusic.adapter; /** * Created by boybe on 2017/1/6. */ public class AlbumHolder extends AbsViewHolder<AlbumDelegate> { private ImageView thumbIv; private TextView titleTv, artistTv, countTv; private View infoLayout; public AlbumHolder(View itemView) { super(itemView); thumbIv = (ImageView)findViewById(R.id.album_thumb); titleTv = (TextView)findViewById(R.id.album_title); artistTv = (TextView)findViewById(R.id.album_artist); countTv = (TextView)findViewById(R.id.album_count); infoLayout = findViewById(R.id.album_info_layout); } @Override public void onBindView(final Context context, final AlbumDelegate albumDelegate, int position, DelegateAdapter adapter) {
// Path: app/src/main/java/com/nulldreams/bemusic/activity/AlbumActivity.java // public class AlbumActivity extends AppCompatActivity { // // private CollapsingToolbarLayout mColTbLayout; // private Toolbar mTb; // private ImageView mThumbIv; // private RecyclerView mRv; // private FloatingActionButton mFab; // // private Album mAlbum; // // private DelegateAdapter mAdapter; // // private View.OnClickListener mClickListener = new View.OnClickListener() { // @Override // public void onClick(View v) { // final int id = v.getId(); // if (id == mFab.getId()) { // //PlayManager.getInstance(v.getContext()).dispatch(mAlbum); // } // } // }; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // setContentView(R.layout.activity_album); // // mAlbum = (Album)getIntent().getSerializableExtra("album"); // // mColTbLayout = (CollapsingToolbarLayout)findViewById(R.id.album_col_toolbar_layout); // mTb = (Toolbar)findViewById(R.id.album_toolbar); // mThumbIv = (ImageView)findViewById(R.id.album_thumb); // mRv = (RecyclerView)findViewById(R.id.album_rv); // mFab = (FloatingActionButton)findViewById(R.id.album_start); // // mRv.setLayoutManager(new LinearLayoutManager(this)); // // mAdapter = new DelegateAdapter(this); // mRv.setAdapter(mAdapter); // // mFab.setOnClickListener(mClickListener); // // setSupportActionBar(mTb); // getSupportActionBar().setDisplayShowHomeEnabled(true); // getSupportActionBar().setDisplayHomeAsUpEnabled(true); // // mColTbLayout.setTitle(mAlbum.getAlbum()); // Glide.with(this).load(mAlbum.getAlbumArt()).into(mThumbIv); // // List<Song> songList = PlayManager.getInstance(this).getAlbumSongList(mAlbum.getId()); // if (songList != null) { // mAdapter.addAll(songList, new DelegateParser<Song>() { // @Override // public LayoutImpl parse(DelegateAdapter adapter, Song data) { // return new SongDelegate(data); // } // }); // mAdapter.notifyDataSetChanged(); // } // } // // @Override // public boolean onOptionsItemSelected(MenuItem item) { // final int id = item.getItemId(); // if (id == android.R.id.home) { // onBackPressed(); // return true; // } // return super.onOptionsItemSelected(item); // } // } // // Path: media/src/main/java/com/nulldreams/media/model/Album.java // public class Album implements Serializable{ // private int id, minYear, maxYear, numSongs; // private String album, albumKey, artist, albumArt; // // public Album(int id, int minYear, int maxYear, int numSongs, String album, String albumKey, String artist, String albumArt) { // this.id = id; // this.minYear = minYear; // this.maxYear = maxYear; // this.numSongs = numSongs; // this.album = album; // this.albumKey = albumKey; // this.artist = artist; // this.albumArt = albumArt; // } // // public int getId() { // return id; // } // // public int getMinYear() { // return minYear; // } // // public int getMaxYear() { // return maxYear; // } // // public int getNumSongs() { // return numSongs; // } // // public String getAlbum() { // return album; // } // // public String getAlbumKey() { // return albumKey; // } // // public String getArtist() { // return artist; // } // // public String getAlbumArt() { // return albumArt; // } // } // Path: app/src/main/java/com/nulldreams/bemusic/adapter/AlbumHolder.java import android.app.Activity; import android.app.ActivityOptions; import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.os.Build; import android.support.v4.app.ActivityOptionsCompat; import android.support.v7.graphics.Palette; import android.view.View; import android.widget.ImageView; import android.widget.TextView; import com.bumptech.glide.Glide; import com.bumptech.glide.request.animation.GlideAnimation; import com.bumptech.glide.request.target.SimpleTarget; import com.nulldreams.adapter.AbsViewHolder; import com.nulldreams.adapter.DelegateAdapter; import com.nulldreams.bemusic.R; import com.nulldreams.bemusic.activity.AlbumActivity; import com.nulldreams.media.model.Album; package com.nulldreams.bemusic.adapter; /** * Created by boybe on 2017/1/6. */ public class AlbumHolder extends AbsViewHolder<AlbumDelegate> { private ImageView thumbIv; private TextView titleTv, artistTv, countTv; private View infoLayout; public AlbumHolder(View itemView) { super(itemView); thumbIv = (ImageView)findViewById(R.id.album_thumb); titleTv = (TextView)findViewById(R.id.album_title); artistTv = (TextView)findViewById(R.id.album_artist); countTv = (TextView)findViewById(R.id.album_count); infoLayout = findViewById(R.id.album_info_layout); } @Override public void onBindView(final Context context, final AlbumDelegate albumDelegate, int position, DelegateAdapter adapter) {
final Album album = albumDelegate.getSource();
boybeak/BeMusic
app/src/main/java/com/nulldreams/bemusic/adapter/AlbumHolder.java
// Path: app/src/main/java/com/nulldreams/bemusic/activity/AlbumActivity.java // public class AlbumActivity extends AppCompatActivity { // // private CollapsingToolbarLayout mColTbLayout; // private Toolbar mTb; // private ImageView mThumbIv; // private RecyclerView mRv; // private FloatingActionButton mFab; // // private Album mAlbum; // // private DelegateAdapter mAdapter; // // private View.OnClickListener mClickListener = new View.OnClickListener() { // @Override // public void onClick(View v) { // final int id = v.getId(); // if (id == mFab.getId()) { // //PlayManager.getInstance(v.getContext()).dispatch(mAlbum); // } // } // }; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // setContentView(R.layout.activity_album); // // mAlbum = (Album)getIntent().getSerializableExtra("album"); // // mColTbLayout = (CollapsingToolbarLayout)findViewById(R.id.album_col_toolbar_layout); // mTb = (Toolbar)findViewById(R.id.album_toolbar); // mThumbIv = (ImageView)findViewById(R.id.album_thumb); // mRv = (RecyclerView)findViewById(R.id.album_rv); // mFab = (FloatingActionButton)findViewById(R.id.album_start); // // mRv.setLayoutManager(new LinearLayoutManager(this)); // // mAdapter = new DelegateAdapter(this); // mRv.setAdapter(mAdapter); // // mFab.setOnClickListener(mClickListener); // // setSupportActionBar(mTb); // getSupportActionBar().setDisplayShowHomeEnabled(true); // getSupportActionBar().setDisplayHomeAsUpEnabled(true); // // mColTbLayout.setTitle(mAlbum.getAlbum()); // Glide.with(this).load(mAlbum.getAlbumArt()).into(mThumbIv); // // List<Song> songList = PlayManager.getInstance(this).getAlbumSongList(mAlbum.getId()); // if (songList != null) { // mAdapter.addAll(songList, new DelegateParser<Song>() { // @Override // public LayoutImpl parse(DelegateAdapter adapter, Song data) { // return new SongDelegate(data); // } // }); // mAdapter.notifyDataSetChanged(); // } // } // // @Override // public boolean onOptionsItemSelected(MenuItem item) { // final int id = item.getItemId(); // if (id == android.R.id.home) { // onBackPressed(); // return true; // } // return super.onOptionsItemSelected(item); // } // } // // Path: media/src/main/java/com/nulldreams/media/model/Album.java // public class Album implements Serializable{ // private int id, minYear, maxYear, numSongs; // private String album, albumKey, artist, albumArt; // // public Album(int id, int minYear, int maxYear, int numSongs, String album, String albumKey, String artist, String albumArt) { // this.id = id; // this.minYear = minYear; // this.maxYear = maxYear; // this.numSongs = numSongs; // this.album = album; // this.albumKey = albumKey; // this.artist = artist; // this.albumArt = albumArt; // } // // public int getId() { // return id; // } // // public int getMinYear() { // return minYear; // } // // public int getMaxYear() { // return maxYear; // } // // public int getNumSongs() { // return numSongs; // } // // public String getAlbum() { // return album; // } // // public String getAlbumKey() { // return albumKey; // } // // public String getArtist() { // return artist; // } // // public String getAlbumArt() { // return albumArt; // } // }
import android.app.Activity; import android.app.ActivityOptions; import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.os.Build; import android.support.v4.app.ActivityOptionsCompat; import android.support.v7.graphics.Palette; import android.view.View; import android.widget.ImageView; import android.widget.TextView; import com.bumptech.glide.Glide; import com.bumptech.glide.request.animation.GlideAnimation; import com.bumptech.glide.request.target.SimpleTarget; import com.nulldreams.adapter.AbsViewHolder; import com.nulldreams.adapter.DelegateAdapter; import com.nulldreams.bemusic.R; import com.nulldreams.bemusic.activity.AlbumActivity; import com.nulldreams.media.model.Album;
@Override public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) { thumbIv.setImageBitmap(resource); if (albumDelegate.getRgb() > 0) { infoLayout.setBackgroundColor(albumDelegate.getRgb()); } else { Palette.from(resource).generate(new Palette.PaletteAsyncListener() { @Override public void onGenerated(Palette palette) { Palette.Swatch swatch = palette.getDarkMutedSwatch(); int rgb; if (swatch != null) { rgb = swatch.getRgb(); } else { rgb = context.getResources().getColor(R.color.colorAccent); } albumDelegate.setRgb(rgb); infoLayout.setBackgroundColor(rgb); } }); } } }); titleTv.setText(album.getAlbum()); artistTv.setText(album.getArtist()); int count = album.getNumSongs(); countTv.setText(context.getResources().getQuantityString(R.plurals.text_album_song_count, count, count)); itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) {
// Path: app/src/main/java/com/nulldreams/bemusic/activity/AlbumActivity.java // public class AlbumActivity extends AppCompatActivity { // // private CollapsingToolbarLayout mColTbLayout; // private Toolbar mTb; // private ImageView mThumbIv; // private RecyclerView mRv; // private FloatingActionButton mFab; // // private Album mAlbum; // // private DelegateAdapter mAdapter; // // private View.OnClickListener mClickListener = new View.OnClickListener() { // @Override // public void onClick(View v) { // final int id = v.getId(); // if (id == mFab.getId()) { // //PlayManager.getInstance(v.getContext()).dispatch(mAlbum); // } // } // }; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // setContentView(R.layout.activity_album); // // mAlbum = (Album)getIntent().getSerializableExtra("album"); // // mColTbLayout = (CollapsingToolbarLayout)findViewById(R.id.album_col_toolbar_layout); // mTb = (Toolbar)findViewById(R.id.album_toolbar); // mThumbIv = (ImageView)findViewById(R.id.album_thumb); // mRv = (RecyclerView)findViewById(R.id.album_rv); // mFab = (FloatingActionButton)findViewById(R.id.album_start); // // mRv.setLayoutManager(new LinearLayoutManager(this)); // // mAdapter = new DelegateAdapter(this); // mRv.setAdapter(mAdapter); // // mFab.setOnClickListener(mClickListener); // // setSupportActionBar(mTb); // getSupportActionBar().setDisplayShowHomeEnabled(true); // getSupportActionBar().setDisplayHomeAsUpEnabled(true); // // mColTbLayout.setTitle(mAlbum.getAlbum()); // Glide.with(this).load(mAlbum.getAlbumArt()).into(mThumbIv); // // List<Song> songList = PlayManager.getInstance(this).getAlbumSongList(mAlbum.getId()); // if (songList != null) { // mAdapter.addAll(songList, new DelegateParser<Song>() { // @Override // public LayoutImpl parse(DelegateAdapter adapter, Song data) { // return new SongDelegate(data); // } // }); // mAdapter.notifyDataSetChanged(); // } // } // // @Override // public boolean onOptionsItemSelected(MenuItem item) { // final int id = item.getItemId(); // if (id == android.R.id.home) { // onBackPressed(); // return true; // } // return super.onOptionsItemSelected(item); // } // } // // Path: media/src/main/java/com/nulldreams/media/model/Album.java // public class Album implements Serializable{ // private int id, minYear, maxYear, numSongs; // private String album, albumKey, artist, albumArt; // // public Album(int id, int minYear, int maxYear, int numSongs, String album, String albumKey, String artist, String albumArt) { // this.id = id; // this.minYear = minYear; // this.maxYear = maxYear; // this.numSongs = numSongs; // this.album = album; // this.albumKey = albumKey; // this.artist = artist; // this.albumArt = albumArt; // } // // public int getId() { // return id; // } // // public int getMinYear() { // return minYear; // } // // public int getMaxYear() { // return maxYear; // } // // public int getNumSongs() { // return numSongs; // } // // public String getAlbum() { // return album; // } // // public String getAlbumKey() { // return albumKey; // } // // public String getArtist() { // return artist; // } // // public String getAlbumArt() { // return albumArt; // } // } // Path: app/src/main/java/com/nulldreams/bemusic/adapter/AlbumHolder.java import android.app.Activity; import android.app.ActivityOptions; import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.os.Build; import android.support.v4.app.ActivityOptionsCompat; import android.support.v7.graphics.Palette; import android.view.View; import android.widget.ImageView; import android.widget.TextView; import com.bumptech.glide.Glide; import com.bumptech.glide.request.animation.GlideAnimation; import com.bumptech.glide.request.target.SimpleTarget; import com.nulldreams.adapter.AbsViewHolder; import com.nulldreams.adapter.DelegateAdapter; import com.nulldreams.bemusic.R; import com.nulldreams.bemusic.activity.AlbumActivity; import com.nulldreams.media.model.Album; @Override public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) { thumbIv.setImageBitmap(resource); if (albumDelegate.getRgb() > 0) { infoLayout.setBackgroundColor(albumDelegate.getRgb()); } else { Palette.from(resource).generate(new Palette.PaletteAsyncListener() { @Override public void onGenerated(Palette palette) { Palette.Swatch swatch = palette.getDarkMutedSwatch(); int rgb; if (swatch != null) { rgb = swatch.getRgb(); } else { rgb = context.getResources().getColor(R.color.colorAccent); } albumDelegate.setRgb(rgb); infoLayout.setBackgroundColor(rgb); } }); } } }); titleTv.setText(album.getAlbum()); artistTv.setText(album.getArtist()); int count = album.getNumSongs(); countTv.setText(context.getResources().getQuantityString(R.plurals.text_album_song_count, count, count)); itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) {
Intent it = new Intent(context, AlbumActivity.class);
chukmunnlee/jsocketio
src/at/jsocketio/core/utils/InvokeMethod.java
// Path: src/at/jsocketio/api/EventObject.java // public class EventObject { // // private String name; // private JsonArray payload = null; // // public EventObject(String n) { // name = n; // } // // public String getName() { // return (name); // } // // public JsonArray getPayload() { // return (payload); // } // public void setPayload(JsonArray array) { // payload = array; // } // public void setPayload(JsonObject obj) { // if (null == payload) // payload = Json.createArrayBuilder().build(); // payload.add(obj); // } // // @Override // public String toString() { // return ("name: " + name + ", payload: " + payload); // } // // public static EventObject valueOf(String s) { // JsonObject obj = Frame.parseJson(s); // EventObject evt = new EventObject(obj.getString("name")); // evt.setPayload(obj.getJsonArray("args")); // return (evt); // } // // }
import at.jsocketio.api.EventObject; import at.jsocketio.api.annotation.*; import at.jsocketio.core.*; import java.lang.annotation.*; import java.lang.reflect.*; import java.util.*; import java.util.logging.*; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.json.*; import javax.websocket.*; import javax.websocket.CloseReason.CloseCode;
if (null == m) continue; Object obj = CDIUtils.locateBean(h); if (null == obj) return; Object[] params = createParameters(m, predefined); if (logger.isLoggable(Level.FINE)) logger.log(Level.FINE, "@{0}: {1}.{2}", new Object[]{ annot.getSimpleName(), m.getDeclaringClass().getName(), m.getName()}); try { m.invoke(obj, params); } catch ( IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { logger.log(Level.WARNING, "Error invoking " + m.getName(), ex); } } } public static List<String> createRegExGroup(Matcher m) { List<String> result = new LinkedList<>(); int count = m.groupCount(); if (m.matches()) for (int i = 0; i < count; i++) result.add(m.group(i)); return (result); }
// Path: src/at/jsocketio/api/EventObject.java // public class EventObject { // // private String name; // private JsonArray payload = null; // // public EventObject(String n) { // name = n; // } // // public String getName() { // return (name); // } // // public JsonArray getPayload() { // return (payload); // } // public void setPayload(JsonArray array) { // payload = array; // } // public void setPayload(JsonObject obj) { // if (null == payload) // payload = Json.createArrayBuilder().build(); // payload.add(obj); // } // // @Override // public String toString() { // return ("name: " + name + ", payload: " + payload); // } // // public static EventObject valueOf(String s) { // JsonObject obj = Frame.parseJson(s); // EventObject evt = new EventObject(obj.getString("name")); // evt.setPayload(obj.getJsonArray("args")); // return (evt); // } // // } // Path: src/at/jsocketio/core/utils/InvokeMethod.java import at.jsocketio.api.EventObject; import at.jsocketio.api.annotation.*; import at.jsocketio.core.*; import java.lang.annotation.*; import java.lang.reflect.*; import java.util.*; import java.util.logging.*; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.json.*; import javax.websocket.*; import javax.websocket.CloseReason.CloseCode; if (null == m) continue; Object obj = CDIUtils.locateBean(h); if (null == obj) return; Object[] params = createParameters(m, predefined); if (logger.isLoggable(Level.FINE)) logger.log(Level.FINE, "@{0}: {1}.{2}", new Object[]{ annot.getSimpleName(), m.getDeclaringClass().getName(), m.getName()}); try { m.invoke(obj, params); } catch ( IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { logger.log(Level.WARNING, "Error invoking " + m.getName(), ex); } } } public static List<String> createRegExGroup(Matcher m) { List<String> result = new LinkedList<>(); int count = m.groupCount(); if (m.matches()) for (int i = 0; i < count; i++) result.add(m.group(i)); return (result); }
public static void invoke(EventObject value, HandlerMap handlerMap, Session session) {
jDramaix/gss.gwt
src/test/java/com/google/gwt/resources/client/GssResourceTest.java
// Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface ClassNameAnnotation extends GssResource { // @ClassName("renamed-class") // String renamedClass(); // // String nonRenamedClass(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface EmptyClass extends GssResource { // String empty(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface NonStandardAtRules extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface NonStandardFunctions extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface RuntimeConditional extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface SomeGssResource extends GssResource { // String someClass(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface WithConstant extends GssResource { // String constantOne(); // // String classOne(); // }
import com.google.gwt.resources.client.TestResources.ClassNameAnnotation; import com.google.gwt.resources.client.TestResources.EmptyClass; import com.google.gwt.resources.client.TestResources.NonStandardAtRules; import com.google.gwt.resources.client.TestResources.NonStandardFunctions; import com.google.gwt.resources.client.TestResources.RuntimeConditional; import com.google.gwt.resources.client.TestResources.SomeGssResource; import com.google.gwt.resources.client.TestResources.WithConstant;
/* * Copyright 2013 Julien Dramaix. * * 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.gwt.resources.client; public class GssResourceTest extends RenamingClassNameTest { @Override public String getModuleName() { return "com.google.gwt.resources.GssResourceTest"; } @Override public void testClassesRenaming() {
// Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface ClassNameAnnotation extends GssResource { // @ClassName("renamed-class") // String renamedClass(); // // String nonRenamedClass(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface EmptyClass extends GssResource { // String empty(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface NonStandardAtRules extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface NonStandardFunctions extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface RuntimeConditional extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface SomeGssResource extends GssResource { // String someClass(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface WithConstant extends GssResource { // String constantOne(); // // String classOne(); // } // Path: src/test/java/com/google/gwt/resources/client/GssResourceTest.java import com.google.gwt.resources.client.TestResources.ClassNameAnnotation; import com.google.gwt.resources.client.TestResources.EmptyClass; import com.google.gwt.resources.client.TestResources.NonStandardAtRules; import com.google.gwt.resources.client.TestResources.NonStandardFunctions; import com.google.gwt.resources.client.TestResources.RuntimeConditional; import com.google.gwt.resources.client.TestResources.SomeGssResource; import com.google.gwt.resources.client.TestResources.WithConstant; /* * Copyright 2013 Julien Dramaix. * * 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.gwt.resources.client; public class GssResourceTest extends RenamingClassNameTest { @Override public String getModuleName() { return "com.google.gwt.resources.GssResourceTest"; } @Override public void testClassesRenaming() {
ClassNameAnnotation classNameAnnotation = res().classNameAnnotation();
jDramaix/gss.gwt
src/test/java/com/google/gwt/resources/client/GssResourceTest.java
// Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface ClassNameAnnotation extends GssResource { // @ClassName("renamed-class") // String renamedClass(); // // String nonRenamedClass(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface EmptyClass extends GssResource { // String empty(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface NonStandardAtRules extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface NonStandardFunctions extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface RuntimeConditional extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface SomeGssResource extends GssResource { // String someClass(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface WithConstant extends GssResource { // String constantOne(); // // String classOne(); // }
import com.google.gwt.resources.client.TestResources.ClassNameAnnotation; import com.google.gwt.resources.client.TestResources.EmptyClass; import com.google.gwt.resources.client.TestResources.NonStandardAtRules; import com.google.gwt.resources.client.TestResources.NonStandardFunctions; import com.google.gwt.resources.client.TestResources.RuntimeConditional; import com.google.gwt.resources.client.TestResources.SomeGssResource; import com.google.gwt.resources.client.TestResources.WithConstant;
public void testEval() { String text = res().eval().getText(); assertTrue(text.contains("{color:#fff;background-color:#f00;width:30px}")); } public void testSprite() { String text = res().sprite().getText(); String expected = "{height:64px;width:64px;overflow:hidden;background:url(" + res() .someImageResource().getSafeUri().asString() + ") -0px -0px no-repeat}"; assertTrue(text.contains(expected)); } public void testResourceUrl() { String text = res().resourceUrl().getText(); String expected = "{cursor:url(" + res().someDataResource().getSafeUri().asString() + ");" + "background-image:url(" + res().someImageResource().getSafeUri().asString() + ");" + "cursor:url(" + res().someDataResource().getSafeUri().asString() + ");" + "background-image:url(" + res().someImageResource().getSafeUri().asString() + ")}"; assertTrue(text.contains(expected)); } /** * Test that empty class definitions doesn't throw an exception (issue #25) and that they are * removed from the resulting css. */ public void testEmptyClass() {
// Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface ClassNameAnnotation extends GssResource { // @ClassName("renamed-class") // String renamedClass(); // // String nonRenamedClass(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface EmptyClass extends GssResource { // String empty(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface NonStandardAtRules extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface NonStandardFunctions extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface RuntimeConditional extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface SomeGssResource extends GssResource { // String someClass(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface WithConstant extends GssResource { // String constantOne(); // // String classOne(); // } // Path: src/test/java/com/google/gwt/resources/client/GssResourceTest.java import com.google.gwt.resources.client.TestResources.ClassNameAnnotation; import com.google.gwt.resources.client.TestResources.EmptyClass; import com.google.gwt.resources.client.TestResources.NonStandardAtRules; import com.google.gwt.resources.client.TestResources.NonStandardFunctions; import com.google.gwt.resources.client.TestResources.RuntimeConditional; import com.google.gwt.resources.client.TestResources.SomeGssResource; import com.google.gwt.resources.client.TestResources.WithConstant; public void testEval() { String text = res().eval().getText(); assertTrue(text.contains("{color:#fff;background-color:#f00;width:30px}")); } public void testSprite() { String text = res().sprite().getText(); String expected = "{height:64px;width:64px;overflow:hidden;background:url(" + res() .someImageResource().getSafeUri().asString() + ") -0px -0px no-repeat}"; assertTrue(text.contains(expected)); } public void testResourceUrl() { String text = res().resourceUrl().getText(); String expected = "{cursor:url(" + res().someDataResource().getSafeUri().asString() + ");" + "background-image:url(" + res().someImageResource().getSafeUri().asString() + ");" + "cursor:url(" + res().someDataResource().getSafeUri().asString() + ");" + "background-image:url(" + res().someImageResource().getSafeUri().asString() + ")}"; assertTrue(text.contains(expected)); } /** * Test that empty class definitions doesn't throw an exception (issue #25) and that they are * removed from the resulting css. */ public void testEmptyClass() {
EmptyClass emptyClass = res().emptyClass();
jDramaix/gss.gwt
src/test/java/com/google/gwt/resources/client/GssResourceTest.java
// Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface ClassNameAnnotation extends GssResource { // @ClassName("renamed-class") // String renamedClass(); // // String nonRenamedClass(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface EmptyClass extends GssResource { // String empty(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface NonStandardAtRules extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface NonStandardFunctions extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface RuntimeConditional extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface SomeGssResource extends GssResource { // String someClass(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface WithConstant extends GssResource { // String constantOne(); // // String classOne(); // }
import com.google.gwt.resources.client.TestResources.ClassNameAnnotation; import com.google.gwt.resources.client.TestResources.EmptyClass; import com.google.gwt.resources.client.TestResources.NonStandardAtRules; import com.google.gwt.resources.client.TestResources.NonStandardFunctions; import com.google.gwt.resources.client.TestResources.RuntimeConditional; import com.google.gwt.resources.client.TestResources.SomeGssResource; import com.google.gwt.resources.client.TestResources.WithConstant;
public void testSprite() { String text = res().sprite().getText(); String expected = "{height:64px;width:64px;overflow:hidden;background:url(" + res() .someImageResource().getSafeUri().asString() + ") -0px -0px no-repeat}"; assertTrue(text.contains(expected)); } public void testResourceUrl() { String text = res().resourceUrl().getText(); String expected = "{cursor:url(" + res().someDataResource().getSafeUri().asString() + ");" + "background-image:url(" + res().someImageResource().getSafeUri().asString() + ");" + "cursor:url(" + res().someDataResource().getSafeUri().asString() + ");" + "background-image:url(" + res().someImageResource().getSafeUri().asString() + ")}"; assertTrue(text.contains(expected)); } /** * Test that empty class definitions doesn't throw an exception (issue #25) and that they are * removed from the resulting css. */ public void testEmptyClass() { EmptyClass emptyClass = res().emptyClass(); assertEquals("", emptyClass.getText()); } public void testConstant() {
// Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface ClassNameAnnotation extends GssResource { // @ClassName("renamed-class") // String renamedClass(); // // String nonRenamedClass(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface EmptyClass extends GssResource { // String empty(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface NonStandardAtRules extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface NonStandardFunctions extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface RuntimeConditional extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface SomeGssResource extends GssResource { // String someClass(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface WithConstant extends GssResource { // String constantOne(); // // String classOne(); // } // Path: src/test/java/com/google/gwt/resources/client/GssResourceTest.java import com.google.gwt.resources.client.TestResources.ClassNameAnnotation; import com.google.gwt.resources.client.TestResources.EmptyClass; import com.google.gwt.resources.client.TestResources.NonStandardAtRules; import com.google.gwt.resources.client.TestResources.NonStandardFunctions; import com.google.gwt.resources.client.TestResources.RuntimeConditional; import com.google.gwt.resources.client.TestResources.SomeGssResource; import com.google.gwt.resources.client.TestResources.WithConstant; public void testSprite() { String text = res().sprite().getText(); String expected = "{height:64px;width:64px;overflow:hidden;background:url(" + res() .someImageResource().getSafeUri().asString() + ") -0px -0px no-repeat}"; assertTrue(text.contains(expected)); } public void testResourceUrl() { String text = res().resourceUrl().getText(); String expected = "{cursor:url(" + res().someDataResource().getSafeUri().asString() + ");" + "background-image:url(" + res().someImageResource().getSafeUri().asString() + ");" + "cursor:url(" + res().someDataResource().getSafeUri().asString() + ");" + "background-image:url(" + res().someImageResource().getSafeUri().asString() + ")}"; assertTrue(text.contains(expected)); } /** * Test that empty class definitions doesn't throw an exception (issue #25) and that they are * removed from the resulting css. */ public void testEmptyClass() { EmptyClass emptyClass = res().emptyClass(); assertEquals("", emptyClass.getText()); } public void testConstant() {
WithConstant withConstant = res().withConstant();
jDramaix/gss.gwt
src/test/java/com/google/gwt/resources/client/GssResourceTest.java
// Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface ClassNameAnnotation extends GssResource { // @ClassName("renamed-class") // String renamedClass(); // // String nonRenamedClass(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface EmptyClass extends GssResource { // String empty(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface NonStandardAtRules extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface NonStandardFunctions extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface RuntimeConditional extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface SomeGssResource extends GssResource { // String someClass(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface WithConstant extends GssResource { // String constantOne(); // // String classOne(); // }
import com.google.gwt.resources.client.TestResources.ClassNameAnnotation; import com.google.gwt.resources.client.TestResources.EmptyClass; import com.google.gwt.resources.client.TestResources.NonStandardAtRules; import com.google.gwt.resources.client.TestResources.NonStandardFunctions; import com.google.gwt.resources.client.TestResources.RuntimeConditional; import com.google.gwt.resources.client.TestResources.SomeGssResource; import com.google.gwt.resources.client.TestResources.WithConstant;
assertEquals("", emptyClass.getText()); } public void testConstant() { WithConstant withConstant = res().withConstant(); assertEquals("15px", withConstant.constantOne()); String expectedCss = "." + withConstant.classOne() + "{padding:" + withConstant.constantOne() + "}"; assertEquals(expectedCss, withConstant.getText()); } public void testClassNameAnnotation() { ClassNameAnnotation css = res().classNameAnnotation(); String expectedCss = "." + css.renamedClass() + "{color:black}." + css.nonRenamedClass() + "{color:white}"; assertEquals(expectedCss, css.getText()); } public void testConstants() { assertEquals("15px", res().cssWithConstant().constantOne()); assertEquals(5, res().cssWithConstant().constantTwo()); assertEquals("black", res().cssWithConstant().CONSTANT_THREE()); assertNotSame("white", res().cssWithConstant().conflictConstantClass()); } public void testNotStrict() {
// Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface ClassNameAnnotation extends GssResource { // @ClassName("renamed-class") // String renamedClass(); // // String nonRenamedClass(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface EmptyClass extends GssResource { // String empty(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface NonStandardAtRules extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface NonStandardFunctions extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface RuntimeConditional extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface SomeGssResource extends GssResource { // String someClass(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface WithConstant extends GssResource { // String constantOne(); // // String classOne(); // } // Path: src/test/java/com/google/gwt/resources/client/GssResourceTest.java import com.google.gwt.resources.client.TestResources.ClassNameAnnotation; import com.google.gwt.resources.client.TestResources.EmptyClass; import com.google.gwt.resources.client.TestResources.NonStandardAtRules; import com.google.gwt.resources.client.TestResources.NonStandardFunctions; import com.google.gwt.resources.client.TestResources.RuntimeConditional; import com.google.gwt.resources.client.TestResources.SomeGssResource; import com.google.gwt.resources.client.TestResources.WithConstant; assertEquals("", emptyClass.getText()); } public void testConstant() { WithConstant withConstant = res().withConstant(); assertEquals("15px", withConstant.constantOne()); String expectedCss = "." + withConstant.classOne() + "{padding:" + withConstant.constantOne() + "}"; assertEquals(expectedCss, withConstant.getText()); } public void testClassNameAnnotation() { ClassNameAnnotation css = res().classNameAnnotation(); String expectedCss = "." + css.renamedClass() + "{color:black}." + css.nonRenamedClass() + "{color:white}"; assertEquals(expectedCss, css.getText()); } public void testConstants() { assertEquals("15px", res().cssWithConstant().constantOne()); assertEquals(5, res().cssWithConstant().constantTwo()); assertEquals("black", res().cssWithConstant().CONSTANT_THREE()); assertNotSame("white", res().cssWithConstant().conflictConstantClass()); } public void testNotStrict() {
SomeGssResource notStrict = res().notstrict();
jDramaix/gss.gwt
src/test/java/com/google/gwt/resources/client/GssResourceTest.java
// Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface ClassNameAnnotation extends GssResource { // @ClassName("renamed-class") // String renamedClass(); // // String nonRenamedClass(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface EmptyClass extends GssResource { // String empty(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface NonStandardAtRules extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface NonStandardFunctions extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface RuntimeConditional extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface SomeGssResource extends GssResource { // String someClass(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface WithConstant extends GssResource { // String constantOne(); // // String classOne(); // }
import com.google.gwt.resources.client.TestResources.ClassNameAnnotation; import com.google.gwt.resources.client.TestResources.EmptyClass; import com.google.gwt.resources.client.TestResources.NonStandardAtRules; import com.google.gwt.resources.client.TestResources.NonStandardFunctions; import com.google.gwt.resources.client.TestResources.RuntimeConditional; import com.google.gwt.resources.client.TestResources.SomeGssResource; import com.google.gwt.resources.client.TestResources.WithConstant;
+ "}"; assertEquals(expectedCss, withConstant.getText()); } public void testClassNameAnnotation() { ClassNameAnnotation css = res().classNameAnnotation(); String expectedCss = "." + css.renamedClass() + "{color:black}." + css.nonRenamedClass() + "{color:white}"; assertEquals(expectedCss, css.getText()); } public void testConstants() { assertEquals("15px", res().cssWithConstant().constantOne()); assertEquals(5, res().cssWithConstant().constantTwo()); assertEquals("black", res().cssWithConstant().CONSTANT_THREE()); assertNotSame("white", res().cssWithConstant().conflictConstantClass()); } public void testNotStrict() { SomeGssResource notStrict = res().notstrict(); String expectedCss = "." + notStrict.someClass() + "{color:black}.otherNotStrictClass{" + "color:white}"; assertEquals(expectedCss, notStrict.getText()); } public void testRuntimeConditional() {
// Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface ClassNameAnnotation extends GssResource { // @ClassName("renamed-class") // String renamedClass(); // // String nonRenamedClass(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface EmptyClass extends GssResource { // String empty(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface NonStandardAtRules extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface NonStandardFunctions extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface RuntimeConditional extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface SomeGssResource extends GssResource { // String someClass(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface WithConstant extends GssResource { // String constantOne(); // // String classOne(); // } // Path: src/test/java/com/google/gwt/resources/client/GssResourceTest.java import com.google.gwt.resources.client.TestResources.ClassNameAnnotation; import com.google.gwt.resources.client.TestResources.EmptyClass; import com.google.gwt.resources.client.TestResources.NonStandardAtRules; import com.google.gwt.resources.client.TestResources.NonStandardFunctions; import com.google.gwt.resources.client.TestResources.RuntimeConditional; import com.google.gwt.resources.client.TestResources.SomeGssResource; import com.google.gwt.resources.client.TestResources.WithConstant; + "}"; assertEquals(expectedCss, withConstant.getText()); } public void testClassNameAnnotation() { ClassNameAnnotation css = res().classNameAnnotation(); String expectedCss = "." + css.renamedClass() + "{color:black}." + css.nonRenamedClass() + "{color:white}"; assertEquals(expectedCss, css.getText()); } public void testConstants() { assertEquals("15px", res().cssWithConstant().constantOne()); assertEquals(5, res().cssWithConstant().constantTwo()); assertEquals("black", res().cssWithConstant().CONSTANT_THREE()); assertNotSame("white", res().cssWithConstant().conflictConstantClass()); } public void testNotStrict() { SomeGssResource notStrict = res().notstrict(); String expectedCss = "." + notStrict.someClass() + "{color:black}.otherNotStrictClass{" + "color:white}"; assertEquals(expectedCss, notStrict.getText()); } public void testRuntimeConditional() {
RuntimeConditional runtimeConditional = res().runtimeConditional();
jDramaix/gss.gwt
src/test/java/com/google/gwt/resources/client/GssResourceTest.java
// Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface ClassNameAnnotation extends GssResource { // @ClassName("renamed-class") // String renamedClass(); // // String nonRenamedClass(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface EmptyClass extends GssResource { // String empty(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface NonStandardAtRules extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface NonStandardFunctions extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface RuntimeConditional extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface SomeGssResource extends GssResource { // String someClass(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface WithConstant extends GssResource { // String constantOne(); // // String classOne(); // }
import com.google.gwt.resources.client.TestResources.ClassNameAnnotation; import com.google.gwt.resources.client.TestResources.EmptyClass; import com.google.gwt.resources.client.TestResources.NonStandardAtRules; import com.google.gwt.resources.client.TestResources.NonStandardFunctions; import com.google.gwt.resources.client.TestResources.RuntimeConditional; import com.google.gwt.resources.client.TestResources.SomeGssResource; import com.google.gwt.resources.client.TestResources.WithConstant;
public void testRuntimeConditional() { RuntimeConditional runtimeConditional = res().runtimeConditional(); String foo = runtimeConditional.foo(); BooleanEval.FIRST = true; BooleanEval.SECOND = true; BooleanEval.THIRD = true; assertEquals(runtimeExpectedCss("purple", "20px", foo), runtimeConditional.getText()); BooleanEval.FIRST = false; BooleanEval.SECOND = true; BooleanEval.THIRD = true; assertEquals(runtimeExpectedCss("black", null, foo), runtimeConditional.getText()); BooleanEval.FIRST = false; BooleanEval.SECOND = true; BooleanEval.THIRD = false; assertEquals(runtimeExpectedCss("khaki", null, foo), runtimeConditional.getText()); BooleanEval.FIRST = false; BooleanEval.SECOND = false; assertEquals(runtimeExpectedCss("gray", null, foo), runtimeConditional.getText()); } public void testNonStandardAtRules() {
// Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface ClassNameAnnotation extends GssResource { // @ClassName("renamed-class") // String renamedClass(); // // String nonRenamedClass(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface EmptyClass extends GssResource { // String empty(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface NonStandardAtRules extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface NonStandardFunctions extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface RuntimeConditional extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface SomeGssResource extends GssResource { // String someClass(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface WithConstant extends GssResource { // String constantOne(); // // String classOne(); // } // Path: src/test/java/com/google/gwt/resources/client/GssResourceTest.java import com.google.gwt.resources.client.TestResources.ClassNameAnnotation; import com.google.gwt.resources.client.TestResources.EmptyClass; import com.google.gwt.resources.client.TestResources.NonStandardAtRules; import com.google.gwt.resources.client.TestResources.NonStandardFunctions; import com.google.gwt.resources.client.TestResources.RuntimeConditional; import com.google.gwt.resources.client.TestResources.SomeGssResource; import com.google.gwt.resources.client.TestResources.WithConstant; public void testRuntimeConditional() { RuntimeConditional runtimeConditional = res().runtimeConditional(); String foo = runtimeConditional.foo(); BooleanEval.FIRST = true; BooleanEval.SECOND = true; BooleanEval.THIRD = true; assertEquals(runtimeExpectedCss("purple", "20px", foo), runtimeConditional.getText()); BooleanEval.FIRST = false; BooleanEval.SECOND = true; BooleanEval.THIRD = true; assertEquals(runtimeExpectedCss("black", null, foo), runtimeConditional.getText()); BooleanEval.FIRST = false; BooleanEval.SECOND = true; BooleanEval.THIRD = false; assertEquals(runtimeExpectedCss("khaki", null, foo), runtimeConditional.getText()); BooleanEval.FIRST = false; BooleanEval.SECOND = false; assertEquals(runtimeExpectedCss("gray", null, foo), runtimeConditional.getText()); } public void testNonStandardAtRules() {
NonStandardAtRules nonStandardAtRules = res().nonStandardAtRules();
jDramaix/gss.gwt
src/test/java/com/google/gwt/resources/client/GssResourceTest.java
// Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface ClassNameAnnotation extends GssResource { // @ClassName("renamed-class") // String renamedClass(); // // String nonRenamedClass(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface EmptyClass extends GssResource { // String empty(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface NonStandardAtRules extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface NonStandardFunctions extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface RuntimeConditional extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface SomeGssResource extends GssResource { // String someClass(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface WithConstant extends GssResource { // String constantOne(); // // String classOne(); // }
import com.google.gwt.resources.client.TestResources.ClassNameAnnotation; import com.google.gwt.resources.client.TestResources.EmptyClass; import com.google.gwt.resources.client.TestResources.NonStandardAtRules; import com.google.gwt.resources.client.TestResources.NonStandardFunctions; import com.google.gwt.resources.client.TestResources.RuntimeConditional; import com.google.gwt.resources.client.TestResources.SomeGssResource; import com.google.gwt.resources.client.TestResources.WithConstant;
assertEquals(runtimeExpectedCss("purple", "20px", foo), runtimeConditional.getText()); BooleanEval.FIRST = false; BooleanEval.SECOND = true; BooleanEval.THIRD = true; assertEquals(runtimeExpectedCss("black", null, foo), runtimeConditional.getText()); BooleanEval.FIRST = false; BooleanEval.SECOND = true; BooleanEval.THIRD = false; assertEquals(runtimeExpectedCss("khaki", null, foo), runtimeConditional.getText()); BooleanEval.FIRST = false; BooleanEval.SECOND = false; assertEquals(runtimeExpectedCss("gray", null, foo), runtimeConditional.getText()); } public void testNonStandardAtRules() { NonStandardAtRules nonStandardAtRules = res().nonStandardAtRules(); String css = nonStandardAtRules.getText(); assertTrue(css.contains("@extenal")); assertTrue(css.contains("@-moz-document")); assertTrue(css.contains("@supports")); } public void testNonStandardFunctions() {
// Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface ClassNameAnnotation extends GssResource { // @ClassName("renamed-class") // String renamedClass(); // // String nonRenamedClass(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface EmptyClass extends GssResource { // String empty(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface NonStandardAtRules extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface NonStandardFunctions extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface RuntimeConditional extends GssResource { // String foo(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface SomeGssResource extends GssResource { // String someClass(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface WithConstant extends GssResource { // String constantOne(); // // String classOne(); // } // Path: src/test/java/com/google/gwt/resources/client/GssResourceTest.java import com.google.gwt.resources.client.TestResources.ClassNameAnnotation; import com.google.gwt.resources.client.TestResources.EmptyClass; import com.google.gwt.resources.client.TestResources.NonStandardAtRules; import com.google.gwt.resources.client.TestResources.NonStandardFunctions; import com.google.gwt.resources.client.TestResources.RuntimeConditional; import com.google.gwt.resources.client.TestResources.SomeGssResource; import com.google.gwt.resources.client.TestResources.WithConstant; assertEquals(runtimeExpectedCss("purple", "20px", foo), runtimeConditional.getText()); BooleanEval.FIRST = false; BooleanEval.SECOND = true; BooleanEval.THIRD = true; assertEquals(runtimeExpectedCss("black", null, foo), runtimeConditional.getText()); BooleanEval.FIRST = false; BooleanEval.SECOND = true; BooleanEval.THIRD = false; assertEquals(runtimeExpectedCss("khaki", null, foo), runtimeConditional.getText()); BooleanEval.FIRST = false; BooleanEval.SECOND = false; assertEquals(runtimeExpectedCss("gray", null, foo), runtimeConditional.getText()); } public void testNonStandardAtRules() { NonStandardAtRules nonStandardAtRules = res().nonStandardAtRules(); String css = nonStandardAtRules.getText(); assertTrue(css.contains("@extenal")); assertTrue(css.contains("@-moz-document")); assertTrue(css.contains("@supports")); } public void testNonStandardFunctions() {
NonStandardFunctions nonStandardFunctions = res().nonStandardFunctions();
jDramaix/gss.gwt
src/test/java/com/google/gwt/resources/client/PrettyObfuscationStyleTest.java
// Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface ClassNameAnnotation extends GssResource { // @ClassName("renamed-class") // String renamedClass(); // // String nonRenamedClass(); // }
import com.google.gwt.resources.client.TestResources.ClassNameAnnotation;
/* * Copyright 2014 Julien Dramaix. * * 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.gwt.resources.client; public class PrettyObfuscationStyleTest extends RenamingClassNameTest { @Override public String getModuleName() { return "com.google.gwt.resources.Pretty"; } public void testClassesRenaming() {
// Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface ClassNameAnnotation extends GssResource { // @ClassName("renamed-class") // String renamedClass(); // // String nonRenamedClass(); // } // Path: src/test/java/com/google/gwt/resources/client/PrettyObfuscationStyleTest.java import com.google.gwt.resources.client.TestResources.ClassNameAnnotation; /* * Copyright 2014 Julien Dramaix. * * 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.gwt.resources.client; public class PrettyObfuscationStyleTest extends RenamingClassNameTest { @Override public String getModuleName() { return "com.google.gwt.resources.Pretty"; } public void testClassesRenaming() {
ClassNameAnnotation classNameAnnotation = res().classNameAnnotation();
jDramaix/gss.gwt
src/main/java/com/google/gwt/resources/gss/ExtendedEliminateConditionalNodes.java
// Path: src/main/java/com/google/gwt/resources/gss/ast/CssRuntimeConditionalRuleNode.java // public class CssRuntimeConditionalRuleNode extends CssConditionalRuleNode { // // public CssRuntimeConditionalRuleNode(CssConditionalRuleNode node, // @Nullable CssJavaExpressionNode condition) { // super(node.getType(), node.getName().deepCopy(), null, // node.getBlock() != null ? node.getBlock().deepCopy() : null); // setSourceCodeLocation(node.getSourceCodeLocation()); // // if (condition != null) { // setRuntimeCondition(condition); // } // } // // /** // * Copy constructor. // * // * @param node // */ // public CssRuntimeConditionalRuleNode(CssRuntimeConditionalRuleNode node) { // this(node, node.getRuntimeCondition()); // } // // /** // * Can only be called after the node is completely built (meaning it has // * the condition set). // */ // public CssJavaExpressionNode getRuntimeCondition() { // if (getType() == Type.ELSE) { // Preconditions.checkState(getParametersCount() == 0); // return null; // } // // Preconditions.checkState(getParametersCount() == 1); // return (CssJavaExpressionNode) this.getParameters().get(0); // } // // void setRuntimeCondition(CssJavaExpressionNode condition) { // Preconditions.checkState(getType() != Type.ELSE); // Preconditions.checkState(getParametersCount() <= 1); // this.setParameters(ImmutableList.<CssValueNode>of(condition)); // } // // @Override // public CssConditionalRuleNode deepCopy() { // return new CssRuntimeConditionalRuleNode(this); // } // }
import java.util.List; import java.util.Set; import com.google.common.collect.Lists; import com.google.common.css.compiler.ast.CssAtRuleNode.Type; import com.google.common.css.compiler.ast.CssBooleanExpressionNode; import com.google.common.css.compiler.ast.CssCompilerPass; import com.google.common.css.compiler.ast.CssConditionalBlockNode; import com.google.common.css.compiler.ast.CssConditionalRuleNode; import com.google.common.css.compiler.ast.DefaultTreeVisitor; import com.google.common.css.compiler.ast.MutatingVisitController; import com.google.common.css.compiler.passes.BooleanExpressionEvaluator; import com.google.common.css.compiler.passes.EliminateConditionalNodes; import com.google.gwt.resources.gss.ast.CssRuntimeConditionalRuleNode; import java.util.ArrayList; import java.util.HashSet;
this.runtimeConditionalNodes = runtimeConditionalNodes; this.delegate = new EliminateConditionalNodes(visitController, trueConditions); } @Override public boolean enterConditionalBlock(CssConditionalBlockNode block) { if (alreadyTreatedNode.contains(block)) { // don't visit this block again but visit its children return true; } if (runtimeConditionalNodes.contains(block)) { return enterRuntimeConditionalBlock(block); } else { // block without any runtime condition. return delegate.enterConditionalBlock(block); } } private boolean enterRuntimeConditionalBlock(CssConditionalBlockNode block) { boolean runtimeEvaluationNodeFound = false; List<CssConditionalRuleNode> newChildren = new ArrayList<CssConditionalRuleNode>(block.numChildren()); for (CssConditionalRuleNode currentConditional : block.childIterable()) { if (currentConditional.getType() == Type.ELSE) { newChildren.add(currentConditional); break; }
// Path: src/main/java/com/google/gwt/resources/gss/ast/CssRuntimeConditionalRuleNode.java // public class CssRuntimeConditionalRuleNode extends CssConditionalRuleNode { // // public CssRuntimeConditionalRuleNode(CssConditionalRuleNode node, // @Nullable CssJavaExpressionNode condition) { // super(node.getType(), node.getName().deepCopy(), null, // node.getBlock() != null ? node.getBlock().deepCopy() : null); // setSourceCodeLocation(node.getSourceCodeLocation()); // // if (condition != null) { // setRuntimeCondition(condition); // } // } // // /** // * Copy constructor. // * // * @param node // */ // public CssRuntimeConditionalRuleNode(CssRuntimeConditionalRuleNode node) { // this(node, node.getRuntimeCondition()); // } // // /** // * Can only be called after the node is completely built (meaning it has // * the condition set). // */ // public CssJavaExpressionNode getRuntimeCondition() { // if (getType() == Type.ELSE) { // Preconditions.checkState(getParametersCount() == 0); // return null; // } // // Preconditions.checkState(getParametersCount() == 1); // return (CssJavaExpressionNode) this.getParameters().get(0); // } // // void setRuntimeCondition(CssJavaExpressionNode condition) { // Preconditions.checkState(getType() != Type.ELSE); // Preconditions.checkState(getParametersCount() <= 1); // this.setParameters(ImmutableList.<CssValueNode>of(condition)); // } // // @Override // public CssConditionalRuleNode deepCopy() { // return new CssRuntimeConditionalRuleNode(this); // } // } // Path: src/main/java/com/google/gwt/resources/gss/ExtendedEliminateConditionalNodes.java import java.util.List; import java.util.Set; import com.google.common.collect.Lists; import com.google.common.css.compiler.ast.CssAtRuleNode.Type; import com.google.common.css.compiler.ast.CssBooleanExpressionNode; import com.google.common.css.compiler.ast.CssCompilerPass; import com.google.common.css.compiler.ast.CssConditionalBlockNode; import com.google.common.css.compiler.ast.CssConditionalRuleNode; import com.google.common.css.compiler.ast.DefaultTreeVisitor; import com.google.common.css.compiler.ast.MutatingVisitController; import com.google.common.css.compiler.passes.BooleanExpressionEvaluator; import com.google.common.css.compiler.passes.EliminateConditionalNodes; import com.google.gwt.resources.gss.ast.CssRuntimeConditionalRuleNode; import java.util.ArrayList; import java.util.HashSet; this.runtimeConditionalNodes = runtimeConditionalNodes; this.delegate = new EliminateConditionalNodes(visitController, trueConditions); } @Override public boolean enterConditionalBlock(CssConditionalBlockNode block) { if (alreadyTreatedNode.contains(block)) { // don't visit this block again but visit its children return true; } if (runtimeConditionalNodes.contains(block)) { return enterRuntimeConditionalBlock(block); } else { // block without any runtime condition. return delegate.enterConditionalBlock(block); } } private boolean enterRuntimeConditionalBlock(CssConditionalBlockNode block) { boolean runtimeEvaluationNodeFound = false; List<CssConditionalRuleNode> newChildren = new ArrayList<CssConditionalRuleNode>(block.numChildren()); for (CssConditionalRuleNode currentConditional : block.childIterable()) { if (currentConditional.getType() == Type.ELSE) { newChildren.add(currentConditional); break; }
if (currentConditional instanceof CssRuntimeConditionalRuleNode) {
jDramaix/gss.gwt
src/test/java/com/google/gwt/resources/client/TestResources.java
// Path: src/test/java/com/google/gwt/resources/client/ScopeResource.java // @Shared // interface SharedParent extends GssResource { // String sharedClassName1(); // String sharedClassName2(); // }
import com.google.gwt.resources.client.CssResource.Import; import com.google.gwt.resources.client.CssResource.NotStrict; import com.google.gwt.resources.client.ScopeResource.SharedParent;
String externalClass2(); String unobfuscated(); String unobfuscated2(); } interface EmptyClass extends GssResource { String empty(); } interface WithConstant extends GssResource { String constantOne(); String classOne(); } interface ClassNameAnnotation extends GssResource { @ClassName("renamed-class") String renamedClass(); String nonRenamedClass(); } interface TestImportCss extends GssResource { String other(); } // used to test shared annotation between clientBundle
// Path: src/test/java/com/google/gwt/resources/client/ScopeResource.java // @Shared // interface SharedParent extends GssResource { // String sharedClassName1(); // String sharedClassName2(); // } // Path: src/test/java/com/google/gwt/resources/client/TestResources.java import com.google.gwt.resources.client.CssResource.Import; import com.google.gwt.resources.client.CssResource.NotStrict; import com.google.gwt.resources.client.ScopeResource.SharedParent; String externalClass2(); String unobfuscated(); String unobfuscated2(); } interface EmptyClass extends GssResource { String empty(); } interface WithConstant extends GssResource { String constantOne(); String classOne(); } interface ClassNameAnnotation extends GssResource { @ClassName("renamed-class") String renamedClass(); String nonRenamedClass(); } interface TestImportCss extends GssResource { String other(); } // used to test shared annotation between clientBundle
interface SharedChild3 extends SharedParent {
jDramaix/gss.gwt
src/test/java/com/google/gwt/resources/client/RenamingClassNameTest.java
// Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface ExternalClasses extends GssResource { // String obfuscatedClass(); // // String externalClass(); // // String externalClass2(); // // String unobfuscated(); // // String unobfuscated2(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface TestImportCss extends GssResource { // String other(); // }
import com.google.gwt.core.shared.GWT; import com.google.gwt.junit.client.GWTTestCase; import com.google.gwt.resources.client.TestResources.ExternalClasses; import com.google.gwt.resources.client.TestResources.TestImportCss;
/* * Copyright 2014 Julien Dramaix. * * 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.gwt.resources.client; /** * These tests are to be tested against several configuration */ public abstract class RenamingClassNameTest extends GWTTestCase { static final String OBFUSCATION_PATTERN = "[a-zA-Z][a-zA-Z0-9]*-[a-zA-Z][a-zA-Z0-9]*"; /** * Test that style classes mentioned as external are not obfuscated. */ public void testExternalClasses() {
// Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface ExternalClasses extends GssResource { // String obfuscatedClass(); // // String externalClass(); // // String externalClass2(); // // String unobfuscated(); // // String unobfuscated2(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface TestImportCss extends GssResource { // String other(); // } // Path: src/test/java/com/google/gwt/resources/client/RenamingClassNameTest.java import com.google.gwt.core.shared.GWT; import com.google.gwt.junit.client.GWTTestCase; import com.google.gwt.resources.client.TestResources.ExternalClasses; import com.google.gwt.resources.client.TestResources.TestImportCss; /* * Copyright 2014 Julien Dramaix. * * 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.gwt.resources.client; /** * These tests are to be tested against several configuration */ public abstract class RenamingClassNameTest extends GWTTestCase { static final String OBFUSCATION_PATTERN = "[a-zA-Z][a-zA-Z0-9]*-[a-zA-Z][a-zA-Z0-9]*"; /** * Test that style classes mentioned as external are not obfuscated. */ public void testExternalClasses() {
ExternalClasses externalClasses = res().externalClasses();
jDramaix/gss.gwt
src/test/java/com/google/gwt/resources/client/RenamingClassNameTest.java
// Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface ExternalClasses extends GssResource { // String obfuscatedClass(); // // String externalClass(); // // String externalClass2(); // // String unobfuscated(); // // String unobfuscated2(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface TestImportCss extends GssResource { // String other(); // }
import com.google.gwt.core.shared.GWT; import com.google.gwt.junit.client.GWTTestCase; import com.google.gwt.resources.client.TestResources.ExternalClasses; import com.google.gwt.resources.client.TestResources.TestImportCss;
/* * Copyright 2014 Julien Dramaix. * * 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.gwt.resources.client; /** * These tests are to be tested against several configuration */ public abstract class RenamingClassNameTest extends GWTTestCase { static final String OBFUSCATION_PATTERN = "[a-zA-Z][a-zA-Z0-9]*-[a-zA-Z][a-zA-Z0-9]*"; /** * Test that style classes mentioned as external are not obfuscated. */ public void testExternalClasses() { ExternalClasses externalClasses = res().externalClasses(); // external at-rule shouldn't be printed assertFalse(externalClasses.getText().contains("@external")); assertNotSame("obfuscatedClass", externalClasses.obfuscatedClass()); assertEquals("externalClass", externalClasses.externalClass()); assertEquals("externalClass2", externalClasses.externalClass2()); assertEquals("unobfuscated", externalClasses.unobfuscated()); assertEquals("unobfuscated2", externalClasses.unobfuscated2()); } public void testObfuscationScope() { ScopeResource res = GWT.create(ScopeResource.class); assertEquals(res.scopeA().foo(), res.scopeA2().foo()); assertNotSame(res.scopeA().foo(), res.scopeB().foo()); assertNotSame(res.scopeB().foo(), res.scopeC().foo()); assertNotSame(res.scopeA().foo(), res.scopeC().foo()); } public void testImportAndImportWithPrefix() {
// Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface ExternalClasses extends GssResource { // String obfuscatedClass(); // // String externalClass(); // // String externalClass2(); // // String unobfuscated(); // // String unobfuscated2(); // } // // Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface TestImportCss extends GssResource { // String other(); // } // Path: src/test/java/com/google/gwt/resources/client/RenamingClassNameTest.java import com.google.gwt.core.shared.GWT; import com.google.gwt.junit.client.GWTTestCase; import com.google.gwt.resources.client.TestResources.ExternalClasses; import com.google.gwt.resources.client.TestResources.TestImportCss; /* * Copyright 2014 Julien Dramaix. * * 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.gwt.resources.client; /** * These tests are to be tested against several configuration */ public abstract class RenamingClassNameTest extends GWTTestCase { static final String OBFUSCATION_PATTERN = "[a-zA-Z][a-zA-Z0-9]*-[a-zA-Z][a-zA-Z0-9]*"; /** * Test that style classes mentioned as external are not obfuscated. */ public void testExternalClasses() { ExternalClasses externalClasses = res().externalClasses(); // external at-rule shouldn't be printed assertFalse(externalClasses.getText().contains("@external")); assertNotSame("obfuscatedClass", externalClasses.obfuscatedClass()); assertEquals("externalClass", externalClasses.externalClass()); assertEquals("externalClass2", externalClasses.externalClass2()); assertEquals("unobfuscated", externalClasses.unobfuscated()); assertEquals("unobfuscated2", externalClasses.unobfuscated2()); } public void testObfuscationScope() { ScopeResource res = GWT.create(ScopeResource.class); assertEquals(res.scopeA().foo(), res.scopeA2().foo()); assertNotSame(res.scopeA().foo(), res.scopeB().foo()); assertNotSame(res.scopeB().foo(), res.scopeC().foo()); assertNotSame(res.scopeA().foo(), res.scopeC().foo()); } public void testImportAndImportWithPrefix() {
TestImportCss css = res().testImportCss();
jDramaix/gss.gwt
src/test/java/com/google/gwt/resources/client/StableObfuscationStyleTest.java
// Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface ClassNameAnnotation extends GssResource { // @ClassName("renamed-class") // String renamedClass(); // // String nonRenamedClass(); // }
import com.google.gwt.resources.client.TestResources.ClassNameAnnotation;
/* * Copyright 2014 Julien Dramaix. * * 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.gwt.resources.client; public class StableObfuscationStyleTest extends RenamingClassNameTest { @Override public String getModuleName() { return "com.google.gwt.resources.Stable"; } public void testClassesRenaming() {
// Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface ClassNameAnnotation extends GssResource { // @ClassName("renamed-class") // String renamedClass(); // // String nonRenamedClass(); // } // Path: src/test/java/com/google/gwt/resources/client/StableObfuscationStyleTest.java import com.google.gwt.resources.client.TestResources.ClassNameAnnotation; /* * Copyright 2014 Julien Dramaix. * * 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.gwt.resources.client; public class StableObfuscationStyleTest extends RenamingClassNameTest { @Override public String getModuleName() { return "com.google.gwt.resources.Stable"; } public void testClassesRenaming() {
ClassNameAnnotation classNameAnnotation = res().classNameAnnotation();
jDramaix/gss.gwt
src/main/java/com/google/gwt/resources/gss/ValueFunction.java
// Path: src/main/java/com/google/gwt/resources/gss/ast/CssDotPathNode.java // public class CssDotPathNode extends CssValueNode { // // public static String resolveExpression(String instance, String path, String prefix, String suffix) { // String expression = path.replace(".", "().") + "()"; // // if (!Strings.isNullOrEmpty(instance)) { // expression = instance + "." + expression; // } // // if (!Strings.isNullOrEmpty(prefix)) { // expression = "\"" + Generator.escape(prefix) + "\" + " + expression; // } // // if (!Strings.isNullOrEmpty(suffix)) { // expression += " + \"" + Generator.escape(suffix) + "\""; // } // // return expression; // } // // private String suffix; // private String prefix; // private String path; // private String instance; // // public CssDotPathNode(String dotPath, String prefix, String suffix, SourceCodeLocation sourceCodeLocation) { // this(null, dotPath, prefix, suffix, sourceCodeLocation); // } // // public CssDotPathNode(String instance, String dotPath, String prefix, String suffix, // SourceCodeLocation sourceCodeLocation) { // super(resolveExpression(instance, dotPath, prefix, suffix), sourceCodeLocation); // // this.prefix = prefix; // this.suffix = suffix; // this.path = dotPath; // this.instance = instance; // } // // @Override // public CssValueNode deepCopy() { // return new CssDotPathNode(instance, path, prefix, suffix, getSourceCodeLocation()); // } // // public String getPath() { // return path; // } // // public String getSuffix() { // return suffix; // } // // public String getPrefix() { // return prefix; // } // // public String getInstance() { // return instance; // } // // public List<String> getPathElements() { // return Arrays.asList(path.split("\\.")); // } // }
import com.google.common.collect.ImmutableList; import com.google.common.css.compiler.ast.CssValueNode; import com.google.common.css.compiler.ast.ErrorManager; import com.google.common.css.compiler.ast.GssFunction; import com.google.common.css.compiler.ast.GssFunctionException; import com.google.gwt.resources.gss.ast.CssDotPathNode; import java.util.List;
/* * Copyright 2013 Julien Dramaix. * * 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.gwt.resources.gss; public class ValueFunction implements GssFunction { public static String getName() { return "value"; } @Override public List<CssValueNode> getCallResultNodes(List<CssValueNode> args, ErrorManager errorManager) throws GssFunctionException { if (args.size() == 0 || args.size() > 3) { throw new GssFunctionException(getName() + " function take one, two or three arguments"); } String functionPath = args.get(0).getValue(); String prefix = null; String suffix = null; if (args.size() > 1) { suffix = args.get(1).getValue(); } if (args.size() > 2) { prefix = args.get(2).getValue(); }
// Path: src/main/java/com/google/gwt/resources/gss/ast/CssDotPathNode.java // public class CssDotPathNode extends CssValueNode { // // public static String resolveExpression(String instance, String path, String prefix, String suffix) { // String expression = path.replace(".", "().") + "()"; // // if (!Strings.isNullOrEmpty(instance)) { // expression = instance + "." + expression; // } // // if (!Strings.isNullOrEmpty(prefix)) { // expression = "\"" + Generator.escape(prefix) + "\" + " + expression; // } // // if (!Strings.isNullOrEmpty(suffix)) { // expression += " + \"" + Generator.escape(suffix) + "\""; // } // // return expression; // } // // private String suffix; // private String prefix; // private String path; // private String instance; // // public CssDotPathNode(String dotPath, String prefix, String suffix, SourceCodeLocation sourceCodeLocation) { // this(null, dotPath, prefix, suffix, sourceCodeLocation); // } // // public CssDotPathNode(String instance, String dotPath, String prefix, String suffix, // SourceCodeLocation sourceCodeLocation) { // super(resolveExpression(instance, dotPath, prefix, suffix), sourceCodeLocation); // // this.prefix = prefix; // this.suffix = suffix; // this.path = dotPath; // this.instance = instance; // } // // @Override // public CssValueNode deepCopy() { // return new CssDotPathNode(instance, path, prefix, suffix, getSourceCodeLocation()); // } // // public String getPath() { // return path; // } // // public String getSuffix() { // return suffix; // } // // public String getPrefix() { // return prefix; // } // // public String getInstance() { // return instance; // } // // public List<String> getPathElements() { // return Arrays.asList(path.split("\\.")); // } // } // Path: src/main/java/com/google/gwt/resources/gss/ValueFunction.java import com.google.common.collect.ImmutableList; import com.google.common.css.compiler.ast.CssValueNode; import com.google.common.css.compiler.ast.ErrorManager; import com.google.common.css.compiler.ast.GssFunction; import com.google.common.css.compiler.ast.GssFunctionException; import com.google.gwt.resources.gss.ast.CssDotPathNode; import java.util.List; /* * Copyright 2013 Julien Dramaix. * * 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.gwt.resources.gss; public class ValueFunction implements GssFunction { public static String getName() { return "value"; } @Override public List<CssValueNode> getCallResultNodes(List<CssValueNode> args, ErrorManager errorManager) throws GssFunctionException { if (args.size() == 0 || args.size() > 3) { throw new GssFunctionException(getName() + " function take one, two or three arguments"); } String functionPath = args.get(0).getValue(); String prefix = null; String suffix = null; if (args.size() > 1) { suffix = args.get(1).getValue(); } if (args.size() > 2) { prefix = args.get(2).getValue(); }
CssDotPathNode cssDotPathNode = new CssDotPathNode(functionPath, prefix, suffix, args.get(0).getSourceCodeLocation());
jDramaix/gss.gwt
src/main/java/com/google/gwt/resources/gss/RuntimeConditionalNodeCollector.java
// Path: src/main/java/com/google/gwt/resources/gss/ast/CssRuntimeConditionalRuleNode.java // public class CssRuntimeConditionalRuleNode extends CssConditionalRuleNode { // // public CssRuntimeConditionalRuleNode(CssConditionalRuleNode node, // @Nullable CssJavaExpressionNode condition) { // super(node.getType(), node.getName().deepCopy(), null, // node.getBlock() != null ? node.getBlock().deepCopy() : null); // setSourceCodeLocation(node.getSourceCodeLocation()); // // if (condition != null) { // setRuntimeCondition(condition); // } // } // // /** // * Copy constructor. // * // * @param node // */ // public CssRuntimeConditionalRuleNode(CssRuntimeConditionalRuleNode node) { // this(node, node.getRuntimeCondition()); // } // // /** // * Can only be called after the node is completely built (meaning it has // * the condition set). // */ // public CssJavaExpressionNode getRuntimeCondition() { // if (getType() == Type.ELSE) { // Preconditions.checkState(getParametersCount() == 0); // return null; // } // // Preconditions.checkState(getParametersCount() == 1); // return (CssJavaExpressionNode) this.getParameters().get(0); // } // // void setRuntimeCondition(CssJavaExpressionNode condition) { // Preconditions.checkState(getType() != Type.ELSE); // Preconditions.checkState(getParametersCount() <= 1); // this.setParameters(ImmutableList.<CssValueNode>of(condition)); // } // // @Override // public CssConditionalRuleNode deepCopy() { // return new CssRuntimeConditionalRuleNode(this); // } // }
import com.google.common.css.compiler.ast.CssCompilerPass; import com.google.common.css.compiler.ast.CssConditionalBlockNode; import com.google.common.css.compiler.ast.CssConditionalRuleNode; import com.google.common.css.compiler.ast.DefaultTreeVisitor; import com.google.common.css.compiler.ast.VisitController; import com.google.gwt.resources.gss.ast.CssRuntimeConditionalRuleNode; import java.util.HashSet; import java.util.Set;
/* * Copyright 2014 Julien Dramaix. * * 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.gwt.resources.gss; public class RuntimeConditionalNodeCollector extends DefaultTreeVisitor implements CssCompilerPass { private final VisitController visitController; private Set<CssConditionalBlockNode> runtimeConditionalNodes; public RuntimeConditionalNodeCollector(VisitController visitController) { this.visitController = visitController; } @Override public boolean enterConditionalBlock(CssConditionalBlockNode block) { for (CssConditionalRuleNode currentConditional : block.childIterable()) {
// Path: src/main/java/com/google/gwt/resources/gss/ast/CssRuntimeConditionalRuleNode.java // public class CssRuntimeConditionalRuleNode extends CssConditionalRuleNode { // // public CssRuntimeConditionalRuleNode(CssConditionalRuleNode node, // @Nullable CssJavaExpressionNode condition) { // super(node.getType(), node.getName().deepCopy(), null, // node.getBlock() != null ? node.getBlock().deepCopy() : null); // setSourceCodeLocation(node.getSourceCodeLocation()); // // if (condition != null) { // setRuntimeCondition(condition); // } // } // // /** // * Copy constructor. // * // * @param node // */ // public CssRuntimeConditionalRuleNode(CssRuntimeConditionalRuleNode node) { // this(node, node.getRuntimeCondition()); // } // // /** // * Can only be called after the node is completely built (meaning it has // * the condition set). // */ // public CssJavaExpressionNode getRuntimeCondition() { // if (getType() == Type.ELSE) { // Preconditions.checkState(getParametersCount() == 0); // return null; // } // // Preconditions.checkState(getParametersCount() == 1); // return (CssJavaExpressionNode) this.getParameters().get(0); // } // // void setRuntimeCondition(CssJavaExpressionNode condition) { // Preconditions.checkState(getType() != Type.ELSE); // Preconditions.checkState(getParametersCount() <= 1); // this.setParameters(ImmutableList.<CssValueNode>of(condition)); // } // // @Override // public CssConditionalRuleNode deepCopy() { // return new CssRuntimeConditionalRuleNode(this); // } // } // Path: src/main/java/com/google/gwt/resources/gss/RuntimeConditionalNodeCollector.java import com.google.common.css.compiler.ast.CssCompilerPass; import com.google.common.css.compiler.ast.CssConditionalBlockNode; import com.google.common.css.compiler.ast.CssConditionalRuleNode; import com.google.common.css.compiler.ast.DefaultTreeVisitor; import com.google.common.css.compiler.ast.VisitController; import com.google.gwt.resources.gss.ast.CssRuntimeConditionalRuleNode; import java.util.HashSet; import java.util.Set; /* * Copyright 2014 Julien Dramaix. * * 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.gwt.resources.gss; public class RuntimeConditionalNodeCollector extends DefaultTreeVisitor implements CssCompilerPass { private final VisitController visitController; private Set<CssConditionalBlockNode> runtimeConditionalNodes; public RuntimeConditionalNodeCollector(VisitController visitController) { this.visitController = visitController; } @Override public boolean enterConditionalBlock(CssConditionalBlockNode block) { for (CssConditionalRuleNode currentConditional : block.childIterable()) {
if (currentConditional instanceof CssRuntimeConditionalRuleNode) {
jDramaix/gss.gwt
src/test/java/com/google/gwt/resources/client/StableNoTypeObfuscationStyleTest.java
// Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface ClassNameAnnotation extends GssResource { // @ClassName("renamed-class") // String renamedClass(); // // String nonRenamedClass(); // }
import com.google.gwt.core.client.GWT; import com.google.gwt.junit.client.GWTTestCase; import com.google.gwt.resources.client.TestResources.ClassNameAnnotation;
/* * Copyright 2014 Julien Dramaix. * * 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.gwt.resources.client; public class StableNoTypeObfuscationStyleTest extends GWTTestCase { @Override public String getModuleName() { return "com.google.gwt.resources.StableNoType"; } public void testClassesRenaming() {
// Path: src/test/java/com/google/gwt/resources/client/TestResources.java // interface ClassNameAnnotation extends GssResource { // @ClassName("renamed-class") // String renamedClass(); // // String nonRenamedClass(); // } // Path: src/test/java/com/google/gwt/resources/client/StableNoTypeObfuscationStyleTest.java import com.google.gwt.core.client.GWT; import com.google.gwt.junit.client.GWTTestCase; import com.google.gwt.resources.client.TestResources.ClassNameAnnotation; /* * Copyright 2014 Julien Dramaix. * * 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.gwt.resources.client; public class StableNoTypeObfuscationStyleTest extends GWTTestCase { @Override public String getModuleName() { return "com.google.gwt.resources.StableNoType"; } public void testClassesRenaming() {
ClassNameAnnotation classNameAnnotation = GWT.<TestResources>create(TestResources.class)