You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ri...@apache.org on 2005/12/09 02:20:13 UTC
svn commit: r355298 - in /beehive/trunk/netui:
src/compiler-core/org/apache/beehive/netui/compiler/
src/compiler-core/org/apache/beehive/netui/compiler/grammar/
test/src/compilerTests/testsuite/actionOutputTypeHintMismatchWarning/
test/src/compilerTest...
Author: rich
Date: Thu Dec 8 17:20:09 2005
New Revision: 355298
URL: http://svn.apache.org/viewcvs?rev=355298&view=rev
Log:
Fix for http://issues.apache.org/jira/browse/BEEHIVE-929 : Compiler check for base type agreement between the type and typeHint attributes of an action output annotation
tests: bvt in netui (WinXP)
BB: same (linux)
Added:
beehive/trunk/netui/test/src/compilerTests/testsuite/actionOutputTypeHintMismatchWarning/
beehive/trunk/netui/test/src/compilerTests/testsuite/actionOutputTypeHintMismatchWarning/actionOutputTypeHintMismatchWarning/
beehive/trunk/netui/test/src/compilerTests/testsuite/actionOutputTypeHintMismatchWarning/actionOutputTypeHintMismatchWarning/Controller.java (with props)
beehive/trunk/netui/test/src/compilerTests/testsuite/actionOutputTypeHintMismatchWarning/expectedOutput/
beehive/trunk/netui/test/src/compilerTests/testsuite/actionOutputTypeHintMismatchWarning/expectedOutput/struts-config-actionOutputTypeHintMismatchWarning.expected
beehive/trunk/netui/test/src/compilerTests/testsuite/actionOutputTypeHintMismatchWarning/expectedOutput/warningsorerrors.expected
Modified:
beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/diagnostics.properties
beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ActionOutputGrammar.java
beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ForwardGrammar.java
Modified: beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/diagnostics.properties
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/diagnostics.properties?rev=355298&r1=355297&r2=355298&view=diff
==============================================================================
--- beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/diagnostics.properties (original)
+++ beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/diagnostics.properties Thu Dec 8 17:20:09 2005
@@ -221,3 +221,6 @@
Class {0} extends {1} and overrides its validate method. When doing this, super.validate must be called in order for \
declarative validation annotations on this class to work. Implementing the {2} interface instead of overriding validate \
avoids this issue.
+
+warning.type-hint-unresolvable = The {0} value of "{1}" is not resolvable as a type.
+warning.type-hint-mismatch = The {0} value of "{1}" cannot be assigned to the {2} value of {3}.
Modified: beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ActionOutputGrammar.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ActionOutputGrammar.java?rev=355298&r1=355297&r2=355298&view=diff
==============================================================================
--- beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ActionOutputGrammar.java (original)
+++ beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ActionOutputGrammar.java Thu Dec 8 17:20:09 2005
@@ -20,19 +20,51 @@
import org.apache.beehive.netui.compiler.AnnotationGrammar;
import org.apache.beehive.netui.compiler.Diagnostics;
import org.apache.beehive.netui.compiler.RuntimeVersionChecker;
+import org.apache.beehive.netui.compiler.CompilerUtils;
import org.apache.beehive.netui.compiler.typesystem.env.AnnotationProcessorEnvironment;
+import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationTypeElementDeclaration;
+import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationValue;
+import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationInstance;
+import org.apache.beehive.netui.compiler.typesystem.declaration.MemberDeclaration;
+import org.apache.beehive.netui.compiler.typesystem.declaration.TypeDeclaration;
+import org.apache.beehive.netui.compiler.typesystem.type.TypeInstance;
public class ActionOutputGrammar
extends AnnotationGrammar
{
private static final String[][] REQUIRED_ATTRS = { { NAME_ATTR }, { TYPE_ATTR } };
-
+
public ActionOutputGrammar( AnnotationProcessorEnvironment env, Diagnostics diags, RuntimeVersionChecker rvc )
{
super( env, diags, null, rvc );
-
+
addMemberType( NAME_ATTR, new UniqueValueType( ACTION_OUTPUTS_ATTR, false, false, null, this ) );
addMemberType( TYPE_ATTR, new TypeNameType( null, true, null, this ) );
+ }
+
+ protected void onCheckMember(AnnotationTypeElementDeclaration memberDecl, AnnotationValue member,
+ AnnotationInstance annotation, AnnotationInstance[] parentAnnotations,
+ MemberDeclaration classMember)
+ {
+ if (memberDecl.getSimpleName().equals(TYPE_HINT_ATTR)) {
+ // Strip off any template args, and compare the typeHint to the actual type.
+ String typeHintStr = member.getValue().toString();
+ int angleBracket = typeHintStr.indexOf('<');
+ String strippedTypeHintStr = angleBracket != -1 ? typeHintStr.substring(0, angleBracket) : typeHintStr;
+ TypeDeclaration typeHint = getEnv().getTypeDeclaration(strippedTypeHintStr);
+
+ // Add a warning if the typeHint type can't be resolved.
+ if (typeHint == null) {
+ addWarning(member, "warning.type-hint-unresolvable", TYPE_HINT_ATTR, typeHintStr);
+ } else {
+ // Add a warning if the typeHint type can't be assigned to the actual type.
+ TypeInstance actualType = CompilerUtils.getTypeInstance(annotation, TYPE_ATTR, true);
+ if (! CompilerUtils.isAssignableFrom(actualType, typeHint)) {
+ addWarning(member, "warning.type-hint-mismatch",
+ new Object[]{ TYPE_HINT_ATTR, typeHintStr, TYPE_ATTR, actualType.toString() });
+ }
+ }
+ }
}
public String[][] getRequiredAttrs()
Modified: beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ForwardGrammar.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ForwardGrammar.java?rev=355298&r1=355297&r2=355298&view=diff
==============================================================================
--- beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ForwardGrammar.java (original)
+++ beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ForwardGrammar.java Thu Dec 8 17:20:09 2005
@@ -79,7 +79,7 @@
RuntimeVersionChecker runtimeVersionChecker, FlowControllerInfo fcInfo )
{
super( env, diags, requiredRuntimeVersion, runtimeVersionChecker, fcInfo );
-
+
addMemberType( NAME_ATTR, getNameType() );
addMemberType( OUTPUT_FORM_BEAN_TYPE_ATTR, new TypeNameType( null, false, null, this ) );
addMemberType( OUTPUT_FORM_BEAN_ATTR, new MemberFieldType( null , null, this ) );
Added: beehive/trunk/netui/test/src/compilerTests/testsuite/actionOutputTypeHintMismatchWarning/actionOutputTypeHintMismatchWarning/Controller.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/test/src/compilerTests/testsuite/actionOutputTypeHintMismatchWarning/actionOutputTypeHintMismatchWarning/Controller.java?rev=355298&view=auto
==============================================================================
--- beehive/trunk/netui/test/src/compilerTests/testsuite/actionOutputTypeHintMismatchWarning/actionOutputTypeHintMismatchWarning/Controller.java (added)
+++ beehive/trunk/netui/test/src/compilerTests/testsuite/actionOutputTypeHintMismatchWarning/actionOutputTypeHintMismatchWarning/Controller.java Thu Dec 8 17:20:09 2005
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * 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.
+ *
+ * $Header:$
+ */
+package actionOutputTypeHintMismatchWarning;
+
+import org.apache.beehive.netui.pageflow.PageFlowController;
+import org.apache.beehive.netui.pageflow.Forward;
+import org.apache.beehive.netui.pageflow.annotations.Jpf;
+import java.util.*;
+
+/**
+ * Test to ensure that there are warnings when the typeHint doesn't match the type on @Jpf.ActionOutput.
+ */
+@Jpf.Controller
+public class Controller extends PageFlowController
+{
+ @Jpf.Action(
+ forwards={
+ @Jpf.Forward(
+ name="dne",
+ path="doesnotexist",
+ actionOutputs={
+ @Jpf.ActionOutput(name="good1", type=ArrayList.class, typeHint="java.util.ArrayList<String>"),
+ @Jpf.ActionOutput(name="good2", type=List.class, typeHint="java.util.ArrayList<String>"),
+ @Jpf.ActionOutput(name="good3", type=ArrayList.class, typeHint="java.util.ArrayList"),
+ @Jpf.ActionOutput(name="bad1", type=ArrayList.class, typeHint="java.util.HashSet"),
+ @Jpf.ActionOutput(name="bad2", type=ArrayList.class, typeHint="java.util.HashSet<String>"),
+ @Jpf.ActionOutput(name="bad3", type=ArrayList.class, typeHint="SomeUnresolvableType")
+ }
+ )
+ }
+ )
+ public Forward begin()
+ {
+ return new Forward("dne");
+ }
+}
Propchange: beehive/trunk/netui/test/src/compilerTests/testsuite/actionOutputTypeHintMismatchWarning/actionOutputTypeHintMismatchWarning/Controller.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: beehive/trunk/netui/test/src/compilerTests/testsuite/actionOutputTypeHintMismatchWarning/expectedOutput/struts-config-actionOutputTypeHintMismatchWarning.expected
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/test/src/compilerTests/testsuite/actionOutputTypeHintMismatchWarning/expectedOutput/struts-config-actionOutputTypeHintMismatchWarning.expected?rev=355298&view=auto
==============================================================================
--- beehive/trunk/netui/test/src/compilerTests/testsuite/actionOutputTypeHintMismatchWarning/expectedOutput/struts-config-actionOutputTypeHintMismatchWarning.expected (added)
+++ beehive/trunk/netui/test/src/compilerTests/testsuite/actionOutputTypeHintMismatchWarning/expectedOutput/struts-config-actionOutputTypeHintMismatchWarning.expected Thu Dec 8 17:20:09 2005
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
+<struts-config>
+ <!-- Generated from /actionOutputTypeHintMismatchWarning/Controller.java on Thu Dec 08 18:03:27 MST 2005 -->
+ <form-beans/>
+ <global-exceptions/>
+ <global-forwards>
+ <forward name="_auto" path=""/>
+ </global-forwards>
+ <action-mappings>
+ <action parameter="actionOutputTypeHintMismatchWarning.Controller" path="/begin" scope="request" type="org.apache.beehive.netui.pageflow.internal.FlowControllerAction" validate="false">
+ <forward className="org.apache.beehive.netui.pageflow.config.PageFlowActionForward" name="dne" path="/doesnotexist">
+ <set-property property="actionOutputCount" value="6"/>
+ <set-property property="actionOutput0" value="java.util.ArrayList|false|good1"/>
+ <set-property property="actionOutput1" value="java.util.List|false|good2"/>
+ <set-property property="actionOutput2" value="java.util.ArrayList|false|good3"/>
+ <set-property property="actionOutput3" value="java.util.ArrayList|false|bad1"/>
+ <set-property property="actionOutput4" value="java.util.ArrayList|false|bad2"/>
+ <set-property property="actionOutput5" value="java.util.ArrayList|false|bad3"/>
+ </forward>
+ </action>
+ </action-mappings>
+ <controller className="org.apache.beehive.netui.pageflow.config.PageFlowControllerConfig" inputForward="true" processorClass="org.apache.beehive.netui.pageflow.PageFlowRequestProcessor">
+ <set-property property="isReturnToPageDisabled" value="true"/>
+ <set-property property="isReturnToActionDisabled" value="true"/>
+ <set-property property="sharedFlows" value=""/>
+ <set-property property="controllerClass" value="actionOutputTypeHintMismatchWarning.Controller"/>
+ <set-property property="isMissingDefaultMessages" value="true"/>
+ </controller>
+ <message-resources key="_defaultMsgs" null="true" parameter="org.apache.beehive.netui.pageflow.validation.defaultMessages"/>
+</struts-config>
Added: beehive/trunk/netui/test/src/compilerTests/testsuite/actionOutputTypeHintMismatchWarning/expectedOutput/warningsorerrors.expected
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/test/src/compilerTests/testsuite/actionOutputTypeHintMismatchWarning/expectedOutput/warningsorerrors.expected?rev=355298&view=auto
==============================================================================
--- beehive/trunk/netui/test/src/compilerTests/testsuite/actionOutputTypeHintMismatchWarning/expectedOutput/warningsorerrors.expected (added)
+++ beehive/trunk/netui/test/src/compilerTests/testsuite/actionOutputTypeHintMismatchWarning/expectedOutput/warningsorerrors.expected Thu Dec 8 17:20:09 2005
@@ -0,0 +1,10 @@
+[LOCAL_PATH]/WEB-INF\.tmpbeansrc\actionOutputTypeHintMismatchWarning\Controller.java:47: warning: The typeHint value of "java.util.HashSet" cannot be assigned to the type value of java.util.ArrayList.
+ public Forward begin()
+ ^
+[LOCAL_PATH]/WEB-INF\.tmpbeansrc\actionOutputTypeHintMismatchWarning\Controller.java:47: warning: The typeHint value of "java.util.HashSet<String>" cannot be assigned to the type value of java.util.ArrayList.
+ public Forward begin()
+ ^
+[LOCAL_PATH]/WEB-INF\.tmpbeansrc\actionOutputTypeHintMismatchWarning\Controller.java:47: warning: The typeHint value of "SomeUnresolvableType" is not resolvable as a type.
+ public Forward begin()
+ ^
+3 warnings