Revision: 5854 Author: [email protected] Date: Fri Jul 31 10:13:46 2009 Log: Changes from review feedback, hook in looking up parameter names in source (not tested yet).
http://code.google.com/p/google-web-toolkit/source/detail?r=5854 Added: /changes/jat/ihm/dev/core/test/com/google/gwt/dev/util/NameTest.java Modified: /changes/jat/ihm/dev/core/src/com/google/gwt/core/ext/typeinfo/JAbstractMethod.java /changes/jat/ihm/dev/core/src/com/google/gwt/core/ext/typeinfo/JClassType.java /changes/jat/ihm/dev/core/src/com/google/gwt/core/ext/typeinfo/TypeOracle.java /changes/jat/ihm/dev/core/src/com/google/gwt/dev/SwtHostedModeBase.java /changes/jat/ihm/dev/core/src/com/google/gwt/dev/cfg/ModuleDef.java /changes/jat/ihm/dev/core/src/com/google/gwt/dev/cfg/ModuleDefSchema.java /changes/jat/ihm/dev/core/src/com/google/gwt/dev/javac/CompilationState.java /changes/jat/ihm/dev/core/src/com/google/gwt/dev/javac/CompilationUnit.java /changes/jat/ihm/dev/core/src/com/google/gwt/dev/javac/JavaSourceParser.java /changes/jat/ihm/dev/core/src/com/google/gwt/dev/javac/TypeOracleMediator.java /changes/jat/ihm/dev/core/src/com/google/gwt/dev/javac/impl/SourceFileCompilationUnit.java /changes/jat/ihm/dev/core/src/com/google/gwt/dev/shell/ShellModuleSpaceHost.java /changes/jat/ihm/dev/core/src/com/google/gwt/dev/util/Name.java /changes/jat/ihm/dev/core/test/com/google/gwt/dev/javac/JavaSourceParserTest.java ======================================= --- /dev/null +++ /changes/jat/ihm/dev/core/test/com/google/gwt/dev/util/NameTest.java Fri Jul 31 10:13:46 2009 @@ -0,0 +1,172 @@ +/* + * Copyright 2009 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.util; + +import com.google.gwt.dev.util.Name.BinaryName; +import com.google.gwt.dev.util.Name.DottedName; +import com.google.gwt.dev.util.Name.InternalName; +import com.google.gwt.dev.util.Name.SourceName; + +import junit.framework.TestCase; + +/** + * Tests for {...@link Name}. + */ +public class NameTest extends TestCase { + + /** + * Used to test getting names from a Class instance. + */ + private static class Inner { + } + + public void testBinaryName() { + assertEquals("org.test.Foo", BinaryName.toSourceName("org.test.Foo")); + assertEquals("org.test.Foo.Bar", + BinaryName.toSourceName("org.test.Foo$Bar")); + assertEquals("org.test.Foo.Bar.Baz", + BinaryName.toSourceName("org.test.Foo$Bar$Baz")); + assertEquals("org.test.Foo.Bar.Baz$", + BinaryName.toSourceName("org.test.Foo$Bar$Baz$")); + assertEquals("org/test/Foo", BinaryName.toInternalName("org.test.Foo")); + assertEquals("org/test/Foo$Bar", + BinaryName.toInternalName("org.test.Foo$Bar")); + assertEquals("org/test/Foo$Bar$Baz", + BinaryName.toInternalName("org.test.Foo$Bar$Baz")); + assertEquals("org/test/Foo$Bar$Baz$", + BinaryName.toInternalName("org.test.Foo$Bar$Baz$")); + assertEquals("org/test/Foo$Bar$Baz$1", + BinaryName.toInternalName("org.test.Foo$Bar$Baz$1")); + assertEquals("org.test.Foo$Bar", + BinaryName.getInnerClassName("org.test.Foo", "Bar")); + assertEquals("org.test.Foo", + BinaryName.getOuterClassName("org.test.Foo$Bar")); + assertEquals("org.test", + BinaryName.getPackageName("org.test.Foo$Bar")); + assertEquals("Foo$Bar", BinaryName.getClassName("org.test.Foo$Bar")); + assertEquals("Bar", BinaryName.getShortClassName("org.test.Foo$Bar")); + } + + public void testDottedName() { + assertEquals("org.test.Foo.Bar", + DottedName.toSourceName("org.test.Foo.Bar")); + assertEquals("org.test.Foo.Bar", + DottedName.toSourceName("org.test.Foo$Bar")); + assertEquals("org.test.Foo.Bar$", + DottedName.toSourceName("org.test.Foo.Bar$")); + assertEquals("org.test.Foo.Bar$", + DottedName.toSourceName("org.test.Foo$Bar$")); + } + + public void testGetBinaryNameForClass() { + assertEquals("com.google.gwt.dev.util.NameTest$Inner", + Name.getBinaryNameForClass(Inner.class)); + } + + public void testGetInternalNameForClass() { + assertEquals("com/google/gwt/dev/util/NameTest$Inner", + Name.getInternalNameForClass(Inner.class)); + } + + public void testGetSourceNameForClass() { + assertEquals("com.google.gwt.dev.util.NameTest.Inner", + Name.getSourceNameForClass(Inner.class)); + } + + public void testInternalName() { + assertEquals("org.test.Foo", InternalName.toSourceName("org/test/Foo")); + assertEquals("org.test.Foo.Bar", + InternalName.toSourceName("org/test/Foo$Bar")); + assertEquals("org.test.Foo.Bar.Baz", + InternalName.toSourceName("org/test/Foo$Bar$Baz")); + assertEquals("org.test.Foo.Bar.Baz$", + InternalName.toSourceName("org/test/Foo$Bar$Baz$")); + assertEquals("org.test.Foo", InternalName.toBinaryName("org.test.Foo")); + assertEquals("org.test.Foo$Bar", + InternalName.toBinaryName("org.test.Foo$Bar")); + assertEquals("org.test.Foo$Bar$Baz", + InternalName.toBinaryName("org.test.Foo$Bar$Baz")); + assertEquals("org.test.Foo$Bar$Baz$", + InternalName.toBinaryName("org/test/Foo$Bar$Baz$")); + assertEquals("org.test.Foo$Bar$Baz$1", + InternalName.toBinaryName("org/test/Foo$Bar$Baz$1")); + assertEquals("org/test/Foo$Bar", + InternalName.getInnerClassName("org/test/Foo", "Bar")); + assertEquals("org/test/Foo", + InternalName.getOuterClassName("org/test/Foo$Bar")); + assertEquals("org/test", + InternalName.getPackageName("org/test/Foo$Bar")); + assertEquals("Foo$Bar", InternalName.getClassName("org/test/Foo$Bar")); + assertEquals("Bar", InternalName.getShortClassName("org/test/Foo$Bar")); + } + + public void testIsBinaryName() { + assertTrue(Name.isBinaryName("org.test.Foo")); + assertTrue(Name.isBinaryName("org.test.Foo$Bar")); + assertTrue(Name.isBinaryName("org.test.Foo$Bar$Baz")); + assertTrue(Name.isBinaryName("org.test.Foo$Bar$Baz$")); + assertTrue(Name.isBinaryName("org.test.Foo$Bar$Baz$1")); + assertFalse(Name.isBinaryName("org/test/Foo")); + assertFalse(Name.isBinaryName("org/test/Foo$Bar")); + assertFalse(Name.isBinaryName("org/test/Foo$Bar$Baz")); + assertFalse(Name.isBinaryName("org/test/Foo$Bar$Baz$")); + assertFalse(Name.isBinaryName("org/test/Foo$Bar$Baz$1")); + assertTrue(Name.isBinaryName("org.test.Foo.Bar")); + // We can't tell these aren't binary names without being able to tell + // what the name of the top-level class is, but don't want to encode + // bad behavior in the test. + // assertTrue(Name.isBinaryName("org.test.Foo.Bar.Baz")); + // assertTrue(Name.isBinaryName("org.test.Foo.Bar.Baz$")); + } + + public void testIsInternalName() { + assertFalse(Name.isInternalName("org.test.Foo")); + assertFalse(Name.isInternalName("org.test.Foo$Bar")); + assertFalse(Name.isInternalName("org.test.Foo$Bar$Baz")); + assertFalse(Name.isInternalName("org.test.Foo$Bar$Baz$")); + assertFalse(Name.isInternalName("org.test.Foo$Bar$Baz$1")); + assertTrue(Name.isInternalName("org/test/Foo")); + assertTrue(Name.isInternalName("org/test/Foo$Bar")); + assertTrue(Name.isInternalName("org/test/Foo$Bar$Baz")); + assertTrue(Name.isInternalName("org/test/Foo$Bar$Baz$")); + assertTrue(Name.isInternalName("org/test/Foo$Bar$Baz$1")); + assertFalse(Name.isInternalName("org.test.Foo.Bar")); + assertFalse(Name.isInternalName("org.test.Foo.Bar.Baz")); + assertFalse(Name.isInternalName("org.test.Foo.Bar.Baz$")); + } + + public void testIsSourceName() { + assertTrue(Name.isSourceName("org.test.Foo")); + assertFalse(Name.isSourceName("org.test.Foo$Bar")); + assertFalse(Name.isSourceName("org.test.Foo$Bar$Baz")); + assertFalse(Name.isSourceName("org.test.Foo$Bar$Baz$")); + assertFalse(Name.isSourceName("org.test.Foo$Bar$Baz$1")); + assertFalse(Name.isSourceName("org/test/Foo")); + assertFalse(Name.isSourceName("org/test/Foo$Bar")); + assertFalse(Name.isSourceName("org/test/Foo$Bar$Baz")); + assertFalse(Name.isSourceName("org/test/Foo$Bar$Baz$")); + assertFalse(Name.isSourceName("org/test/Foo$Bar$Baz$1")); + assertTrue(Name.isSourceName("org.test.Foo.Bar")); + assertTrue(Name.isSourceName("org.test.Foo.Bar.Baz")); + assertTrue(Name.isSourceName("org.test.Foo.Bar.Baz$")); + } + + public void testSourceName() { + assertEquals("org.test.Foo.Bar", + SourceName.getInnerClassName("org.test.Foo", "Bar")); + assertEquals("Bar", SourceName.getShortClassName("org.test.Foo.Bar")); + } +} ======================================= --- /changes/jat/ihm/dev/core/src/com/google/gwt/core/ext/typeinfo/JAbstractMethod.java Thu Jul 30 09:28:03 2009 +++ /changes/jat/ihm/dev/core/src/com/google/gwt/core/ext/typeinfo/JAbstractMethod.java Fri Jul 31 10:13:46 2009 @@ -243,14 +243,12 @@ String getRealParameterName(JParameter parameter) { if (realParameterNames == null) { fetchRealParameterNames(); - // TODO(jat): handle null if not available - assert realParameterNames != null; } int n = params.size(); for (int i = 0; i < n; ++i) { // Identity tests are ok since identity is durable within an oracle. if (params.get(i) == parameter) { - return realParameterNames[i]; + return realParameterNames == null ? "arg" + i : realParameterNames[i]; } } // TODO: report error if we are asked for an unknown JParameter? @@ -274,11 +272,6 @@ } private void fetchRealParameterNames() { - JClassType topLevelType = getEnclosingType(); - while (topLevelType.getEnclosingType() != null) { - topLevelType = topLevelType.getEnclosingType(); - } - realParameterNames = topLevelType.getRealParameterNames(getEnclosingType(), - this); + realParameterNames = getEnclosingType().getOracle().getJavaSourceParser().getArguments(this); } } ======================================= --- /changes/jat/ihm/dev/core/src/com/google/gwt/core/ext/typeinfo/JClassType.java Thu Jul 30 09:28:03 2009 +++ /changes/jat/ihm/dev/core/src/com/google/gwt/core/ext/typeinfo/JClassType.java Fri Jul 31 10:13:46 2009 @@ -605,19 +605,6 @@ * NOTE: This method is for testing purposes only. */ abstract Annotation[] getDeclaredAnnotations(); - - /** - * Called by JAbstractMethod to lookup real argument names from source on - * demand (since bytecode does not always contain them). - * - * @param enclosingType - * @param abstractMethod - * @return array of parameter names, or null if unavailable - */ - String[] getRealParameterNames(JClassType enclosingType, - JAbstractMethod abstractMethod) { - return null; - } @Override abstract JClassType getSubstitutedType(JParameterizedType parameterizedType); ======================================= --- /changes/jat/ihm/dev/core/src/com/google/gwt/core/ext/typeinfo/TypeOracle.java Tue Jul 28 15:07:40 2009 +++ /changes/jat/ihm/dev/core/src/com/google/gwt/core/ext/typeinfo/TypeOracle.java Fri Jul 31 10:13:46 2009 @@ -16,7 +16,9 @@ package com.google.gwt.core.ext.typeinfo; import com.google.gwt.core.ext.typeinfo.JWildcardType.BoundType; +import com.google.gwt.dev.javac.JavaSourceParser; import com.google.gwt.dev.jjs.InternalCompilerException; +import com.google.gwt.dev.resource.Resource; import com.google.gwt.dev.shell.JsValueGlue; import com.google.gwt.dev.util.Name; import com.google.gwt.dev.util.collect.HashMap; @@ -198,6 +200,8 @@ private JClassType javaLangObject; + private JavaSourceParser javaSourceParser = new JavaSourceParser(); + /** * Maps SingleJsoImpl interfaces to the implementing JSO subtype. */ @@ -228,6 +232,10 @@ // getOrCreatePackage(""); } + + public void addSourceReference(JRealClassType type, Resource sourceFile) { + javaSourceParser.addSourceForType(type, sourceFile); + } /** * Called after a block of new types to compute the hierarchy relationships. @@ -322,6 +330,10 @@ } return javaLangObject; } + + public JavaSourceParser getJavaSourceParser() { + return javaSourceParser; + } /** * Ensure that a package with the specified name exists as well as its parent @@ -856,7 +868,7 @@ } } } - + /** * Removes the specified type from the type oracle. */ ======================================= --- /changes/jat/ihm/dev/core/src/com/google/gwt/dev/SwtHostedModeBase.java Fri May 8 17:38:40 2009 +++ /changes/jat/ihm/dev/core/src/com/google/gwt/dev/SwtHostedModeBase.java Fri Jul 31 10:13:46 2009 @@ -65,11 +65,7 @@ ModuleDef moduleDef = loadModule(logger, moduleName, true); assert (moduleDef != null); - boolean wantBinaries = true; - if ("no".equals(System.getProperty("gwt.hosted.useBinaries"))) { - wantBinaries = false; - } - TypeOracle typeOracle = moduleDef.getTypeOracle(logger, wantBinaries); + TypeOracle typeOracle = moduleDef.getTypeOracle(logger); ShellModuleSpaceHost host = doCreateShellModuleSpaceHost( getTopLogger(), typeOracle, moduleDef); return host; ======================================= --- /changes/jat/ihm/dev/core/src/com/google/gwt/dev/cfg/ModuleDef.java Wed Jul 29 15:12:22 2009 +++ /changes/jat/ihm/dev/core/src/com/google/gwt/dev/cfg/ModuleDef.java Fri Jul 31 10:13:46 2009 @@ -127,18 +127,6 @@ this.name = name; defaultFilters = new DefaultFilters(); } - - public synchronized void addBinaryPackage(String binaryPackage, - String[] includeList, String[] excludeList, boolean defaultExcludes, - boolean caseSensitive) { - if (lazyJavaBinaryOracle != null) { - throw new IllegalStateException("Already normalized"); - } - - binaryPrefixSet.add(new PathPrefix(binaryPackage, - defaultFilters.customClassFilter(includeList, excludeList, - defaultExcludes, caseSensitive), false)); - } public synchronized void addEntryPointTypeName(String typeName) { entryPointTypeNames.add(typeName); @@ -176,6 +164,9 @@ String[] excludeList, boolean defaultExcludes, boolean caseSensitive) { addSourcePackageImpl(sourcePackage, includeList, excludeList, defaultExcludes, caseSensitive, false); + binaryPrefixSet.add(new PathPrefix(sourcePackage, + defaultFilters.customClassFilter(includeList, excludeList, + defaultExcludes, caseSensitive), false)); } public void addSourcePackageImpl(String sourcePackage, String[] includeList, @@ -301,17 +292,10 @@ public synchronized CompilationState getCompilationState(TreeLogger logger) throws UnableToCompleteException { - return getCompilationState(logger, false); - } - - public CompilationState getCompilationState(TreeLogger logger, - boolean wantBinaries) throws UnableToCompleteException { if (lazyCompilationState == null) { lazyCompilationState = new CompilationState(logger, lazySourceOracle, - lazyJavaBinaryOracle, wantBinaries); + lazyJavaBinaryOracle); checkForSeedTypes(logger); - } else if (wantBinaries) { - lazyCompilationState.setWantBinaries(); } return lazyCompilationState; } @@ -386,13 +370,7 @@ public synchronized TypeOracle getTypeOracle(TreeLogger logger) throws UnableToCompleteException { - return getTypeOracle(logger, false); - } - - public synchronized TypeOracle getTypeOracle(TreeLogger logger, - boolean useBinaries) throws UnableToCompleteException { - CompilationState compilationState = getCompilationState(logger, - useBinaries); + CompilationState compilationState = getCompilationState(logger); return compilationState.getTypeOracle(); } ======================================= --- /changes/jat/ihm/dev/core/src/com/google/gwt/dev/cfg/ModuleDefSchema.java Thu Jul 30 15:44:00 2009 +++ /changes/jat/ihm/dev/core/src/com/google/gwt/dev/cfg/ModuleDefSchema.java Fri Jul 31 10:13:46 2009 @@ -55,16 +55,6 @@ protected final String __define_configuration_property_1_name = null; - protected final String __binary_1_path = ""; - - protected final String __binary_2_includes = ""; - - protected final String __binary_3_excludes = ""; - - protected final String __binary_4_defaultexcludes = "yes"; - - protected final String __binary_5_casesensitive = "true"; - protected final String __define_configuration_property_2_is_multi_valued = null; protected final String __define_linker_1_name = null; @@ -154,22 +144,6 @@ moduleDef.addLinker(name.name); return null; } - - /** - * Indicates which subdirectories contain class files without - * necessarily adding a sourcepath entry. - */ - protected Schema __binary_begin(String path, String includes, - String excludes, String defaultExcludes, String caseSensitive) { - return fChild = new IncludeExcludeSchema(); - } - - protected void __binary_end(String path, String includes, String excludes, - String defaultExcludes, String caseSensitive) { - foundAnyBinary = true; - addBinaryPackage(path, includes, excludes, defaultExcludes, - caseSensitive); - } protected Schema __clear_configuration_property_begin(PropertyName name) throws UnableToCompleteException { @@ -584,49 +558,6 @@ addSourcePackage(path, includes, excludes, defaultExcludes, caseSensitive, true); } - - private void addBinaryPackage(String relDir, String includes, - String excludes, String defaultExcludes, String caseSensitive) { - IncludeExcludeSchema childSchema = ((IncludeExcludeSchema) fChild); - - Set<String> includeSet = childSchema.getIncludes(); - addDelimitedStringToSet(includes, "[ ,]", includeSet); - String[] includeList = includeSet.toArray(new String[includeSet.size()]); - - Set<String> excludeSet = childSchema.getExcludes(); - addDelimitedStringToSet(excludes, "[ ,]", excludeSet); - String[] excludeList = excludeSet.toArray(new String[excludeSet.size()]); - - boolean doDefaultExcludes = toPrimitiveBoolean(defaultExcludes); - boolean doCaseSensitive = toPrimitiveBoolean(caseSensitive); - - addBinaryPackage(modulePackageAsPath, relDir, includeList, excludeList, - doDefaultExcludes, doCaseSensitive); - } - - private void addBinaryPackage(String parentDir, String relDir, - String[] includeList, String[] excludeList, boolean defaultExcludes, - boolean caseSensitive) { - String normChildDir = normalizePathEntry(relDir); - if (normChildDir.startsWith("/")) { - logger.log(TreeLogger.WARN, "Non-relative public package: " - + normChildDir, null); - return; - } - if (normChildDir.startsWith("./") || normChildDir.indexOf("/./") >= 0) { - logger.log(TreeLogger.WARN, "Non-canonical public package: " - + normChildDir, null); - return; - } - if (normChildDir.startsWith("../") || normChildDir.indexOf("/../") >= 0) { - logger.log(TreeLogger.WARN, "Non-canonical public package: " - + normChildDir, null); - return; - } - String fullDir = parentDir + normChildDir; - moduleDef.addBinaryPackage(fullDir, includeList, excludeList, - defaultExcludes, caseSensitive); - } private void addDelimitedStringToSet(String delimited, String delimiter, Set<String> toSet) { @@ -1186,7 +1117,6 @@ private final ClassAttrCvt classAttrCvt = new ClassAttrCvt(); private final PropertyAttrCvt configurationPropAttrCvt = new PropertyAttrCvt( ConfigurationProperty.class); - private boolean foundAnyBinary; private boolean foundAnyPublic; private boolean foundExplicitSourceOrSuperSource; private final ObjAttrCvt<Generator> genAttrCvt = new ObjAttrCvt<Generator>( @@ -1243,11 +1173,6 @@ bodySchema.addPublicPackage(modulePackageAsPath, "public", Empty.STRINGS, Empty.STRINGS, true, true); } - - if (!foundAnyBinary) { - bodySchema.addBinaryPackage(modulePackageAsPath, "", Empty.STRINGS, - Empty.STRINGS, true, true); - } // We do this in __module_end so this value is never inherited moduleDef.setNameOverride(renameTo.token); ======================================= --- /changes/jat/ihm/dev/core/src/com/google/gwt/dev/javac/CompilationState.java Thu Jul 30 15:48:11 2009 +++ /changes/jat/ihm/dev/core/src/com/google/gwt/dev/javac/CompilationState.java Fri Jul 31 10:13:46 2009 @@ -40,6 +40,12 @@ */ public class CompilationState { + /** + * True if we want to use binaries (.class/etc files). + */ + private static final boolean WANT_BINARIES = System.getProperty( + "gwt.typeOracle.noUseClasses") != null; + private static Set<CompilationUnit> concatSet(Collection<CompilationUnit> a, Collection<CompilationUnit> b) { Set<CompilationUnit> result = new HashSet<CompilationUnit>(a.size() @@ -110,14 +116,10 @@ */ private final ResourceOracle sourceOracle; - /** - * True if we want to use binaries (.class/etc files). - */ - private boolean wantBinaries; - /** * Construct a new {...@link CompilationState}. * + * @param logger TreeLogger instance * @param sourceOracle an oracle used to retrieve source code and check for * changes in the underlying source code base */ @@ -127,29 +129,16 @@ /** * Construct a new {...@link CompilationState}. - * + * + * @param logger TreeLogger instance * @param sourceOracle an oracle used to retrieve source code and check for * changes in the underlying source code base * @param binaryOracle */ public CompilationState(TreeLogger logger, ResourceOracle sourceOracle, JavaBinaryOracle binaryOracle) { - this(logger, sourceOracle, binaryOracle, false); - } - - /** - * Construct a new {...@link CompilationState}. - * - * @param sourceOracle an oracle used to retrieve source code and check for - * changes in the underlying source code base - * @param binaryOracle - * @param wantBinaries true if we should use binary files - */ - public CompilationState(TreeLogger logger, ResourceOracle sourceOracle, - JavaBinaryOracle binaryOracle, boolean wantBinaries) { this.sourceOracle = sourceOracle; this.binaryOracle = binaryOracle; - this.wantBinaries = wantBinaries; refresh(logger); } @@ -285,12 +274,6 @@ mediator.refresh(logger, unitMap.values()); markSurvivorsChecked(unitMap.values()); } - - public void setWantBinaries() { - // TODO(jat): refresh if we have already built without binaries, - // but consider performance implications - wantBinaries = true; - } /** * This method processes generatedCups using usefulGraveyardUnits wherever @@ -377,7 +360,7 @@ */ private void compile(TreeLogger logger, Collection<CompilationUnit> newUnits, Collection<CompilationUnit> existingUnits) { - if (wantBinaries) { + if (WANT_BINARIES) { for (CompilationUnit unit : newUnits) { unit.checkBinaries(logger); } @@ -469,6 +452,9 @@ // First remove any stale units. for (Iterator<CompilationUnit> it = unitMap.values().iterator(); it.hasNext();) { CompilationUnit unit = it.next(); + if (!(unit instanceof SourceFileCompilationUnit)) { + continue; + } SourceFileCompilationUnit sourceFileUnit = (SourceFileCompilationUnit) unit; JavaBinary binary = sourceFileUnit.getBinary(); if (!unchangedSrc.contains(sourceFileUnit.getSourceFile()) ======================================= --- /changes/jat/ihm/dev/core/src/com/google/gwt/dev/javac/CompilationUnit.java Tue Jul 28 15:07:40 2009 +++ /changes/jat/ihm/dev/core/src/com/google/gwt/dev/javac/CompilationUnit.java Fri Jul 31 10:13:46 2009 @@ -343,6 +343,14 @@ } return anonymousClassMap; } + + /** + * @return the binary files used for this compilation unit, or null if + * not available. + */ + public JavaBinary getBinary() { + return null; + } /** * Returns the user-relevant location of the source file. No programmatic ======================================= --- /changes/jat/ihm/dev/core/src/com/google/gwt/dev/javac/JavaSourceParser.java Thu Jul 30 15:12:48 2009 +++ /changes/jat/ihm/dev/core/src/com/google/gwt/dev/javac/JavaSourceParser.java Fri Jul 31 10:13:46 2009 @@ -223,6 +223,18 @@ * needed again), and are held in SoftReferences to allow GC to dump them. */ private WeakHashMap<JClassType, SoftReference<CompilationUnitDeclaration>> cudCache = new WeakHashMap<JClassType, SoftReference<CompilationUnitDeclaration>>(); + + /** + * Add a source file associated with the outermost enclosing class. + * + * @param topType + * @param source + * + * TODO: reduce visibility + */ + public synchronized void addSourceForType(JClassType topType, Resource source) { + classSources.put(topType, source); + } /** * Return the real argument names for a given method from the source. @@ -246,10 +258,6 @@ } return argNames; } - - synchronized void addSourceForType(JClassType topType, Resource source) { - classSources.put(topType, source); - } /** * Finds a JDT CUD for a given top-level type, generating it if needed. @@ -268,8 +276,11 @@ } if (cud == null) { Resource classSource = classSources.get(topType); - InputStream stream = classSource.openContents(); - String source = Util.readStreamAsString(stream); + String source = null; + if (classSource != null) { + InputStream stream = classSource.openContents(); + source = Util.readStreamAsString(stream); + } if (source == null) { // cache negative result so we don't try again cudCache.put(topType, null); ======================================= --- /changes/jat/ihm/dev/core/src/com/google/gwt/dev/javac/TypeOracleMediator.java Thu Jul 30 09:28:03 2009 +++ /changes/jat/ihm/dev/core/src/com/google/gwt/dev/javac/TypeOracleMediator.java Fri Jul 31 10:13:46 2009 @@ -54,6 +54,8 @@ import com.google.gwt.dev.javac.asm.CollectAnnotationData.AnnotationData; import com.google.gwt.dev.javac.asm.CollectClassData.AnnotationEnum; import com.google.gwt.dev.javac.impl.Shared; +import com.google.gwt.dev.javac.impl.SourceFileCompilationUnit; +import com.google.gwt.dev.resource.Resource; import com.google.gwt.dev.util.Name; import com.google.gwt.dev.util.Name.BinaryName; import com.google.gwt.dev.util.Name.InternalName; @@ -436,6 +438,19 @@ } typeOracle.finish(); + + // save source references + for (CompilationUnit unit : units) { + if (unit.isCompiled() && unit instanceof SourceFileCompilationUnit) { + SourceFileCompilationUnit sourceUnit = (SourceFileCompilationUnit) unit; + Resource sourceFile = sourceUnit.getSourceFile(); + Set<CompiledClass> compiledClasses = unit.getCompiledClasses(); + for (CompiledClass compiledClass : compiledClasses) { + JRealClassType type = compiledClass.getRealClassType(); + typeOracle.addSourceReference(type, sourceFile); + } + } + } // no longer needed classMap = null; ======================================= --- /changes/jat/ihm/dev/core/src/com/google/gwt/dev/javac/impl/SourceFileCompilationUnit.java Wed Jul 15 08:39:35 2009 +++ /changes/jat/ihm/dev/core/src/com/google/gwt/dev/javac/impl/SourceFileCompilationUnit.java Fri Jul 31 10:13:46 2009 @@ -239,6 +239,7 @@ } } + @Override public JavaBinary getBinary() { return binary; } ======================================= --- /changes/jat/ihm/dev/core/src/com/google/gwt/dev/shell/ShellModuleSpaceHost.java Tue Jun 16 14:33:06 2009 +++ /changes/jat/ihm/dev/core/src/com/google/gwt/dev/shell/ShellModuleSpaceHost.java Fri Jul 31 10:13:46 2009 @@ -21,7 +21,6 @@ import com.google.gwt.core.ext.typeinfo.TypeOracle; import com.google.gwt.dev.cfg.ModuleDef; import com.google.gwt.dev.cfg.Rules; -import com.google.gwt.dev.javac.CompilationState; import java.io.File; @@ -91,12 +90,9 @@ // It has to wait until now because we need to inject javascript. // Rules rules = module.getRules(); - CompilationState compilationState = module.getCompilationState(logger); - if (!"no".equals(System.getProperty("gwt.hosted.useBinaries"))) { - compilationState.setWantBinaries(); - } StandardGeneratorContext genCtx = new StandardGeneratorContext( - compilationState, module, genDir, shellDir, new ArtifactSet()); + module.getCompilationState(logger), module, genDir, shellDir, + new ArtifactSet()); rebindOracle = new StandardRebindOracle(propOracle, rules, genCtx); // Create a completely isolated class loader which owns all classes @@ -111,7 +107,7 @@ // class loader (the one that loaded the shell itself). // classLoader = new CompilingClassLoader(logger, - compilationState, readySpace); + module.getCompilationState(logger), readySpace); } public String rebind(TreeLogger logger, String sourceTypeName) ======================================= --- /changes/jat/ihm/dev/core/src/com/google/gwt/dev/util/Name.java Fri May 8 17:38:40 2009 +++ /changes/jat/ihm/dev/core/src/com/google/gwt/dev/util/Name.java Fri Jul 31 10:13:46 2009 @@ -15,9 +15,6 @@ */ package com.google.gwt.dev.util; -import com.google.gwt.core.ext.typeinfo.JClassType; -import com.google.gwt.core.ext.typeinfo.TypeOracle; - /** * Utility methods for dealing with the various types of Java names. */ @@ -32,6 +29,7 @@ public static class BinaryName { public static String getClassName(String binaryName) { + assert isBinaryName(binaryName); int lastDot = binaryName.lastIndexOf('.'); if (lastDot < 0) { return binaryName; @@ -41,27 +39,31 @@ public static String getInnerClassName(String binaryName, String innerClassName) { + assert isBinaryName(binaryName); return binaryName + '$' + innerClassName; } - public static String getOuterClassName(String name) { - int lastDollar = name.lastIndexOf('$'); + public static String getOuterClassName(String binaryName) { + assert isBinaryName(binaryName); + int lastDollar = binaryName.lastIndexOf('$'); if (lastDollar < 0) { return null; } - return name.substring(0, lastDollar); + return binaryName.substring(0, lastDollar); } - public static String getPackageName(String name) { - int lastDot = name.lastIndexOf('.'); + public static String getPackageName(String binaryName) { + assert isBinaryName(binaryName); + int lastDot = binaryName.lastIndexOf('.'); if (lastDot < 0) { return ""; } - return name.substring(0, lastDot); + return binaryName.substring(0, lastDot); } - public static String getShortClassName(String name) { - String className = getClassName(name); + public static String getShortClassName(String binaryName) { + assert isBinaryName(binaryName); + String className = getClassName(binaryName); int lastDollar = className.lastIndexOf('$', className.length() - 2); if (lastDollar < 0) { return className; @@ -69,12 +71,15 @@ return className.substring(lastDollar + 1); } - public static String toInternalName(String name) { - return name.replace('.', '/'); + public static String toInternalName(String binaryName) { + assert isBinaryName(binaryName); + return binaryName.replace('.', '/'); } - public static String toSourceName(String name) { - return name.replaceAll("[$/](\\w)", ".$1"); + public static String toSourceName(String binaryName) { + assert isBinaryName(binaryName); + // don't change a trailing $ to a . + return binaryName.replaceAll("[$](\\w)", ".$1"); } } @@ -87,7 +92,8 @@ public static class DottedName { public static String toSourceName(String dottedName) { - return dottedName.replaceAll("[$/](\\w)", ".$1"); + // don't change a trailing $ to a . + return dottedName.replaceAll("[$](\\w)", ".$1"); } } @@ -100,6 +106,7 @@ public static class InternalName { public static String getClassName(String name) { + assert isInternalName(name); int lastSlash = name.lastIndexOf('/'); if (lastSlash < 0) { return name; @@ -108,13 +115,16 @@ } public static String getInnerClassName(String internalName, String innerClassName) { + assert isInternalName(internalName); return internalName + '$' + innerClassName; } /** + * Return the outer class name of an inner class, or null if this is not + * an inner class. * * @param name internal name which might be an inner class - * @return an internal name of the enclosing class + * @return an internal name of the enclosing class or null if none */ public static String getOuterClassName(String name) { int lastDollar = name.lastIndexOf('$'); @@ -125,14 +135,16 @@ } public static String getPackageName(String name) { + assert isInternalName(name); int lastSlash = name.lastIndexOf('/'); if (lastSlash < 0) { return ""; } - return name.substring(0, lastSlash).replace('/', '.'); + return name.substring(0, lastSlash); } public static String getShortClassName(String internalName) { + assert isInternalName(internalName); String className = getClassName(internalName); int lastDollar = className.lastIndexOf('$', className.length() - 2); if (lastDollar < 0) { @@ -142,10 +154,13 @@ } public static String toBinaryName(String internalName) { + assert isInternalName(internalName); return internalName.replace('/', '.'); } public static String toSourceName(String internalName) { + assert isInternalName(internalName); + // don't change a trailing $ or slash to a . return internalName.replaceAll("[$/](\\w)", ".$1"); } @@ -163,69 +178,87 @@ public static String getInnerClassName(String sourceName, String innerClassName) { + assert isSourceName(sourceName); return sourceName + '.' + innerClassName; } - public static String getShortClassName(String name) { - int lastDollar = name.lastIndexOf('.'); + public static String getShortClassName(String sourceName) { + assert isSourceName(sourceName); + int lastDollar = sourceName.lastIndexOf('.'); if (lastDollar < 0) { - return name; - } - return name.substring(lastDollar + 1); + return sourceName; + } + return sourceName.substring(lastDollar + 1); } } /** - * Convert a Java class name in binary form to a type-safe wrapper. + * Get the binary name for a Java class. * - * @param name class name in binary form (ie, org.example.Foo$Bar) - * @return BinaryName instance corresponding to the supplied name + * @param clazz class literal + * @return binary name for the class */ - public static boolean isBinaryName(String name) { - return name == null || !name.contains("/"); + public static String getBinaryNameForClass(Class<?> clazz) { + return clazz.getName(); } /** - * Convert a Java class name in internal form to a type-safe wrapper. + * Get the internal name for a Java class. * - * @param name class name in internal form (ie, org/example/Foo$Bar) - * @return InternalName instance corresponding to the supplied name + * @param clazz class literal + * @return internal name for the class */ - public static boolean isInternalName(String name) { - return name == null || !name.contains("."); + public static String getInternalNameForClass(Class<?> clazz) { + return BinaryName.toInternalName(getBinaryNameForClass(clazz)); } - public static boolean isSourceName(String name) { - if (name == null) { - return true; - } - return !name.contains("/") && (!name.contains("$") || name.endsWith("$")); + /** + * Get the source name for a Java class. + * + * @param clazz class literal + * @return source name for the class + */ + public static String getSourceNameForClass(Class<?> clazz) { + return clazz.getCanonicalName(); } /** - * Lookup a supplied source name in a TypeOracle and return the corresponding - * binary name, or null if not found. + * @return true if name could be a valid binary name. * - * @param sourceName SourceName to lookup - * @param oracle TypeOracle to use for lookup - * @return binary name corresponding to the supplied name or null + * Note that many invalid names might pass this test -- in particular, source + * names cannot be verified to know they are not valid binary names without + * being able to tell the package name part of the name. + * + * @param name class name to test */ - public static String lookupBinaryName(String sourceName, - TypeOracle oracle) { - JClassType type = oracle.findType(sourceName); - if (type != null) { - return type.getQualifiedBinaryName(); - } - return null; + public static boolean isBinaryName(String name) { + assert isBinaryName(name); + return name == null || !name.contains("/"); } /** - * Get the source name for a Java class. + * @return true if name could be a valid internal name. * - * @param clazz class literal - * @return source name for the class + * Note that many invalid names might pass this test. + * + * @param name class name to test */ - public static String sourceName(Class<?> clazz) { - return clazz.getCanonicalName(); + public static boolean isInternalName(String name) { + return name == null || !name.contains("."); + } + + /** + * @return true if name could be a valid source name. + * + * Note that many invalid names might pass this test. + * + * @param name class name to test + */ + public static boolean isSourceName(String name) { + if (name == null) { + return true; + } + int dollar = name.indexOf('$'); + return !name.contains("/") && (dollar < 0 || dollar == name.length() - 1); } } ======================================= --- /changes/jat/ihm/dev/core/test/com/google/gwt/dev/javac/JavaSourceParserTest.java Thu Jul 30 15:12:48 2009 +++ /changes/jat/ihm/dev/core/test/com/google/gwt/dev/javac/JavaSourceParserTest.java Fri Jul 31 10:13:46 2009 @@ -56,6 +56,25 @@ } }; + private static final MockJavaResource BAZ = new MockJavaResource("test.Baz") { + @Override + protected CharSequence getContent() { + StringBuffer code = new StringBuffer(); + code.append("package test;\n"); + code.append("public class Baz {\n"); + code.append(" public static class Baz1 {\n"); + code.append(" public String value(String a) { return \"Baz1\"; }\n"); + code.append(" public String value(int val) { return \"Baz1\"; }\n"); + code.append(" }\n"); + code.append(" public class Baz2 {\n"); + code.append(" public String value(String a) { return \"Baz2\"; }\n"); + code.append(" public String value(int val) { return \"Baz2\"; }\n"); + code.append(" }\n"); + code.append("}\n"); + return code; + } + }; + /** * Test method for {...@link JavaSourceParser#getClassChain(java.lang.String)}. */ @@ -73,11 +92,16 @@ JavaSourceParser parser = new JavaSourceParser(); addGeneratedUnits(FOO); addGeneratedUnits(BAR); + addGeneratedUnits(BAZ); JClassType string = state.getTypeOracle().getType("java.lang.String"); JClassType foo = state.getTypeOracle().getType("test.Foo"); parser.addSourceForType(foo, FOO); JClassType bar = state.getTypeOracle().getType("test.Bar"); parser.addSourceForType(bar, BAR); + JClassType baz = state.getTypeOracle().getType("test.Baz"); + parser.addSourceForType(baz, BAZ); + JClassType baz1 = state.getTypeOracle().getType("test.Baz.Baz1"); + JClassType baz2 = state.getTypeOracle().getType("test.Baz.Baz2"); JMethod method = foo.getMethod("value", new JType[] { string, JPrimitiveType.INT }); String[] arguments = parser.getArguments(method); @@ -102,6 +126,26 @@ assertNotNull(arguments); assertEquals(1, arguments.length); assertEquals("a", arguments[0]); + method = baz1.getMethod("value", new JType[] { JPrimitiveType.INT }); + arguments = parser.getArguments(method); + assertNotNull(arguments); + assertEquals(1, arguments.length); + assertEquals("val", arguments[0]); + method = baz1.getMethod("value", new JType[] { string }); + arguments = parser.getArguments(method); + assertNotNull(arguments); + assertEquals(1, arguments.length); + assertEquals("a", arguments[0]); + method = baz2.getMethod("value", new JType[] { JPrimitiveType.INT }); + arguments = parser.getArguments(method); + assertNotNull(arguments); + assertEquals(1, arguments.length); + assertEquals("val", arguments[0]); + method = baz2.getMethod("value", new JType[] { string }); + arguments = parser.getArguments(method); + assertNotNull(arguments); + assertEquals(1, arguments.length); + assertEquals("a", arguments[0]); } private void assertExpected(List<char[]> actual, String... expected) { --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/Google-Web-Toolkit-Contributors -~----------~----~----~----~------~----~------~--~---
