Skip to content

Commit

Permalink
Fixes issue on display of links
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanue1 committed Mar 29, 2015
1 parent 47b05c2 commit a2bf0c6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,10 @@ import jd.gui.util.decompiler.ContainerLoader
import jd.gui.util.decompiler.GuiPreferences
import org.fife.ui.rsyntaxtextarea.DocumentRange
import org.fife.ui.rsyntaxtextarea.SyntaxConstants
import org.fife.ui.rsyntaxtextarea.folding.FoldManager

import javax.swing.text.BadLocationException
import javax.swing.text.DefaultCaret
import java.awt.Color
import java.awt.Insets
import java.awt.Point
import java.awt.Rectangle
import java.util.regex.Pattern

class ClassFilePage
Expand Down Expand Up @@ -54,11 +50,11 @@ class ClassFilePage

static {
// Early class loading
def internalPath = ClassFilePage.class.name.replace('.', '/')
def internalTypeName = ClassFilePage.class.name.replace('.', '/')
def preferences = new GuiPreferences()
def loader = new Loader() {
DataInputStream load(String internalTypePath) throws LoaderException {
return new DataInputStream(ClassFilePage.class.classLoader.getResourceAsStream(internalPath + '.class'))
return new DataInputStream(ClassFilePage.class.classLoader.getResourceAsStream(internalTypeName + '.class'))
}
boolean canLoad(String internalTypePath) { false }
}
Expand All @@ -70,7 +66,7 @@ class ClassFilePage
void append(char c) {}
void append(String s) {}
}
DECOMPILER.decompile(preferences, loader, printer, internalPath)
DECOMPILER.decompile(preferences, loader, printer, internalTypeName)
}

ClassFilePage(API api, Container.Entry entry) {
Expand All @@ -91,7 +87,6 @@ class ClassFilePage
declarations.clear()
typeDeclarations.clear()
strings.clear()

// Init preferences
def p = new GuiPreferences()
p.setUnicodeEscape(getPreferenceValue(preferences, ESCAPE_UNICODE_CHARACTERS, false))
Expand All @@ -101,18 +96,14 @@ class ClassFilePage
p.setRealignmentLineNumber(getPreferenceValue(preferences, REALIGN_LINE_NUMBERS, false))

setShowMisalignment(p.realignmentLineNumber)

// Init loader
def loader = new ContainerLoader(entry)

// Init printer
def printer = new Printer(p)

// Decompile class file
DECOMPILER.decompile(p, loader, printer, entry.path)

setText(printer.toString())

// Show hyperlinks
indexesChanged(api.collectionOfIndexes)
} catch (Exception ignore) {
Expand Down Expand Up @@ -286,7 +277,7 @@ class ClassFilePage
}
} else {
// Unknown descriptor ==> Select all and scroll to the first one
def prefix = fragment.substring(0, fragment.lastIndexOf('-' + 1))
def prefix = fragment.substring(0, fragment.lastIndexOf('-') + 1)
boolean method = (fragment.charAt(index - 1) == '(')
int prefixLength = prefix.size()

Expand Down
14 changes: 8 additions & 6 deletions services/src/main/groovy/jd/gui/view/component/LogPage.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class LogPage extends HyperlinkPage implements UriGettable, ContentSavable, Inde
parseLine(content, index, content.size())
// Display
setText(content)
// Show hyperlinks
indexesChanged(api.collectionOfIndexes)
}

