@Test public void extract_A$String_Slim3_AbstractModelRef() throws Exception { ClassMetaExtractor target = new ClassMetaExtractor(config); String sourceCodeString = IOUtil.readAsString(IOUtil.getResourceAsStream("inputs/Slim3_AbstractModelRef.txt"), "UTF-8"); ClassMeta actual = target.extract(sourceCodeString); assertEquals("org.slim3.datastore", actual.packageName); assertEquals(false, actual.isAbstract); assertEquals("AbstractModelRef", actual.name); }
public ClassMeta extract(String sourceCodeString) { Assertion.on("sourceCodeString").mustNotBeNull(sourceCodeString); ClassMeta meta = new ClassMeta(); String modifiedSourceCodeString = TrimFilterUtil.doAllFilters(sourceCodeString); Matcher matcherGroupingPackageName = RegExp.PatternObject.Pacakge_Group.matcher(modifiedSourceCodeString); if (matcherGroupingPackageName.find()) { meta.packageName = matcherGroupingPackageName.group(1); } String outOfBrace = modifiedSourceCodeString.split("\\{")[0]; int lenForOutOfBrace = outOfBrace.length(); StringBuilder bufForOutOfBrace = new StringBuilder(); boolean isInsideOfGenerics = false; int depth = 0; for (int i = 0; i < lenForOutOfBrace; i++) { char current = outOfBrace.charAt(i); if (current == '<') { isInsideOfGenerics = true; depth++; } if (current == '>') { depth--; if (depth <= 0) { isInsideOfGenerics = false; continue; } } if (!isInsideOfGenerics) { bufForOutOfBrace.append(current); } } String outOfBraceWithoutGenerics = bufForOutOfBrace.toString(); String[] splittedBySpace = outOfBraceWithoutGenerics.split("\\s+"); boolean isClass = outOfBrace.matches(".*\\s+class\\s+.*") || outOfBrace.matches(".*;class\\s+.*"); meta.isEnum = outOfBrace.matches(".*\\s+enum\\s+.*"); if (!isClass && !meta.isEnum) { meta.isAbstract = true; } else { for (String each : splittedBySpace) { if (each.equals("abstract") || each.equals("interface") || each.equals("@interface")) { meta.isAbstract = true; break; } } } meta.name = splittedBySpace[splittedBySpace.length - 1].replaceFirst(RegExp.Generics, StringValue.Empty); for (int i = 0; i < splittedBySpace.length; i++) { if (splittedBySpace[i].equals("extends") || splittedBySpace[i].equals("implements")) { meta.name = splittedBySpace[i - 1].replaceFirst(RegExp.Generics, StringValue.Empty); break; } } meta.importedList = importedListExtractor.extract(modifiedSourceCodeString); constructorMetaExtractor.initialize(meta, modifiedSourceCodeString); meta.constructors = constructorMetaExtractor.extract(modifiedSourceCodeString); methodMetaExtractor.initialize(meta, modifiedSourceCodeString); meta.methods = methodMetaExtractor.extract(modifiedSourceCodeString); if (meta.constructors.size() > 0) { for (ConstructorMeta cons : meta.constructors) { int len = cons.argNames.size(); for (int i = 0; i < len; i++) { if (isDuplicatedVariableName(cons.argNames.get(i))) { cons.argNames.set(i, cons.argNames.get(i) + "_"); } } } ConstructorMeta constructor = meta.constructors.get(0); for (MethodMeta method : meta.methods) { int len = method.argNames.size(); for (int i = 0; i < len; i++) { String targetArgName = method.argNames.get(i); List<String> methodArgNames = new ArrayList<String>(); for (String methodArgName : method.argNames) { if (!targetArgName.equals(methodArgName)) { methodArgNames.add(methodArgName); } } method.argNames.set(i, renameIfDuplicatedToConstructorArgNames(targetArgName, constructor.argNames, methodArgNames)); } } } return meta; }
ClassMetaExtractor { public ClassMeta extract(String sourceCodeString) { Assertion.on("sourceCodeString").mustNotBeNull(sourceCodeString); ClassMeta meta = new ClassMeta(); String modifiedSourceCodeString = TrimFilterUtil.doAllFilters(sourceCodeString); Matcher matcherGroupingPackageName = RegExp.PatternObject.Pacakge_Group.matcher(modifiedSourceCodeString); if (matcherGroupingPackageName.find()) { meta.packageName = matcherGroupingPackageName.group(1); } String outOfBrace = modifiedSourceCodeString.split("\\{")[0]; int lenForOutOfBrace = outOfBrace.length(); StringBuilder bufForOutOfBrace = new StringBuilder(); boolean isInsideOfGenerics = false; int depth = 0; for (int i = 0; i < lenForOutOfBrace; i++) { char current = outOfBrace.charAt(i); if (current == '<') { isInsideOfGenerics = true; depth++; } if (current == '>') { depth--; if (depth <= 0) { isInsideOfGenerics = false; continue; } } if (!isInsideOfGenerics) { bufForOutOfBrace.append(current); } } String outOfBraceWithoutGenerics = bufForOutOfBrace.toString(); String[] splittedBySpace = outOfBraceWithoutGenerics.split("\\s+"); boolean isClass = outOfBrace.matches(".*\\s+class\\s+.*") || outOfBrace.matches(".*;class\\s+.*"); meta.isEnum = outOfBrace.matches(".*\\s+enum\\s+.*"); if (!isClass && !meta.isEnum) { meta.isAbstract = true; } else { for (String each : splittedBySpace) { if (each.equals("abstract") || each.equals("interface") || each.equals("@interface")) { meta.isAbstract = true; break; } } } meta.name = splittedBySpace[splittedBySpace.length - 1].replaceFirst(RegExp.Generics, StringValue.Empty); for (int i = 0; i < splittedBySpace.length; i++) { if (splittedBySpace[i].equals("extends") || splittedBySpace[i].equals("implements")) { meta.name = splittedBySpace[i - 1].replaceFirst(RegExp.Generics, StringValue.Empty); break; } } meta.importedList = importedListExtractor.extract(modifiedSourceCodeString); constructorMetaExtractor.initialize(meta, modifiedSourceCodeString); meta.constructors = constructorMetaExtractor.extract(modifiedSourceCodeString); methodMetaExtractor.initialize(meta, modifiedSourceCodeString); meta.methods = methodMetaExtractor.extract(modifiedSourceCodeString); if (meta.constructors.size() > 0) { for (ConstructorMeta cons : meta.constructors) { int len = cons.argNames.size(); for (int i = 0; i < len; i++) { if (isDuplicatedVariableName(cons.argNames.get(i))) { cons.argNames.set(i, cons.argNames.get(i) + "_"); } } } ConstructorMeta constructor = meta.constructors.get(0); for (MethodMeta method : meta.methods) { int len = method.argNames.size(); for (int i = 0; i < len; i++) { String targetArgName = method.argNames.get(i); List<String> methodArgNames = new ArrayList<String>(); for (String methodArgName : method.argNames) { if (!targetArgName.equals(methodArgName)) { methodArgNames.add(methodArgName); } } method.argNames.set(i, renameIfDuplicatedToConstructorArgNames(targetArgName, constructor.argNames, methodArgNames)); } } } return meta; } }
ClassMetaExtractor { public ClassMeta extract(String sourceCodeString) { Assertion.on("sourceCodeString").mustNotBeNull(sourceCodeString); ClassMeta meta = new ClassMeta(); String modifiedSourceCodeString = TrimFilterUtil.doAllFilters(sourceCodeString); Matcher matcherGroupingPackageName = RegExp.PatternObject.Pacakge_Group.matcher(modifiedSourceCodeString); if (matcherGroupingPackageName.find()) { meta.packageName = matcherGroupingPackageName.group(1); } String outOfBrace = modifiedSourceCodeString.split("\\{")[0]; int lenForOutOfBrace = outOfBrace.length(); StringBuilder bufForOutOfBrace = new StringBuilder(); boolean isInsideOfGenerics = false; int depth = 0; for (int i = 0; i < lenForOutOfBrace; i++) { char current = outOfBrace.charAt(i); if (current == '<') { isInsideOfGenerics = true; depth++; } if (current == '>') { depth--; if (depth <= 0) { isInsideOfGenerics = false; continue; } } if (!isInsideOfGenerics) { bufForOutOfBrace.append(current); } } String outOfBraceWithoutGenerics = bufForOutOfBrace.toString(); String[] splittedBySpace = outOfBraceWithoutGenerics.split("\\s+"); boolean isClass = outOfBrace.matches(".*\\s+class\\s+.*") || outOfBrace.matches(".*;class\\s+.*"); meta.isEnum = outOfBrace.matches(".*\\s+enum\\s+.*"); if (!isClass && !meta.isEnum) { meta.isAbstract = true; } else { for (String each : splittedBySpace) { if (each.equals("abstract") || each.equals("interface") || each.equals("@interface")) { meta.isAbstract = true; break; } } } meta.name = splittedBySpace[splittedBySpace.length - 1].replaceFirst(RegExp.Generics, StringValue.Empty); for (int i = 0; i < splittedBySpace.length; i++) { if (splittedBySpace[i].equals("extends") || splittedBySpace[i].equals("implements")) { meta.name = splittedBySpace[i - 1].replaceFirst(RegExp.Generics, StringValue.Empty); break; } } meta.importedList = importedListExtractor.extract(modifiedSourceCodeString); constructorMetaExtractor.initialize(meta, modifiedSourceCodeString); meta.constructors = constructorMetaExtractor.extract(modifiedSourceCodeString); methodMetaExtractor.initialize(meta, modifiedSourceCodeString); meta.methods = methodMetaExtractor.extract(modifiedSourceCodeString); if (meta.constructors.size() > 0) { for (ConstructorMeta cons : meta.constructors) { int len = cons.argNames.size(); for (int i = 0; i < len; i++) { if (isDuplicatedVariableName(cons.argNames.get(i))) { cons.argNames.set(i, cons.argNames.get(i) + "_"); } } } ConstructorMeta constructor = meta.constructors.get(0); for (MethodMeta method : meta.methods) { int len = method.argNames.size(); for (int i = 0; i < len; i++) { String targetArgName = method.argNames.get(i); List<String> methodArgNames = new ArrayList<String>(); for (String methodArgName : method.argNames) { if (!targetArgName.equals(methodArgName)) { methodArgNames.add(methodArgName); } } method.argNames.set(i, renameIfDuplicatedToConstructorArgNames(targetArgName, constructor.argNames, methodArgNames)); } } } return meta; } ClassMetaExtractor(Configuration config); }
ClassMetaExtractor { public ClassMeta extract(String sourceCodeString) { Assertion.on("sourceCodeString").mustNotBeNull(sourceCodeString); ClassMeta meta = new ClassMeta(); String modifiedSourceCodeString = TrimFilterUtil.doAllFilters(sourceCodeString); Matcher matcherGroupingPackageName = RegExp.PatternObject.Pacakge_Group.matcher(modifiedSourceCodeString); if (matcherGroupingPackageName.find()) { meta.packageName = matcherGroupingPackageName.group(1); } String outOfBrace = modifiedSourceCodeString.split("\\{")[0]; int lenForOutOfBrace = outOfBrace.length(); StringBuilder bufForOutOfBrace = new StringBuilder(); boolean isInsideOfGenerics = false; int depth = 0; for (int i = 0; i < lenForOutOfBrace; i++) { char current = outOfBrace.charAt(i); if (current == '<') { isInsideOfGenerics = true; depth++; } if (current == '>') { depth--; if (depth <= 0) { isInsideOfGenerics = false; continue; } } if (!isInsideOfGenerics) { bufForOutOfBrace.append(current); } } String outOfBraceWithoutGenerics = bufForOutOfBrace.toString(); String[] splittedBySpace = outOfBraceWithoutGenerics.split("\\s+"); boolean isClass = outOfBrace.matches(".*\\s+class\\s+.*") || outOfBrace.matches(".*;class\\s+.*"); meta.isEnum = outOfBrace.matches(".*\\s+enum\\s+.*"); if (!isClass && !meta.isEnum) { meta.isAbstract = true; } else { for (String each : splittedBySpace) { if (each.equals("abstract") || each.equals("interface") || each.equals("@interface")) { meta.isAbstract = true; break; } } } meta.name = splittedBySpace[splittedBySpace.length - 1].replaceFirst(RegExp.Generics, StringValue.Empty); for (int i = 0; i < splittedBySpace.length; i++) { if (splittedBySpace[i].equals("extends") || splittedBySpace[i].equals("implements")) { meta.name = splittedBySpace[i - 1].replaceFirst(RegExp.Generics, StringValue.Empty); break; } } meta.importedList = importedListExtractor.extract(modifiedSourceCodeString); constructorMetaExtractor.initialize(meta, modifiedSourceCodeString); meta.constructors = constructorMetaExtractor.extract(modifiedSourceCodeString); methodMetaExtractor.initialize(meta, modifiedSourceCodeString); meta.methods = methodMetaExtractor.extract(modifiedSourceCodeString); if (meta.constructors.size() > 0) { for (ConstructorMeta cons : meta.constructors) { int len = cons.argNames.size(); for (int i = 0; i < len; i++) { if (isDuplicatedVariableName(cons.argNames.get(i))) { cons.argNames.set(i, cons.argNames.get(i) + "_"); } } } ConstructorMeta constructor = meta.constructors.get(0); for (MethodMeta method : meta.methods) { int len = method.argNames.size(); for (int i = 0; i < len; i++) { String targetArgName = method.argNames.get(i); List<String> methodArgNames = new ArrayList<String>(); for (String methodArgName : method.argNames) { if (!targetArgName.equals(methodArgName)) { methodArgNames.add(methodArgName); } } method.argNames.set(i, renameIfDuplicatedToConstructorArgNames(targetArgName, constructor.argNames, methodArgNames)); } } } return meta; } ClassMetaExtractor(Configuration config); ClassMeta extract(String sourceCodeString); }
ClassMetaExtractor { public ClassMeta extract(String sourceCodeString) { Assertion.on("sourceCodeString").mustNotBeNull(sourceCodeString); ClassMeta meta = new ClassMeta(); String modifiedSourceCodeString = TrimFilterUtil.doAllFilters(sourceCodeString); Matcher matcherGroupingPackageName = RegExp.PatternObject.Pacakge_Group.matcher(modifiedSourceCodeString); if (matcherGroupingPackageName.find()) { meta.packageName = matcherGroupingPackageName.group(1); } String outOfBrace = modifiedSourceCodeString.split("\\{")[0]; int lenForOutOfBrace = outOfBrace.length(); StringBuilder bufForOutOfBrace = new StringBuilder(); boolean isInsideOfGenerics = false; int depth = 0; for (int i = 0; i < lenForOutOfBrace; i++) { char current = outOfBrace.charAt(i); if (current == '<') { isInsideOfGenerics = true; depth++; } if (current == '>') { depth--; if (depth <= 0) { isInsideOfGenerics = false; continue; } } if (!isInsideOfGenerics) { bufForOutOfBrace.append(current); } } String outOfBraceWithoutGenerics = bufForOutOfBrace.toString(); String[] splittedBySpace = outOfBraceWithoutGenerics.split("\\s+"); boolean isClass = outOfBrace.matches(".*\\s+class\\s+.*") || outOfBrace.matches(".*;class\\s+.*"); meta.isEnum = outOfBrace.matches(".*\\s+enum\\s+.*"); if (!isClass && !meta.isEnum) { meta.isAbstract = true; } else { for (String each : splittedBySpace) { if (each.equals("abstract") || each.equals("interface") || each.equals("@interface")) { meta.isAbstract = true; break; } } } meta.name = splittedBySpace[splittedBySpace.length - 1].replaceFirst(RegExp.Generics, StringValue.Empty); for (int i = 0; i < splittedBySpace.length; i++) { if (splittedBySpace[i].equals("extends") || splittedBySpace[i].equals("implements")) { meta.name = splittedBySpace[i - 1].replaceFirst(RegExp.Generics, StringValue.Empty); break; } } meta.importedList = importedListExtractor.extract(modifiedSourceCodeString); constructorMetaExtractor.initialize(meta, modifiedSourceCodeString); meta.constructors = constructorMetaExtractor.extract(modifiedSourceCodeString); methodMetaExtractor.initialize(meta, modifiedSourceCodeString); meta.methods = methodMetaExtractor.extract(modifiedSourceCodeString); if (meta.constructors.size() > 0) { for (ConstructorMeta cons : meta.constructors) { int len = cons.argNames.size(); for (int i = 0; i < len; i++) { if (isDuplicatedVariableName(cons.argNames.get(i))) { cons.argNames.set(i, cons.argNames.get(i) + "_"); } } } ConstructorMeta constructor = meta.constructors.get(0); for (MethodMeta method : meta.methods) { int len = method.argNames.size(); for (int i = 0; i < len; i++) { String targetArgName = method.argNames.get(i); List<String> methodArgNames = new ArrayList<String>(); for (String methodArgName : method.argNames) { if (!targetArgName.equals(methodArgName)) { methodArgNames.add(methodArgName); } } method.argNames.set(i, renameIfDuplicatedToConstructorArgNames(targetArgName, constructor.argNames, methodArgNames)); } } } return meta; } ClassMetaExtractor(Configuration config); ClassMeta extract(String sourceCodeString);  }