편집 : 설명하지 않은 것에 대해 사과드립니다. goto
은 현재 Java 언어의 기능적 부분이 아닙니다. 이 질문은 자바에서 goto
을 사용하려고 시도하는 것이 아니라 이 아니고을 사용하려고합니다.Goto 문 축소 (예 : 자바 대체 용)
편집 : 주어진 특정 사례에 도움을 주겠지 만이 질문은 이러한 코드를 리팩토링하는 프로세스에 적용 할 수있는 결정적 방법이 있는지 여부를 조사하는 것입니다.
안녕 모두
,이것은 this one과 유사하지만 더 일반적으로 추구하는 문제이다.
즉, 클래스 파일을 디 컴파일하고 수정하고 다시 사용하려면 다시 컴파일해야하지만 ~25 개의 오류가 발생합니다. 그 중 대부분은 goto
및 관련 명명 된 코드 블록과 관련되어 있습니다.
주위를 둘러 본 후 내 선택은 인터넷 패브릭에서 사용한 것보다 더 나은 디 컴파일러를 가져 오거나 직접 압축을 풀고 내가 만들 수있는 것이 제대로 컴파일되는지 확인하는 것 같습니다. .
제 질문은 goto 문을 더 정상/일반적으로 허용되는 제어 흐름 키워드로 변환하려고 할 때 따라야 할 일반 지침이 있습니까? 지금까지는 권장 사항이 사안별로 나온 것처럼 보입니다. 그러한 연습을 통해 적용 할 수있는 아이디어가 있습니까? 이 도움이 경우
, 나는 여기에 관련 코드를 게시합니다 :이 SO에 대한 내 첫 번째 질문은
private void unpackNatives(CompleteVersion version, File targetDir)
throws IOException
{
OperatingSystem os;
Iterator iterator;
os = OperatingSystem.getCurrentPlatform();
Collection libraries = version.getRelevantLibraries();
iterator = libraries.iterator();
goto _L1
_L7:
ZipFile zip;
ExtractRules extractRules;
Library library = (Library)iterator.next();
Map nativesPerOs = library.getNatives();
if(nativesPerOs == null || nativesPerOs.get(os) == null)
continue; /* Loop/switch isn't completed */
File file = new File(Launcher.getInstance().getBaseDirectory(), (new StringBuilder("libraries/")).append(library.getArtifactPath((String)nativesPerOs.get(os))).toString());
zip = new ZipFile(file);
extractRules = library.getExtractRules();
Enumeration entries = zip.entries();
goto _L2
_L5:
BufferedInputStream inputStream;
byte buffer[];
FileOutputStream outputStream;
BufferedOutputStream bufferedOutputStream;
ZipEntry entry = (ZipEntry)entries.nextElement();
if(extractRules != null && !extractRules.shouldExtract(entry.getName()))
continue; /* Loop/switch isn't completed */
File targetFile = new File(targetDir, entry.getName());
if(targetFile.getParentFile() != null)
targetFile.getParentFile().mkdirs();
if(entry.isDirectory())
continue; /* Loop/switch isn't completed */
inputStream = new BufferedInputStream(zip.getInputStream(entry));
buffer = new byte[2048];
outputStream = new FileOutputStream(targetFile);
bufferedOutputStream = new BufferedOutputStream(outputStream);
int length;
while((length = inputStream.read(buffer, 0, buffer.length)) != -1)
bufferedOutputStream.write(buffer, 0, length);
goto _L3
Exception exception;
exception;
Downloadable.closeSilently(bufferedOutputStream);
Downloadable.closeSilently(outputStream);
Downloadable.closeSilently(inputStream);
throw exception;
_L3:
Downloadable.closeSilently(bufferedOutputStream);
Downloadable.closeSilently(outputStream);
Downloadable.closeSilently(inputStream);
_L2:
if(entries.hasMoreElements()) goto _L5; else goto _L4
_L4:
break MISSING_BLOCK_LABEL_339;
Exception exception1;
exception1;
zip.close();
throw exception1;
zip.close();
_L1:
if(iterator.hasNext()) goto _L7; else goto _L6
_L6:
}
입니다, 그래서 형식에 도움/태그 환영입니다 .
goto는 Java에서 기능이 없습니다. 예약 키워드이지만 아무 것도하지 않으므로 소스에 나타나는대로 사용할 수 없습니다. – berry120
if/else, for, while, do/while 또는 switch 문이 어셈블리 언어로 변환되고 사용자가 보유한 문을 파악한 다음 다시 번역하는 방법을 이해하기 만하면됩니다. 그것은 단지 일이며 마술은 아닙니다. –
예를 들어, 위의 맨 마지막 실행 문은 대부분의 메서드에 걸쳐 do/while의 while 문처럼 보입니다. 그러나 당신이 가까이에서 보면 맨 위부터 L1까지의 점프가 있습니다. 그래서 그것은 정말 간단한 진술입니다. –