protected void parseLine(String content, int index, int eol) {
Expand Down Expand Up @@ -62,17 +64,17 @@ class LogPage extends HyperlinkPage implements UriGettable, ContentSavable, Inde
def typeAndMethodNames = text.substring(hyperlinkData.startPosition, hyperlinkData.endPosition)
int lastDotIndex = typeAndMethodNames.lastIndexOf('.')
def methodName = typeAndMethodNames.substring(lastDotIndex+1)
def typeName = typeAndMethodNames.substring(0, lastDotIndex).replace('.', '/')
def entries = collectionOfIndexes?.collect { it.getIndex('typeDeclarations')?.get(typeName) }.flatten().grep { it!=null }
def internalTypeName = typeAndMethodNames.substring(0, lastDotIndex).replace('.', '/')
def entries = collectionOfIndexes?.collect { it.getIndex('typeDeclarations')?.get(internalTypeName) }.flatten().grep { it!=null }

int leftParenthesisIndex = hyperlinkData.endPosition + 1
int rightParenthesisIndex = text.indexOf(')', leftParenthesisIndex)
def lineNumberOrNativeMethodFlag = text.substring(leftParenthesisIndex, rightParenthesisIndex)

if (lineNumberOrNativeMethodFlag.equals('Native Method')) {
// Example: at java.security.AccessController.doPrivileged(Native Method)
lastDotIndex = typeName.lastIndexOf('/')
def shortTypeName = typeName.substring(lastDotIndex+1)
lastDotIndex = internalTypeName.lastIndexOf('/')
def shortTypeName = internalTypeName.substring(lastDotIndex+1)
api.openURI(x, y, entries, null, shortTypeName + '-' + methodName + '-(?)?')
} else {
// Example: at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
Expand Down Expand Up @@ -109,8 +111,8 @@ class LogPage extends HyperlinkPage implements UriGettable, ContentSavable, Inde
def entryData = entry.value as LogHyperlinkData
def typeAndMethodNames = text.substring(entryData.startPosition, entryData.endPosition)
int lastDotIndex = typeAndMethodNames.lastIndexOf('.')
def typeName = typeAndMethodNames.substring(0, lastDotIndex).replace('.', '/')
boolean enabled = collectionOfIndexes.find { it.getIndex('typeDeclarations')?.get(typeName) } != null
def internalTypeName = typeAndMethodNames.substring(0, lastDotIndex).replace('.', '/')
boolean enabled = collectionOfIndexes.find { it.getIndex('typeDeclarations')?.get(internalTypeName) } != null

if (entryData.enabled != enabled) {
entryData.enabled = enabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package jd.gui.view.component

import groovy.transform.CompileStatic
import jd.gui.api.API
import jd.gui.api.feature.ContentSavable
import jd.gui.api.feature.IndexesChangeListener
Expand All @@ -31,29 +32,30 @@ class ManifestFilePage extends HyperlinkPage implements UriGettable, ContentSava
if (startLineIndex != -1) {
// Example: Main-Class: jd.gui.App
int startIndex = skipSeparators(text, startLineIndex + 'Main-Class:'.size())
int endIndex = searchEndIndexForValue(text, startLineIndex, startIndex)
int endIndex = searchEndIndexOfValue(text, startLineIndex, startIndex)
def typeName = text.substring(startIndex, endIndex)
int lastDotIndex = typeName.lastIndexOf('.')
def shortTypeName = typeName.substring(lastDotIndex+1)
addHyperlink(new ManifestHyperlinkData(startIndex, endIndex, shortTypeName + '-main-(Ljava/lang/String;)V'))
def internalTypeName = typeName.replace('.', '/')
addHyperlink(new ManifestHyperlinkData(startIndex, endIndex, internalTypeName + '-main-([Ljava/lang/String;)V'))
}

startLineIndex = text.indexOf('Premain-Class:')
if (startLineIndex != -1) {
// Example: Premain-Class: packge.JavaAgent
int startIndex = skipSeparators(text, startLineIndex + 'Premain-Class:'.size())
int endIndex = searchEndIndexForValue(text, startLineIndex, startIndex)
int endIndex = searchEndIndexOfValue(text, startLineIndex, startIndex)
def typeName = text.substring(startIndex, endIndex)
int lastDotIndex = typeName.lastIndexOf('.')
def shortTypeName = typeName.substring(lastDotIndex+1)
def internalTypeName = typeName.replace('.', '/')
// Undefined parameters : 2 candidate methods
// http://docs.oracle.com/javase/6/docs/api/java/lang/instrument/package-summary.html
addHyperlink(new ManifestHyperlinkData(startIndex, endIndex, shortTypeName + '-premain-(?)?'))
addHyperlink(new ManifestHyperlinkData(startIndex, endIndex, internalTypeName + '-premain-(?)?'))
}
// Display
setText(text)
// Show hyperlinks
indexesChanged(api.collectionOfIndexes)
}

@CompileStatic
int skipSeparators(String text, int index) {
int length = text.size()

Expand All @@ -70,7 +72,8 @@ class ManifestFilePage extends HyperlinkPage implements UriGettable, ContentSava
return index
}

int searchEndIndexForValue(String text, int startLineIndex, int startIndex) {
@CompileStatic
int searchEndIndexOfValue(String text, int startLineIndex, int startIndex) {
int length = text.size()
int index = startIndex

Expand Down Expand Up @@ -117,12 +120,11 @@ class ManifestFilePage extends HyperlinkPage implements UriGettable, ContentSava
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 text = getText()
def textLink = getValue(text, hyperlinkData.startPosition, hyperlinkData.endPosition)
def typeName = textLink.replace('.', '/')
def entries = collectionOfIndexes?.collect { it.getIndex('typeDeclarations')?.get(typeName) }.flatten().grep { it!=null }
def internalTypeName = textLink.replace('.', '/')
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) }

Expand Down Expand Up @@ -159,8 +161,8 @@ class ManifestFilePage extends HyperlinkPage implements UriGettable, ContentSava
for (def entry : hyperlinks.entrySet()) {
def entryData = entry.value as ManifestHyperlinkData
def textLink = getValue(text, entryData.startPosition, entryData.endPosition)
def typeName = textLink.replace('.', '/')
boolean enabled = collectionOfIndexes.find { it.getIndex('typeDeclarations')?.get(typeName) } != null
def internalTypeName = textLink.replace('.', '/')
boolean enabled = collectionOfIndexes.find { it.getIndex('typeDeclarations')?.get(internalTypeName) } != null

if (entryData.enabled != enabled) {
entryData.enabled = enabled
Expand Down

0 comments on commit a2bf0c6

Please sign in to comment.