Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2008 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.gwt.dev.cfg;
import com.google.gwt.core.ext.BadPropertyValueException;
import com.google.gwt.core.ext.Generator;
import com.google.gwt.core.ext.GeneratorContext;
import com.google.gwt.core.ext.RebindResult;
import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.core.ext.UnableToCompleteException;
import com.google.gwt.dev.javac.StandardGeneratorContext;
import com.google.gwt.dev.javac.typemodel.LibraryTypeOracle.UnsupportedTypeOracleAccess;
import com.google.gwt.dev.javac.typemodel.TypeOracle;
import com.google.gwt.dev.jjs.InternalCompilerException;
import com.google.gwt.thirdparty.guava.common.annotations.VisibleForTesting;
import com.google.gwt.thirdparty.guava.common.base.Objects;
import com.google.gwt.thirdparty.guava.common.collect.ImmutableSet;
import com.google.gwt.thirdparty.guava.common.collect.Maps;
import com.google.gwt.thirdparty.guava.common.collect.Sets;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
/**
* A rule to replace the type being rebound with a class whose name is determined by a generator
* class. Generators usually generate new classes during the deferred binding process, but it is not
* required.
*/
public class RuleGenerateWith extends Rule {
public static final Set ALL_PROPERTIES = ImmutableSet.of("%ALL%");
/**
* Returns a Set of the names of properties that will be accessed by the given Generator.
*/
public static Set getAccessedPropertyNames(Class extends Generator> generatorClass) {
// TODO: Make this based on @RunsLocal
return ALL_PROPERTIES;
}
private final Set accessedPropertyNames;
private Generator generator;
private final Class extends Generator> generatorClass;
private Map rebindProperties;
private String rebindRequestTypeName;
private String rebindResultTypeName;
public RuleGenerateWith(Class extends Generator> generatorClass) {
this.generatorClass = generatorClass;
this.accessedPropertyNames = getAccessedPropertyNames(generatorClass);
}
/**
* Returns whether the output of the Generator being managed by this rule is modified by or
* whether the rules embedded condition is judging any of the properties whose names have been
* passed.
*
* Makes it possible for external callers to watch the changing property environment and only
* trigger Generators within Rules whose output might have changed.
*/
public boolean caresAboutProperties(Set propertyNames) {
// If this generator cares about all properties.
if (accessedPropertyNames.equals(ALL_PROPERTIES)) {
// Then if some properties were supplied, it cares about them.
return !propertyNames.isEmpty();
}
// Otherwise an explicit list of cared about properties was supplied. Return whether any of the
// supplied properties is cared about.
return !Sets.intersection(accessedPropertyNames, propertyNames).isEmpty();
}
/**
* Returns whether the output of the Generator being managed by this rule depends on access to the
* global set of types to be able to run accurately.
*/
public boolean contentDependsOnTypes() {
// TODO: Make this based on @RunsLocal
return true;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof RuleGenerateWith)) {
return false;
}
RuleGenerateWith other = (RuleGenerateWith) obj;
if (generatorClass == null) {
if (other.generatorClass != null) {
return false;
}
} else if (!generatorClass.equals(other.generatorClass)) {
return false;
}
return true;
}
/**
* Generate all possible Generator output for the wrapped Generator in combination with the scope
* of Properties and values known about by the passed GeneratorContext. Additionally generate and
* gather runtime rebind rules for all corresponding pairs of property values and Generator
* output.
*/
public void generate(TreeLogger logger, Properties moduleProperties, GeneratorContext context,
String typeName) throws UnableToCompleteException {
Map