2626import java .util .HashMap ;
2727import java .util .List ;
2828import java .util .Map ;
29- import java .util .Set ;
3029import org .eclipse .jdt .core .compiler .CharOperation ;
3130import org .eclipse .jdt .core .compiler .InvalidInputException ;
3231import org .eclipse .jdt .internal .compiler .ast .TypeReference ;
@@ -1394,30 +1393,8 @@ protected boolean parseReference() throws InvalidInputException {
13941393 return parseReference (false );
13951394 }
13961395
1397- // Checks if current identifier is a URL scheme (http, https, ftp, etc.)
1398- private boolean isURLScheme (char [] identifier ) {
1399- return CharOperation .equals ("http" .toCharArray (), identifier ) || //$NON-NLS-1$
1400- CharOperation .equals ("https" .toCharArray (), identifier ) || //$NON-NLS-1$
1401- CharOperation .equals ("ftp" .toCharArray (), identifier ) || //$NON-NLS-1$
1402- CharOperation .equals ("file" .toCharArray (), identifier ); //$NON-NLS-1$
1403- }
1404-
1405- // Checks if the current position is followed by "://" URL pattern
1406- private boolean isFollowedByURLPattern () {
1407- int pos = this .scanner .currentPosition ;
1408- try {
1409- if (pos + 2 >= this .source .length ) return false ;
1410-
1411- return this .source [pos ] == ':' &&
1412- this .source [pos + 1 ] == '/' &&
1413- this .source [pos + 2 ] == '/' ;
1414- } catch (Exception e ) {
1415- return false ;
1416- }
1417- }
1418-
14191396 // Parses a complete URL reference starting from current position
1420- private Object parseURLReference (boolean httpFlag ) throws InvalidInputException {
1397+ private Object parseURLReference () throws InvalidInputException {
14211398 // httpFlag is used to check wheather URL contains http or not
14221399 StringBuilder urlBuilder = new StringBuilder ();
14231400 int firstTokenStartPos = this .scanner .startPosition ;
@@ -1428,75 +1405,34 @@ private Object parseURLReference(boolean httpFlag) throws InvalidInputException
14281405 }
14291406 char [] fullURL ;
14301407 int pos ;
1431- if (httpFlag ) {
1432- // Add :
1433- TerminalToken token1 = readTokenSafely ();
1434- if (token1 == TerminalToken .TokenNameCOLON ) {
1435- urlBuilder .append (this .scanner .getCurrentTokenSource ());
1436- consumeToken ();
1437- }
14381408
1439- pos = this .scanner .getCurrentTokenEndPosition () + 1 ;
1440- char c ;
1441- while (pos < this .source .length ) {
1442- c = (this .source [pos ] == ')' ) ? this .source [pos ] : readChar ();
1443-
1444- if (c == ':' ) continue ;
1445- if (c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '*' || c == ')' || c == '(' || c == '[' || c == ']' ) {
1446- break ;
1447- }
1448- urlBuilder .append (c );
1449- pos ++;
1450- }
1451- fullURL = urlBuilder .toString ().toCharArray ();
1452- } else {
1409+ TerminalToken token1 = readTokenSafely ();
1410+ if (token1 == TerminalToken .TokenNameCOLON ) {
1411+ urlBuilder .append (this .scanner .getCurrentTokenSource ());
1412+ consumeToken ();
1413+ }
14531414
1454- //process the second token
1455- TerminalToken token1 = readTokenSafely ();
1456- if (token1 == TerminalToken .TokenNameDOT ) {
1457- urlBuilder .append (this .scanner .getCurrentTokenSource ());
1458- consumeToken ();
1459- }
1415+ pos = this .scanner .getCurrentTokenEndPosition () + 1 ;
1416+ char c ;
1417+ while (pos < this .source .length ) {
1418+ c = (this .source [pos ] == ')' ) ? this .source [pos ] : readChar ();
14601419
1461- TerminalToken token2 = readTokenSafely () ;
1462- if (token2 == TerminalToken . TokenNameIdentifier ) {
1463- urlBuilder . append ( this . scanner . getCurrentTokenSource ()) ;
1464- }
1465- pos = this . scanner . getCurrentTokenEndPosition () + 1 ;
1466- fullURL = urlBuilder . toString (). toCharArray () ;
1420+ if ( c == ':' ) continue ;
1421+ if (c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '*' || c == ')' || c == '(' || c == '[' || c == ']' ) {
1422+ break ;
1423+ }
1424+ urlBuilder . append ( c ) ;
1425+ pos ++ ;
14671426 }
1427+ fullURL = urlBuilder .toString ().toCharArray ();
1428+
14681429 this .identifierPtr = 0 ;
14691430 this .identifierStack [this .identifierPtr ] = fullURL ;
14701431 this .identifierPositionStack [this .identifierPtr ] = (((long ) firstTokenStartPos ) << 32 ) + (pos - 1 );
14711432 this .identifierLengthStack [this .identifierLengthPtr ] = 1 ;
14721433 return createTypeReference (TokenNameInvalid , true );
14731434 }
14741435
1475- // Ensure the markdown URL bracket syntax follows []() or [][]
1476- private void checkMarkdownLinkSyntaxValid (int currStartPos , boolean httpFlag ) {
1477- // httpFlag is used to check wheather URL contains http or not
1478- char secondBracket = this .source [currStartPos - 2 ];
1479- char thirdBracket = this .source [currStartPos - 1 ];
1480-
1481- char [] generatedURL = this .identifierStack [this .identifierPtr ];
1482- char fourthBracket = this .source [currStartPos + generatedURL .length ];
1483-
1484- String pattern = new String (new char [] {secondBracket , thirdBracket , fourthBracket });
1485- //invalid bracket patterns
1486- Set <String > invalidPatterns = Set .of (
1487- ")[)" , //$NON-NLS-1$
1488- "](]" , //$NON-NLS-1$
1489- ")[]" , //$NON-NLS-1$
1490- "][)" , //$NON-NLS-1$
1491- "([)" , //$NON-NLS-1$
1492- "(][" , //$NON-NLS-1$
1493- "[)(" , //$NON-NLS-1$
1494- "(](" //$NON-NLS-1$
1495- );
1496- if (invalidPatterns .contains (pattern )) this .abort = true ;
1497-
1498- }
1499-
15001436 /*
15011437 * Parse a reference in @see tag
15021438 */
@@ -1593,27 +1529,14 @@ else if (this.tagValue == TAG_VALUE_VALUE) {
15931529 case TokenNameUNDERSCORE :
15941530 case TokenNameIdentifier :
15951531 if (this .markdown ) {
1596- char [] identifier = this .scanner .getCurrentIdentifierSource ();
15971532 int pos1 = this .scanner .getCurrentTokenStartPosition () - 1 ;
15981533 while (pos1 >= 0 && Character .isWhitespace (this .source [pos1 ])) {
15991534 pos1 --;
16001535 }
16011536 if (pos1 >= 0 && this .source [pos1 ] == '(' ) {
1602- if (isURLScheme (identifier )) {
1603- if (isFollowedByURLPattern ()) {
1604- if (typeRef == null ) {
1605- int currStartPos = this .scanner .startPosition ;
1606- typeRefStartPosition = this .scanner .getCurrentTokenStartPosition ();
1607- typeRef = parseURLReference (true );
1608- checkMarkdownLinkSyntaxValid (currStartPos , true );
1609- if (this .abort ) return false ;
1610- }
1611- }
1612- } else if (this .source [this .scanner .getCurrentTokenEndPosition () +1 ] == '.' ) {
1613- int currStartPos = this .scanner .startPosition ;
1537+ if (typeRef == null ) {
16141538 typeRefStartPosition = this .scanner .getCurrentTokenStartPosition ();
1615- typeRef = parseURLReference (false );
1616- checkMarkdownLinkSyntaxValid (currStartPos , true );
1539+ typeRef = parseURLReference ();
16171540 if (this .abort ) return false ;
16181541 }
16191542 }
0 commit comments