Skip to content

Commit

Permalink
Fixed JDK6 compilation issues.
Browse files Browse the repository at this point in the history
The ForgePropertyStyle and ForgePropertyStyleConfig classes from scaffold-faces project have been used. Need to review the differences in these classes across the scaffold-faces and scaffold-aerogear projects.
  • Loading branch information
VineetReynolds committed Feb 28, 2013
1 parent a8297ce commit 957dcb9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 79 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2011, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
* Copyright 2012-2013 Red Hat, Inc. and/or its affiliates.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.jboss.forge.scaffold.html5.metawidget.inspector.propertystyle;

Expand All @@ -29,8 +14,10 @@
import java.util.List;
import java.util.Map;

import org.jboss.forge.parser.java.EnumConstant;
import org.jboss.forge.parser.java.Field;
import org.jboss.forge.parser.java.FieldHolder;
import org.jboss.forge.parser.java.JavaEnum;
import org.jboss.forge.parser.java.JavaSource;
import org.jboss.forge.parser.java.Method;
import org.jboss.forge.parser.java.MethodHolder;
Expand Down Expand Up @@ -60,9 +47,9 @@ public class ForgePropertyStyle
// Private members
//

private Project project;
private final Project project;

private MessageFormat privateFieldConvention;
private final MessageFormat privateFieldConvention;

//
// Constructor
Expand Down Expand Up @@ -142,16 +129,14 @@ protected Map<String, Property> inspectProperties(final String type)

// Lookup properties

JavaSource<?> clazz = sourceForName(type);
JavaSource<?> clazz = sourceForName(this.project,type);

if (clazz == null)
if (clazz instanceof MethodHolder<?>)
{
return properties;
lookupGetters(properties, (MethodHolder<?>) clazz);
lookupSetters(properties, (MethodHolder<?>) clazz);
}

lookupGetters(properties, (MethodHolder<?>) clazz);
lookupSetters(properties, (MethodHolder<?>) clazz);

return properties;
}
catch (Exception e)
Expand Down Expand Up @@ -211,7 +196,7 @@ protected void lookupGetters(final Map<String, Property> properties, final Metho

properties
.put(propertyName,
new ForgeProperty(propertyName, returnType, method, null, privateField));
new ForgeProperty(propertyName, returnType, method, null, privateField, this.project));
}
}

Expand Down Expand Up @@ -247,24 +232,19 @@ else if (methodName.startsWith(ClassUtils.JAVABEAN_IS_PREFIX)
return null;
}

if (Character.isLowerCase(propertyName.charAt(0)))
{
return null;
}

return StringUtils.decapitalize(propertyName);
}

/**
* Lookup setter-based properties.
* <p>
* This method will be called after <code>lookupFields</code> and <code>lookupGetters</code>.
* @param <O>
*/

protected <O extends JavaSource<O>> void lookupSetters(final Map<String, Property> properties, final MethodHolder<?> clazz)
protected <O extends JavaSource<O>> void lookupSetters(final Map<String, Property> properties,
final MethodHolder<O> clazz)
{
for (Method<?> method : clazz.getMethods())
for (Method<O> method : clazz.getMethods())
{
// Exclude static methods

Expand All @@ -275,7 +255,7 @@ protected <O extends JavaSource<O>> void lookupSetters(final Map<String, Propert

// Get type

List<?> parameters = method.getParameters();
List<Parameter<O>> parameters = method.getParameters();

if (parameters.size() != 1)
{
Expand All @@ -295,7 +275,7 @@ protected <O extends JavaSource<O>> void lookupSetters(final Map<String, Propert
//
// (explicitly set to null in case we encountered an imbalanced field/getter)

String type = ((Parameter) parameters.get(0)).getType();
String type = parameters.get(0).getType();

Field<?> privateField = getPrivateField((FieldHolder<?>) clazz, propertyName);

Expand All @@ -318,7 +298,7 @@ protected <O extends JavaSource<O>> void lookupSetters(final Map<String, Propert
propertyName,
new ForgeProperty(propertyName, existingForgeProperty.getType(),
existingForgeProperty.getReadMethod(), method, getPrivateField((FieldHolder<?>) clazz,
propertyName)));
propertyName), this.project));
continue;
}

Expand All @@ -331,7 +311,7 @@ protected <O extends JavaSource<O>> void lookupSetters(final Map<String, Propert

properties
.put(propertyName,
new ForgeProperty(propertyName, type, null, method, privateField));
new ForgeProperty(propertyName, type, null, method, privateField, this.project));
}
}

