@Override
 public IHyperlink[] detectHyperlinks(
     ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
   if (controller == null || controller.getLastCompilationUnit() == null) {
     return null;
   } else {
     Node node =
         findNode(
             controller.getLastCompilationUnit(),
             controller.getTokens(),
             region.getOffset(),
             region.getOffset() + region.getLength());
     if (node == null) {
       return null;
     } else {
       Node id = getIdentifyingNode(node);
       if (id == null) {
         return null;
       } else {
         Referenceable referenceable = getReferencedModel(node);
         Backends supportedBackends = supportedBackends();
         if (referenceable instanceof Declaration) {
           Declaration dec = (Declaration) referenceable;
           if (dec.isNative()) {
             if (supportedBackends.none()) {
               return null;
             } else {
               referenceable = resolveNative(referenceable, dec, supportedBackends);
             }
           } else {
             if (!supportedBackends.none()) {
               return null;
             }
           }
         } else { // Module or package descriptors
           if (!supportedBackends.none()) {
             return null;
           }
         }
         Node r = getReferencedNode(referenceable);
         if (r == null) {
           return null;
         } else {
           return new IHyperlink[] {new CeylonNodeLink(r, id)};
         }
       }
     }
   }
 }
  private Referenceable resolveNative(
      Referenceable referenceable, Declaration dec, Backends backends) {
    Unit unit = dec.getUnit();
    Scope containerToSearchHeaderIn = null;
    if (unit instanceof CeylonBinaryUnit) {
      CeylonBinaryUnit binaryUnit = (CeylonBinaryUnit) unit;
      ExternalPhasedUnit phasedUnit = binaryUnit.getPhasedUnit();
      if (phasedUnit != null) {
        ExternalSourceFile sourceFile = phasedUnit.getUnit();
        if (sourceFile != null) {
          String sourceRelativePath =
              toJavaString(
                  binaryUnit
                      .getCeylonModule()
                      .toSourceUnitRelativePath(toCeylonString(unit.getRelativePath())));
          if (sourceRelativePath != null && sourceRelativePath.endsWith(".ceylon")) {
            for (Declaration sourceDecl : sourceFile.getDeclarations()) {
              if (sourceDecl.equals(dec)) {
                containerToSearchHeaderIn = sourceDecl.getContainer();
                break;
              }
            }
          } else {
            for (Declaration sourceDecl : sourceFile.getDeclarations()) {
              if (sourceDecl.getQualifiedNameString().equals(dec.getQualifiedNameString())) {
                containerToSearchHeaderIn = sourceDecl.getContainer();
                break;
              }
            }
          }
        }
      }
    } else {
      containerToSearchHeaderIn = dec.getContainer();
    }

    if (containerToSearchHeaderIn != null) {
      Declaration headerDeclaration = getNativeHeader(containerToSearchHeaderIn, dec.getName());
      if (headerDeclaration == null || !headerDeclaration.isNative()) return null;
      if (backends.header()) {
        referenceable = headerDeclaration;
      } else {
        if (headerDeclaration != null) {
          referenceable = getNativeDeclaration(headerDeclaration, supportedBackends());
        }
      }
    }
    return referenceable;
  }
Exemple #3
0
 private void addWildcardImport(ImportList il, Declaration dec, Import i) {
   if (notOverloaded(dec)) {
     String alias = i.getAlias();
     if (alias != null) {
       Import o = unit.getImport(dec.getName());
       if (o != null && o.isWildcardImport()) {
         if (o.getDeclaration().equals(dec) || dec.isNativeHeader()) {
           // this case only happens in the IDE,
           // due to reuse of the Unit
           unit.getImports().remove(o);
           il.getImports().remove(o);
         } else if (!dec.isNative()) {
           i.setAmbiguous(true);
           o.setAmbiguous(true);
         }
       }
       unit.getImports().add(i);
       il.getImports().add(i);
     }
   }
 }