• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*******************************************************************************
2  * Copyright 2011 See AUTHORS file.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  ******************************************************************************/
16 
17 package com.badlogic.gwtref.gen;
18 
19 import com.google.gwt.core.ext.Generator;
20 import com.google.gwt.core.ext.GeneratorContext;
21 import com.google.gwt.core.ext.TreeLogger;
22 import com.google.gwt.core.ext.UnableToCompleteException;
23 import com.google.gwt.core.ext.typeinfo.JClassType;
24 import com.google.gwt.core.ext.typeinfo.TypeOracle;
25 import static com.google.gwt.core.ext.TreeLogger.*;
26 
27 public class ReflectionCacheGenerator extends Generator {
28 	@Override
generate(TreeLogger logger, GeneratorContext context, String typeName)29 	public String generate (TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException {
30 		TypeOracle oracle = context.getTypeOracle();
31 		assert (oracle != null);
32 		JClassType type = oracle.findType(typeName);
33 		if (type == null) {
34 			logger.log(ERROR, "Couldn't find type '" + typeName + "'");
35 			throw new UnableToCompleteException();
36 		}
37 
38 		if (type.isInterface() == null) {
39 			logger.log(ERROR, "Type '" + typeName + "' must be an interface");
40 			throw new UnableToCompleteException();
41 		}
42 
43 		ReflectionCacheSourceCreator source = new ReflectionCacheSourceCreator(logger, context, type);
44 		return source.create();
45 	}
46 }
47