Package org.eclipse.jdt.core

Examples of org.eclipse.jdt.core.ISourceRange


        }

        // get Java range, translate coordinate to JSP

        try {
          ISourceRange range = null;
          IJSPTranslation jspTranslation = getJSPTranslation(document);
          if (jspTranslation != null) {
            // link to local variable definitions
            if (element instanceof ILocalVariable) {
              range = ((ILocalVariable) element).getNameRange();
              Object cu = ((ILocalVariable) element).getDeclaringMember().getCompilationUnit();
              if (cu != null && cu.equals(jspTranslation.getCompilationUnit()))
                isInTranslationCU = true;
            }
            // linking to fields of the same compilation unit
            else if (element.getElementType() == IJavaElement.FIELD) {
              Object cu = ((IField) element).getCompilationUnit();
              if (cu != null && cu.equals(jspTranslation.getCompilationUnit())) {
                range = ((ISourceReference) element).getSourceRange();
                isInTranslationCU = true;
              }
            }
            // linking to methods of the same compilation unit
            else if (element.getElementType() == IJavaElement.METHOD) {
              Object cu = ((IMethod) element).getCompilationUnit();
              if (cu != null && cu.equals(jspTranslation.getCompilationUnit())) {
                range = ((ISourceReference) element).getSourceRange();
                isInTranslationCU = true;
              }
            }
          }

          if (range != null && file != null) {
            jspOffset = jspTranslation.getJspOffset(range.getOffset());
            if (jspOffset >= 0) {
              link = new WorkspaceFileHyperlink(region, file, new Region(jspOffset, range.getLength()));
            }
          }
        }
        catch (JavaModelException jme) {
          Logger.log(Logger.WARNING_DEBUG, jme.getMessage(), jme);
View Full Code Here


    IJavaProject javaProject = JavaCore.create(getProject());
    SingletonDependencyFinder finder = new SingletonDependencyFinder(projectModel);
    Dependency[] dependencies = finder.findSingletonDependencies(singleton, interfacesToSearchFor);
   
    IType type = javaProject.findType(singleton);
    ISourceRange sourceRange = type.getSourceRange();

    CompilationUnit compilationUnit = cache.getCompilationUnit(type.getCompilationUnit());
    TypeDeclaration typeDeclaration = cache.getTypeDeclaration(type);
    IAnnotationBinding[] annotations = typeDeclaration.resolveBinding().getAnnotations();

    List<String> declaredDependencies = new ArrayList<String>();

    for (IAnnotationBinding annotation : annotations) {
      if ("javax.ejb.DependsOn".equals(annotation.getAnnotationType().getQualifiedName())) {
        IMemberValuePairBinding[] pairs = annotation.getDeclaredMemberValuePairs();
        for (int i = 0; i < pairs.length; i++) {
          if ("value".equals(pairs[i].getName())) {
            if (pairs[i].getValue() instanceof Object[]) {
              Object[] values = (Object[]) pairs[i].getValue();
              for (int j = 0; j < values.length; j++) {
                declaredDependencies.add(values[j].toString());
              }
            }
          }
        }
      }
    }

    List<String> expectedDependencies = new ArrayList<String>();

    if (dependencies != null) {
      for (Dependency dependency : dependencies) {
        expectedDependencies.add(dependency.getDependsOn());
      }
    }

    boolean matches = expectedDependencies.size() == declaredDependencies.size();

    if (matches) {
      for (String dependency : declaredDependencies) {
        if (!expectedDependencies.contains(dependency)) {
          matches = false;
          break;
        }
      }
    }

    if (!matches) {
      IMarker marker = type.getUnderlyingResource().createMarker(MARKER_TYPE_DEPENDS_ON);
      Map attributes = new HashMap();

      attributes.put(IMarker.LINE_NUMBER, compilationUnit.getLineNumber(sourceRange.getOffset()));
      attributes.put(IMarker.CHAR_START, sourceRange.getOffset());
      attributes.put(IMarker.CHAR_END, sourceRange.getOffset() + sourceRange.getLength());
      attributes.put(IMarker.LINE_NUMBER, compilationUnit.getLineNumber(sourceRange.getOffset()));
      attributes.put(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
      attributes.put(IMarker.MESSAGE, expectedDependencies.size() == 0 ? "This bean should not have the @DependsOn annotation" : "This bean requires the @DependsOn annotation, and depends on: " + getDependencyList(expectedDependencies));
      attributes.put(ISingletonDependencyMarker.DEPENDENCIES, expectedDependencies.toArray(new String[expectedDependencies.size()]));
      attributes.put(ISingletonDependencyMarker.BEAN, singleton);
      marker.setAttributes(attributes);
View Full Code Here

                SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));

        // Work around for bug 164121. Force match for formal
        // parameters.
        if (je.getElementType() == IJavaElement.LOCAL_VARIABLE) {
          final ISourceRange isr = ((ILocalVariable) je)
              .getNameRange();
          final SearchMatch match = new SearchMatch(je,
              SearchMatch.A_ACCURATE, isr.getOffset(), isr
                  .getLength(), SearchEngine
                  .getDefaultSearchParticipant(), je
                  .getResource());
          requestor.acceptSearchMatch(match);
        }
View Full Code Here

    case ASTNode.INFIX_EXPRESSION: {
      final InfixExpression iexp = (InfixExpression) node;
      final InfixExpression.Operator op = iexp.getOperator();
      if (Util.isLegalInfixOperator(op)) {
        if (Util.inNeedOfTransformation(op)) {
          final ISourceRange range = new SourceRange(iexp
              .getStartPosition(), iexp.getLength());
          this.legalEncounteredInfixExpressionSourceLocations
              .add(range);
        }
        this.processExpression(iexp.getLeftOperand());
View Full Code Here

    case ASTNode.INFIX_EXPRESSION: {
      final InfixExpression ie = (InfixExpression) node;
      final InfixExpression.Operator op = ie.getOperator();
      if (Util.isLegalInfixOperator(op)) {
        if (Util.inNeedOfTransformation(op)) {
          final ISourceRange range = new SourceRange(ie
              .getStartPosition(), ie.getLength());
          this.legalEncounteredInfixExpressionSourceLocations
              .add(range);
        }
        this.processExpression(ie.getLeftOperand());
View Full Code Here

        if (field == null || type == null) {
            return;
        }

        IField ifield = type.getField(field.getFieldName());
        ISourceRange sourceRange = null;
        IScanner scanner = null;
        JavaModelException ex = null;
        try {
            sourceRange = ifield.getNameRange();
        } catch (JavaModelException e) {
            ex = e;
        }
        try {
            // second try...
            if (sourceRange == null) {
                sourceRange = ifield.getSourceRange();
            }
            scanner = initScanner(type, sourceRange);
        } catch (JavaModelException e) {
            String message = "Can not complete field annotation " + field + " for the field: " + ifield + " in class: "
                    + qualifiedClassName + ", type " + type + ", bug " + bug;
            if (ex != null) {
                // report only first one
                e = ex;
            }
            FindbugsPlugin.getDefault().logMessage(IStatus.WARNING, message, e);
        }
        if (scanner == null || sourceRange == null) {
            return;
        }
        int lineNbr = scanner.getLineNumber(sourceRange.getOffset());
        lineNbr = lineNbr <= 0 ? 1 : lineNbr;
        String sourceFileStr = getSourceFileHint(type, qualifiedClassName);
        field.setSourceLines(new SourceLineAnnotation(qualifiedClassName, sourceFileStr, lineNbr, lineNbr, 0, 0));
    }
View Full Code Here

    /**
     * @return start line of given type, or 1 if line could not be found
     */
    private static int getLineStart(IType source) throws JavaModelException {
        ISourceRange range = source.getNameRange();
        if (range == null) {
            range = source.getSourceRange();
        }
        IScanner scanner = initScanner(source, range);
        if (scanner != null && range != null) {
            return scanner.getLineNumber(range.getOffset());
        }
        return START_LINE_OF_ENCLOSING_TYPE;
    }
View Full Code Here

      if (annotation == null) {
        continue;
      }
      // update @UiHandler name
      {
        ISourceRange annoRange = annotation.getSourceRange();
        ISourceRange nameRange = annotation.getNameRange();
        int nameEnd = nameRange.getOffset() + nameRange.getLength();
        int annoEnd = annoRange.getOffset() + annoRange.getLength();
        change.addEdit(new ReplaceEdit(nameEnd, annoEnd - nameEnd, "(\"" + m_newName + "\")"));
      }
      // rename method
      String methodName = method.getElementName();
View Full Code Here

        MessageDialog.openConfirm(this.getShell(), "title2", "message");
      }
      IMethod suiteMethod = suiteType.getMethod("suite", new String[] {}); //$NON-NLS-1$
      if (suiteMethod.exists()) {
        try {
          ISourceRange range = suiteMethod.getSourceRange();
          IBuffer buf = cu.getBuffer();
          String originalContent = buf.getText(range.getOffset(),
              range.getLength());
          if (UpdateTestSuite4
              .getTestSuiteClassListRange(originalContent) == null) {
            cannotUpdateSuiteError();
            return false;
          }
View Full Code Here

//          for (Object object : objects) {
//            String clazz = String.valueOf(object);
//            System.out.println(clazz);
//          }
//        }
        ISourceRange range = fTestSuite.getSourceRange();
        IBuffer buf = fTestSuite.getBuffer();
        String originalContent = buf.getText(range.getOffset(), range
            .getLength());
        buf.close();
        if (getTestSuiteClassListRange(originalContent) != null) {
          CheckedTableSelectionDialog dialog = new CheckedTableSelectionDialog(
              fShell, lprovider, cprovider);
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.core.ISourceRange

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.