forked from java-decompiler/jd-gui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes bug in META-INF/services/* indexer
- Loading branch information
Showing
3 changed files
with
138 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
services/src/main/groovy/jd/gui/view/component/OneTypeReferenceByLinePage.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* Copyright (c) 2008-2015 Emmanuel Dupuy | ||
* This program is made available under the terms of the GPLv3 License. | ||
*/ | ||
package jd.gui.view.component | ||
|
||
import jd.gui.api.API | ||
import jd.gui.api.feature.IndexesChangeListener | ||
import jd.gui.api.feature.UriGettable | ||
import jd.gui.api.model.Container | ||
import jd.gui.api.model.Indexes | ||
|
||
import java.awt.Point | ||
|
||
class OneTypeReferenceByLinePage extends TypeReferencePage implements UriGettable, IndexesChangeListener { | ||
protected API api | ||
protected Container.Entry entry | ||
protected Collection<Indexes> collectionOfIndexes | ||
|
||
OneTypeReferenceByLinePage(API api, Container.Entry entry) { | ||
this.api = api | ||
this.entry = entry | ||
// Load content file | ||
def text = entry.inputStream.text.replace('\r\n', '\n').replace('\r', '\n') | ||
// Create hyperlinks | ||
int offset = 0 | ||
|
||
text.eachLine { String line -> | ||
def trim = line.trim() | ||
|
||
if (trim) { | ||
int startIndex = offset + line.indexOf(trim) | ||
int endIndex = startIndex + trim.length() | ||
def internalTypeName = trim.replace('.', '/') | ||
|
||
addHyperlink(new TypeReferencePage.TypeHyperlinkData(startIndex, endIndex, internalTypeName)) | ||
} | ||
|
||
offset += line.length() + 1 | ||
} | ||
// Display | ||
setText(text) | ||
// Show hyperlinks | ||
indexesChanged(api.collectionOfIndexes) | ||
} | ||
|
||
protected boolean isHyperlinkEnabled(HyperlinkPage.HyperlinkData hyperlinkData) { hyperlinkData.enabled } | ||
|
||
protected void openHyperlink(int x, int y, HyperlinkPage.HyperlinkData hyperlinkData) { | ||
if (hyperlinkData.enabled) { | ||
// Save current position in history | ||
def location = textArea.getLocationOnScreen() | ||
int offset = textArea.viewToModel(new Point(x-location.x as int, y-location.y as int)) | ||
def uri = entry.uri | ||
api.addURI(new URI(uri.scheme, uri.authority, uri.path, 'position=' + offset, null)) | ||
|
||
// Open link | ||
def internalTypeName = hyperlinkData.internalTypeName | ||
def entries = collectionOfIndexes?.collect { it.getIndex('typeDeclarations')?.get(internalTypeName) }.flatten().grep { it!=null } | ||
def rootUri = entry.container.root.uri.toString() | ||
def sameContainerEntries = entries?.grep { it.uri.toString().startsWith(rootUri) } | ||
|
||
if (sameContainerEntries) { | ||
api.openURI(x, y, sameContainerEntries, null, hyperlinkData.internalTypeName) | ||
} else if (entries) { | ||
api.openURI(x, y, entries, null, hyperlinkData.internalTypeName) | ||
} | ||
} | ||
} | ||
|
||
// --- UriGettable --- // | ||
URI getUri() { entry.uri } | ||
|
||
// --- ContentSavable --- // | ||
String getFileName() { | ||
def path = entry.path | ||
int index = path.lastIndexOf('/') | ||
return path.substring(index+1) | ||
} | ||
|
||
// --- IndexesChangeListener --- // | ||
void indexesChanged(Collection<Indexes> collectionOfIndexes) { | ||
// Update the list of containers | ||
this.collectionOfIndexes = collectionOfIndexes | ||
// Refresh links | ||
boolean refresh = false | ||
|
||
for (def entry : hyperlinks.entrySet()) { | ||
def data = entry.value | ||
def internalTypeName = data.internalTypeName | ||
boolean enabled = collectionOfIndexes.find { it.getIndex('typeDeclarations')?.get(internalTypeName) } != null | ||
|
||
if (data.enabled != enabled) { | ||
data.enabled = enabled | ||
refresh = true | ||
} | ||
} | ||
|
||
if (refresh) { | ||
textArea.repaint() | ||
} | ||
} | ||
} |