Expand All @@ -353,11 +333,6 @@ protected String isSetter(final Method<?> method)

String propertyName = methodName.substring(ClassUtils.JAVABEAN_SET_PREFIX.length());

if (Character.isLowerCase(propertyName.charAt(0)))
{
return null;
}

return StringUtils.decapitalize(propertyName);
}

Expand Down Expand Up @@ -391,7 +366,7 @@ protected Field<?> getPrivateField(final FieldHolder<?> fieldHolder, final Strin

// FORGE-402: support fields starting with capital letter

if (field == null && Character.isLowerCase(propertyName.charAt(0)))
if (field == null && !Character.isUpperCase(propertyName.charAt( 0 )))
{
field = fieldHolder.getField(StringUtils.capitalize(propertyName));
}
Expand All @@ -403,17 +378,14 @@ protected Field<?> getPrivateField(final FieldHolder<?> fieldHolder, final Strin
// Private methods
//

private JavaSource<?> sourceForName(final String type)
/*package private*/

static JavaSource<?> sourceForName(final Project project, final String type)
{
try
{
JavaSourceFacet javaSourceFact = this.project.getFacet(JavaSourceFacet.class);

// (strip generics)

String typeToUse = StringUtils.substringBefore(type, "<");

return javaSourceFact.getJavaResource(typeToUse).getJavaSource();
JavaSourceFacet javaSourceFact = project.getFacet(JavaSourceFacet.class);
return javaSourceFact.getJavaResource(type).getJavaSource();
}
catch (FileNotFoundException e)
{
Expand All @@ -440,13 +412,16 @@ public static class ForgeProperty

private final Field<?> privateField;

private final Project project;

//
// Constructor
//

public ForgeProperty(final String name, final String type, final Method<?> readMethod,
final Method<?> writeMethod,
final Field<?> privateField)
final Field<?> privateField,
final Project project)
{
super(name, type);

Expand All @@ -461,6 +436,7 @@ public ForgeProperty(final String name, final String type, final Method<?> readM
}

this.privateField = privateField;
this.project = project;
}

//
Expand Down Expand Up @@ -510,14 +486,24 @@ public <T extends Annotation> T getAnnotation(final Class<T> annotationClass)

if (annotation != null)
{
@SuppressWarnings("unchecked")
T annotationProxy = (T) AnnotationProxy.newInstance(annotation);
T annotationProxy = AnnotationProxy.newInstance(annotation);
return annotationProxy;
}

return null;
}

public List<EnumConstant<JavaEnum>> getEnumConstants()
{
JavaSource<?> source = sourceForName( this.project, getType() );

if ( source instanceof JavaEnum ) {
return ((JavaEnum) source).getEnumConstants();
}

return null;
}

@Override
public String getGenericType()
{
Expand Down Expand Up @@ -548,13 +534,11 @@ public String getGenericType()

public Method<?> getReadMethod()
{

return this.readMethod;
}

public Method<?> getWriteMethod()
{

return this.writeMethod;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2011, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
* Copyright 2012 Red Hat, Inc. and/or its affiliates.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.jboss.forge.scaffold.html5.metawidget.inspector.propertystyle;

Expand Down Expand Up @@ -50,9 +35,6 @@ public class ForgePropertyStyleConfig
public ForgePropertyStyleConfig setProject(Project project)
{
this.project = project;

// Fluent interface

return this;
}

Expand Down

0 comments on commit 957dcb9

Please sign in to comment.