Skip to content

Commit

Permalink
cleanup in codegen/factories
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
  • Loading branch information
lukasj committed Sep 14, 2021
1 parent 6fe70c2 commit b2cd639
Show file tree
Hide file tree
Showing 44 changed files with 535 additions and 457 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2613,7 +2613,7 @@ public Vector getMultipleTableForeignKeyAssociations() {
*/
public Map<DatabaseTable, Set<DatabaseTable>> getMultipleTableForeignKeys() {
if (multipleTableForeignKeys == null) {
multipleTableForeignKeys = new HashMap(5);
multipleTableForeignKeys = new HashMap<>(5);
}
return multipleTableForeignKeys;
}
Expand Down Expand Up @@ -4790,11 +4790,8 @@ public void setFields(Vector<DatabaseField> fields) {
* INTERNAL:
* This method is used by the XML Deployment ClassDescriptor to read and write these mappings
*/
public void setForeignKeyFieldNamesForMultipleTable(Vector associations) throws DescriptorException {
Enumeration foreignKeys = associations.elements();

while (foreignKeys.hasMoreElements()) {
Association association = (Association) foreignKeys.nextElement();
public void setForeignKeyFieldNamesForMultipleTable(List<Association> associations) throws DescriptorException {
for (Association association: associations) {
addForeignKeyFieldNameForMultipleTable((String) association.getKey(), (String) association.getValue());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2021 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -201,7 +201,6 @@ public void write(CodeGenerator generator) {
generator.write(" ");
}
generator.write("synchronized");
needsSpace = true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ protected AttributeDefinition() {
* (and adding the appropriate import) if the type is
* unambiguous.
*/
private void adjustInitialValue(Map typeNameMap) {
private void adjustInitialValue(Map<String, Set<String>> typeNameMap) {
if (getInitialValue() == null) {
return;
}

StringBuilder initialValue = new StringBuilder(getInitialValue());
Set typeNames = parseForTypeNames(initialValue.toString());
Set<String> typeNames = parseForTypeNames(initialValue.toString());

for (Iterator i = typeNames.iterator(); i.hasNext();) {
String typeName = (String)i.next();
for (Iterator<String> i = typeNames.iterator(); i.hasNext();) {
String typeName = i.next();
String adjustedTypeName = adjustTypeName(typeName, typeNameMap);

if (!typeName.equals(adjustedTypeName)) {
Expand All @@ -59,7 +59,7 @@ private void adjustInitialValue(Map typeNameMap) {
setInitialValue(initialValue.toString());
}

protected void adjustTypeNames(Map typeNameMap) {
protected void adjustTypeNames(Map<String, Set<String>> typeNameMap) {
adjustInitialValue(typeNameMap);
}

Expand All @@ -72,11 +72,11 @@ public String getInitialValue() {
/**
* Used for calculating imports. @see org.eclipse.persistence.internal.codegen.ClassDefinition#calculateImports()
*/
protected void putTypeNamesInMap(Map typeNameMap) {
protected void putTypeNamesInMap(Map<String, Set<String>> typeNameMap) {
putTypeNameInMap(getTypeName(), typeNameMap);

for (Iterator i = parseForTypeNames(getInitialValue()).iterator(); i.hasNext();) {
putTypeNameInMap((String)i.next(), typeNameMap);
for (Iterator<String> i = parseForTypeNames(getInitialValue()).iterator(); i.hasNext();) {
putTypeNameInMap(i.next(), typeNameMap);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2021 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -35,24 +35,24 @@
*/
public class ClassDefinition extends CodeDefinition {
protected String packageName;
protected Vector imports;
protected Vector<String> imports;
protected int type;
public static final int CLASS_TYPE = 1;
public static final int INTERFACE_TYPE = 2;
protected String superClass;
protected Vector interfaces;
protected Vector attributes;
protected Vector methods;
protected Vector innerClasses;
protected Vector<String> interfaces;
protected Vector<AttributeDefinition> attributes;
protected Vector<MethodDefinition> methods;
protected Vector<ClassDefinition> innerClasses;

public ClassDefinition() {
this.packageName = "";
this.imports = new Vector(3);
this.imports = new Vector<>(3);
this.type = CLASS_TYPE;
this.interfaces = new Vector(3);
this.attributes = new Vector();
this.methods = new Vector();
this.innerClasses = new Vector(3);
this.interfaces = new Vector<>(3);
this.attributes = new Vector<>();
this.methods = new Vector<>();
this.innerClasses = new Vector<>(3);
}

public void addAttribute(AttributeDefinition attribute) {
Expand All @@ -69,8 +69,8 @@ public void addImport(String importStatement) {
}
}

private void addImports(Map typeNameMap) {
for (Map.Entry<String, Set<String>> entry : (Set<Map.Entry<String, Set<String>>>) typeNameMap.entrySet()) {
private void addImports(Map<String, Set<String>> typeNameMap) {
for (Map.Entry<String, Set<String>> entry : typeNameMap.entrySet()) {
String shortName = entry.getKey();
Set<String> packageNames = entry.getValue();

Expand Down Expand Up @@ -100,36 +100,36 @@ public void addMethod(MethodDefinition method) {
getMethods().addElement(method);
}

private void addTypeNamesToMap(HashMap typeNameMap) {
private void addTypeNamesToMap(HashMap<String, Set<String>> typeNameMap) {
putTypeNameInMap(getSuperClass(), typeNameMap);

for (Iterator i = getInterfaces().iterator(); i.hasNext();) {
putTypeNameInMap((String)i.next(), typeNameMap);
for (Iterator<String> i = getInterfaces().iterator(); i.hasNext();) {
putTypeNameInMap(i.next(), typeNameMap);
}

for (Iterator i = getAttributes().iterator(); i.hasNext();) {
((AttributeDefinition)i.next()).putTypeNamesInMap(typeNameMap);
for (Iterator<AttributeDefinition> i = getAttributes().iterator(); i.hasNext();) {
(i.next()).putTypeNamesInMap(typeNameMap);
}

for (Iterator i = getMethods().iterator(); i.hasNext();) {
((MethodDefinition)i.next()).putTypeNamesInMap(typeNameMap);
for (Iterator<MethodDefinition> i = getMethods().iterator(); i.hasNext();) {
i.next().putTypeNamesInMap(typeNameMap);
}
}

private void adjustTypeNames(HashMap typeNameMap) {
private void adjustTypeNames(HashMap<String, Set<String>> typeNameMap) {
setSuperClass(adjustTypeName(getSuperClass(), typeNameMap));

for (Iterator i = new Vector(getInterfaces()).iterator(); i.hasNext();) {
String interfaceName = (String)i.next();
for (Iterator<String> i = new Vector<>(getInterfaces()).iterator(); i.hasNext();) {
String interfaceName = i.next();
replaceInterface(interfaceName, adjustTypeName(interfaceName, typeNameMap));
}

for (Iterator i = getAttributes().iterator(); i.hasNext();) {
((AttributeDefinition)i.next()).adjustTypeNames(typeNameMap);
for (Iterator<AttributeDefinition> i = getAttributes().iterator(); i.hasNext();) {
(i.next()).adjustTypeNames(typeNameMap);
}

for (Iterator i = getMethods().iterator(); i.hasNext();) {
((MethodDefinition)i.next()).adjustTypeNames(typeNameMap);
for (Iterator<MethodDefinition> i = getMethods().iterator(); i.hasNext();) {
i.next().adjustTypeNames(typeNameMap);
}
}

Expand All @@ -149,7 +149,7 @@ private void adjustTypeNames(HashMap typeNameMap) {
public void calculateImports() {
// Calculate type name map for class definition.
// Key - short type name, Value - Set of package names for that type name
HashMap typeNameMap = new HashMap();
HashMap<String, Set<String>> typeNameMap = new HashMap<>();
addTypeNamesToMap(typeNameMap);

// Go back through class def, pulling out imports and removing package names from
Expand All @@ -164,23 +164,23 @@ public boolean containsMethod(MethodDefinition method) {
return getMethods().contains(method);
}

protected Vector getAttributes() {
protected Vector<AttributeDefinition> getAttributes() {
return attributes;
}

protected Vector getImports() {
protected Vector<String> getImports() {
return imports;
}

protected Vector getInnerClasses() {
protected Vector<ClassDefinition> getInnerClasses() {
return innerClasses;
}

protected Vector getInterfaces() {
protected Vector<String> getInterfaces() {
return interfaces;
}

protected Vector getMethods() {
protected Vector<MethodDefinition> getMethods() {
return methods;
}

Expand Down Expand Up @@ -208,11 +208,11 @@ protected void replaceInterface(String oldInterfaceName, String newInterfaceName
}
}

private void setImports(Vector imports) {
private void setImports(Vector<String> imports) {
this.imports = imports;
}

private void setMethods(Vector methods) {
private void setMethods(Vector<MethodDefinition> methods) {
this.methods = methods;
}

Expand All @@ -233,29 +233,29 @@ public void setType(int type) {
}

protected void sortImports() {
setImports(new Vector(new TreeSet(getImports())));
setImports(new Vector<>(new TreeSet<>(getImports())));
}

protected void sortMethods() {
//Object methodArray[] = getMethods().toArray();
Object[] methodArray = Helper.arrayFromVector(getMethods());
MethodDefinition[] methodArray = getMethods().toArray(new MethodDefinition[0]);

Comparator comparison = new Comparator() {
Comparator<MethodDefinition> comparison = new Comparator<MethodDefinition>() {
@Override
public int compare(Object first, Object second) {
if (((MethodDefinition)first).isConstructor()) {
public int compare(MethodDefinition first, MethodDefinition second) {
if (first.isConstructor()) {
return -1;
} else if (((MethodDefinition)second).isConstructor()) {
} else if (second.isConstructor()) {
return 1;
} else {
return ((MethodDefinition)first).getName().compareTo(((MethodDefinition)second).getName());
return first.getName().compareTo(second.getName());
}
}
};

Arrays.sort(methodArray, comparison);

Vector sortedMethods = new Vector(getMethods().size());
Vector<MethodDefinition> sortedMethods = new Vector<>(getMethods().size());
for (int index = 0; index < methodArray.length; index++) {
sortedMethods.addElement(methodArray[index]);
}
Expand All @@ -275,8 +275,8 @@ public void write(CodeGenerator generator) {
generator.cr();
}

for (Enumeration importsEnum = getImports().elements(); importsEnum.hasMoreElements();) {
String importLine = (String)importsEnum.nextElement();
for (Enumeration<String> importsEnum = getImports().elements(); importsEnum.hasMoreElements();) {
String importLine = importsEnum.nextElement();
generator.write("import ");
generator.write(importLine);
generator.writeln(";");
Expand Down Expand Up @@ -308,9 +308,9 @@ public void writeBody(CodeGenerator generator) {
}

boolean isFirst = true;
for (Enumeration interfacesEnum = getInterfaces().elements();
interfacesEnum.hasMoreElements();) {
String interfaceName = (String)interfacesEnum.nextElement();
for (Enumeration<String> interfacesEnum = getInterfaces().elements();
interfacesEnum.hasMoreElements();) {
String interfaceName = interfacesEnum.nextElement();

if (isFirst) {
if (isInterface()) {
Expand All @@ -331,27 +331,27 @@ public void writeBody(CodeGenerator generator) {
generator.writeln(" {");
generator.cr();

for (Enumeration attributesEnum = getAttributes().elements();
attributesEnum.hasMoreElements();) {
for (Enumeration<AttributeDefinition> attributesEnum = getAttributes().elements();
attributesEnum.hasMoreElements();) {
generator.tab();
((AttributeDefinition)attributesEnum.nextElement()).write(generator);
(attributesEnum.nextElement()).write(generator);
generator.cr();
}

if (!getAttributes().isEmpty()) {
generator.cr();
}

for (Enumeration methodsEnum = getMethods().elements(); methodsEnum.hasMoreElements();) {
((MethodDefinition)methodsEnum.nextElement()).write(generator);
for (Enumeration<MethodDefinition> methodsEnum = getMethods().elements(); methodsEnum.hasMoreElements();) {
methodsEnum.nextElement().write(generator);
generator.cr();
generator.cr();
}

//used for Oc4j code gen
for (Enumeration innerClassesEnum = getInnerClasses().elements();
innerClassesEnum.hasMoreElements();) {
((ClassDefinition)innerClassesEnum.nextElement()).write(generator);
for (Enumeration<ClassDefinition> innerClassesEnum = getInnerClasses().elements();
innerClassesEnum.hasMoreElements();) {
(innerClassesEnum.nextElement()).write(generator);
generator.cr();
generator.cr();
}
Expand Down

0 comments on commit b2cd639

Please sign in to comment.