当前位置: 首页>>代码示例>>Java>>正文


Java ISourceReference类代码示例

本文整理汇总了Java中org.eclipse.jdt.core.ISourceReference的典型用法代码示例。如果您正苦于以下问题:Java ISourceReference类的具体用法?Java ISourceReference怎么用?Java ISourceReference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ISourceReference类属于org.eclipse.jdt.core包,在下文中一共展示了ISourceReference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: classFileNavigation

import org.eclipse.jdt.core.ISourceReference; //导入依赖的package包/类
private OpenDeclarationDescriptor classFileNavigation(IClassFile classFile, IJavaElement element)
    throws JavaModelException {
  OpenDeclarationDescriptor dto =
      DtoFactory.getInstance().createDto(OpenDeclarationDescriptor.class);
  dto.setPath(classFile.getType().getFullyQualifiedName());
  dto.setLibId(classFile.getAncestor(IPackageFragmentRoot.PACKAGE_FRAGMENT_ROOT).hashCode());
  dto.setBinary(true);
  if (classFile.getSourceRange() != null) {
    if (element instanceof ISourceReference) {
      ISourceRange nameRange = ((ISourceReference) element).getNameRange();
      dto.setOffset(nameRange.getOffset());
      dto.setLength(nameRange.getLength());
    }
  }
  return dto;
}
 
开发者ID:eclipse,项目名称:che,代码行数:17,代码来源:JavaNavigation.java

示例2: toLocation

import org.eclipse.jdt.core.ISourceReference; //导入依赖的package包/类
/**
 * Creates a location for a given java element.
 * Element can be a {@link ICompilationUnit} or {@link IClassFile}
 *
 * @param element
 * @return location or null
 * @throws JavaModelException
 */
public static Location toLocation(IJavaElement element) throws JavaModelException{
	ICompilationUnit unit = (ICompilationUnit) element.getAncestor(IJavaElement.COMPILATION_UNIT);
	IClassFile cf = (IClassFile) element.getAncestor(IJavaElement.CLASS_FILE);
	if (unit == null && cf == null) {
		return null;
	}
	if (element instanceof ISourceReference) {
		ISourceRange nameRange = getNameRange(element);
		if (SourceRange.isAvailable(nameRange)) {
			if (cf == null) {
				return toLocation(unit, nameRange.getOffset(), nameRange.getLength());
			} else {
				return toLocation(cf, nameRange.getOffset(), nameRange.getLength());
			}
		}
	}
	return null;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:27,代码来源:JDTUtils.java

示例3: getNameRange

import org.eclipse.jdt.core.ISourceReference; //导入依赖的package包/类
private static ISourceRange getNameRange(IJavaElement element) throws JavaModelException {
	ISourceRange nameRange = null;
	if (element instanceof IMember) {
		IMember member = (IMember) element;
		nameRange = member.getNameRange();
		if ( (!SourceRange.isAvailable(nameRange))) {
			nameRange = member.getSourceRange();
		}
	} else if (element instanceof ITypeParameter || element instanceof ILocalVariable) {
		nameRange = ((ISourceReference) element).getNameRange();
	} else if (element instanceof ISourceReference) {
		nameRange = ((ISourceReference) element).getSourceRange();
	}
	if (!SourceRange.isAvailable(nameRange) && element.getParent() != null) {
		nameRange = getNameRange(element.getParent());
	}
	return nameRange;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:19,代码来源:JDTUtils.java

示例4: getSortedChildren

import org.eclipse.jdt.core.ISourceReference; //导入依赖的package包/类
private ArrayList<IJavaElement> getSortedChildren(IType parent) throws JavaModelException {
  IJavaElement[] children = parent.getChildren();
  ArrayList<IJavaElement> sortedChildren = new ArrayList<IJavaElement>(Arrays.asList(children));
  Collections.sort(
      sortedChildren,
      new Comparator<IJavaElement>() {
        public int compare(IJavaElement e1, IJavaElement e2) {
          if (!(e1 instanceof ISourceReference)) return 0;
          if (!(e2 instanceof ISourceReference)) return 0;

          try {
            ISourceRange sr1 = ((ISourceReference) e1).getSourceRange();
            ISourceRange sr2 = ((ISourceReference) e2).getSourceRange();
            if (sr1 == null || sr2 == null) return 0;

            return sr1.getOffset() - sr2.getOffset();

          } catch (JavaModelException e) {
            return 0;
          }
        }
      });
  return sortedChildren;
}
 
开发者ID:eclipse,项目名称:che,代码行数:25,代码来源:ReorgPolicyFactory.java

示例5: getUsedIndentation

import org.eclipse.jdt.core.ISourceReference; //导入依赖的package包/类
/**
 * Evaluates the indentation used by a Java element. (in tabulators)
 */
private int getUsedIndentation(IJavaElement elem) throws JavaModelException {
    if (elem instanceof ISourceReference) {
        ICompilationUnit cu = (ICompilationUnit) elem.getAncestor(IJavaElement.COMPILATION_UNIT);
        if (cu != null) {
            IBuffer buf = cu.getBuffer();
            int offset = ((ISourceReference) elem).getSourceRange().getOffset();
            int i = offset;
            // find beginning of line
            while (i > 0 && !isLineDelimiterChar(buf.getChar(i - 1))) {
                i--;
            }
            return computeIndent(buf.getText(i, offset - i), getTabWidth());
        }
    }
    return 0;
}
 
开发者ID:maximeAudrain,项目名称:jenerate,代码行数:20,代码来源:JavaCodeFormatterImpl.java

示例6: getSortedChildren

import org.eclipse.jdt.core.ISourceReference; //导入依赖的package包/类
private ArrayList<IJavaElement> getSortedChildren(IType parent) throws JavaModelException {
	IJavaElement[] children= parent.getChildren();
	ArrayList<IJavaElement> sortedChildren= new ArrayList<IJavaElement>(Arrays.asList(children));
	Collections.sort(sortedChildren, new Comparator<IJavaElement>() {
		public int compare(IJavaElement e1, IJavaElement e2) {
			if (!(e1 instanceof ISourceReference))
				return 0;
			if (!(e2 instanceof ISourceReference))
				return 0;

			try {
				ISourceRange sr1= ((ISourceReference)e1).getSourceRange();
				ISourceRange sr2= ((ISourceReference)e2).getSourceRange();
				if (sr1 == null || sr2 == null)
					return 0;

				return sr1.getOffset() - sr2.getOffset();

			} catch (JavaModelException e) {
				return 0;
			}
		}
	});
	return sortedChildren;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:26,代码来源:ReorgPolicyFactory.java

示例7: createRefactoringStatusContext

import org.eclipse.jdt.core.ISourceReference; //导入依赖的package包/类
static RefactoringStatusContext createRefactoringStatusContext(IJavaElement element) {
	if (element instanceof IMember) {
		return JavaStatusContext.create((IMember) element);
	}
	if (element instanceof ISourceReference) {
		IOpenable openable= element.getOpenable();
		try {
			if (openable instanceof ICompilationUnit) {
				return JavaStatusContext.create((ICompilationUnit) openable, ((ISourceReference) element).getSourceRange());
			} else if (openable instanceof IClassFile) {
				return JavaStatusContext.create((IClassFile) openable, ((ISourceReference) element).getSourceRange());
			}
		} catch (JavaModelException e) {
			// ignore
		}
	}
	return null;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:19,代码来源:GenerateMethodAbstractAction.java

示例8: getOffsetInUnclippedDocument

import org.eclipse.jdt.core.ISourceReference; //导入依赖的package包/类
/**
 * Computes and returns the offset in the unclipped document based on the given text selection
 * from the clipped document.
 *
 * @param textSelection the text selection
 * @return the offset in the unclipped document or <code>-1</code> if the offset cannot be
 *         computed
 */
private int getOffsetInUnclippedDocument(ITextSelection textSelection) {
	IDocument unclippedDocument= null;
	try {
		unclippedDocument= new Document(((ISourceReference)fCurrentViewInput).getSource());
	} catch (JavaModelException e) {
		return -1;
	}
	IDocument clippedDoc= (IDocument)fViewer.getInput();
	try {
		IRegion unclippedLineInfo= unclippedDocument.getLineInformation(fCommentLineCount + textSelection.getStartLine());
		IRegion clippedLineInfo= clippedDoc.getLineInformation(textSelection.getStartLine());
		int removedIndentation= unclippedLineInfo.getLength() - clippedLineInfo.getLength();
		int relativeLineOffset= textSelection.getOffset() - clippedLineInfo.getOffset();
		return unclippedLineInfo.getOffset() + removedIndentation + relativeLineOffset ;
	} catch (BadLocationException ex) {
		return -1;
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:27,代码来源:SourceView.java

示例9: setSelection

import org.eclipse.jdt.core.ISourceReference; //导入依赖的package包/类
public void setSelection(IJavaElement element) {

		if (element == null || element instanceof ICompilationUnit || element instanceof IClassFile) {
			/*
			 * If the element is an ICompilationUnit this unit is either the input
			 * of this editor or not being displayed. In both cases, nothing should
			 * happened. (http://dev.eclipse.org/bugs/show_bug.cgi?id=5128)
			 */
			return;
		}

		IJavaElement corresponding= getCorrespondingElement(element);
		if (corresponding instanceof ISourceReference) {
			ISourceReference reference= (ISourceReference) corresponding;
			// set highlight range
			setSelection(reference, true);
			// set outliner selection
			if (fOutlinePage != null)
				fOutlinePage.select(reference);
		}
	}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:22,代码来源:JavaEditor.java

示例10: showBreadcrumb

import org.eclipse.jdt.core.ISourceReference; //导入依赖的package包/类
/**
 * Makes the breadcrumb visible. Creates its content
 * if this is the first time it is made visible.
 *
 * @since 3.4
 */
private void showBreadcrumb() {
	if (fBreadcrumb == null)
		return;

	if (fBreadcrumbComposite.getChildren().length == 0) {
		fBreadcrumb.createContent(fBreadcrumbComposite);
	}

	((GridData) fBreadcrumbComposite.getLayoutData()).exclude= false;
	fBreadcrumbComposite.setVisible(true);

	ISourceReference selection= computeHighlightRangeSourceReference();
	if (selection == null)
		selection= getInputJavaElement();
	setBreadcrumbInput(selection);
	fBreadcrumbComposite.getParent().layout(true, true);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:24,代码来源:JavaEditor.java

示例11: internalGetNewSelectionRange

import org.eclipse.jdt.core.ISourceReference; //导入依赖的package包/类
@Override
ISourceRange internalGetNewSelectionRange(ISourceRange oldSourceRange, ISourceReference sr, SelectionAnalyzer selAnalyzer) throws JavaModelException{
	if (oldSourceRange.getLength() == 0 && selAnalyzer.getLastCoveringNode() != null) {
		ASTNode previousNode= NextNodeAnalyzer.perform(oldSourceRange.getOffset(), selAnalyzer.getLastCoveringNode());
		if (previousNode != null)
			return getSelectedNodeSourceRange(sr, previousNode);
	}
	ASTNode first= selAnalyzer.getFirstSelectedNode();
	if (first == null)
		return getLastCoveringNodeRange(oldSourceRange, sr, selAnalyzer);

	ASTNode parent= first.getParent();
	if (parent == null)
		return getLastCoveringNodeRange(oldSourceRange, sr, selAnalyzer);

	ASTNode lastSelectedNode= selAnalyzer.getSelectedNodes()[selAnalyzer.getSelectedNodes().length - 1];
	ASTNode nextNode= getNextNode(parent, lastSelectedNode);
	if (nextNode == parent)
		return getSelectedNodeSourceRange(sr, first.getParent());
	int offset= oldSourceRange.getOffset();
	int end= Math.min(sr.getSourceRange().getLength(), nextNode.getStartPosition() + nextNode.getLength() - 1);
	return StructureSelectionAction.createSourceRange(offset, end);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:24,代码来源:StructureSelectNextAction.java

示例12: isEnabled

import org.eclipse.jdt.core.ISourceReference; //导入依赖的package包/类
protected boolean isEnabled(ISelection selection) {
	if (selection instanceof IStructuredSelection) {
		Object[] sel= ((IStructuredSelection) selection).toArray();
		if (sel.length == 2) {
			for (int i= 0; i < 2; i++) {
				Object o= sel[i];
				if (!(o instanceof ISourceReference))
					return false;
			}
			fLeft= (ISourceReference) sel[0];
			fRight= (ISourceReference) sel[1];
			return true;
		}
	}
	return false;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:17,代码来源:JavaCompareAction.java

示例13: getPackageContents

import org.eclipse.jdt.core.ISourceReference; //导入依赖的package包/类
private Object[] getPackageContents(IPackageFragment fragment) throws JavaModelException {
	ISourceReference[] sourceRefs;
	if (fragment.getKind() == IPackageFragmentRoot.K_SOURCE) {
		sourceRefs= fragment.getCompilationUnits();
	}
	else {
		IClassFile[] classFiles= fragment.getClassFiles();
		List<IClassFile> topLevelClassFile= new ArrayList<IClassFile>();
		for (int i= 0; i < classFiles.length; i++) {
			IType type= classFiles[i].getType();
			if (type != null && type.getDeclaringType() == null && !type.isAnonymous() && !type.isLocal())
				topLevelClassFile.add(classFiles[i]);
		}
		sourceRefs= topLevelClassFile.toArray(new ISourceReference[topLevelClassFile.size()]);
	}

	Object[] result= new Object[0];
	for (int i= 0; i < sourceRefs.length; i++)
		result= concatenate(result, removeImportAndPackageDeclarations(getChildren(sourceRefs[i])));
	return concatenate(result, fragment.getNonJavaResources());
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:22,代码来源:JavaBrowsingContentProvider.java

示例14: verify

import org.eclipse.jdt.core.ISourceReference; //导入依赖的package包/类
/**
 * @see MultiOperation
 */
protected void verify(IJavaElement element) throws JavaModelException {
	if (element == null || !element.exists())
		error(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, element);

	if (element.isReadOnly())
		error(IJavaModelStatusConstants.READ_ONLY, element);

	if (!(element instanceof ISourceReference))
		error(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, element);

	int elementType = element.getElementType();
	if (elementType < IJavaElement.TYPE || elementType == IJavaElement.INITIALIZER)
		error(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, element);

	verifyRenaming(element);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:20,代码来源:RenameElementsOperation.java

示例15: getErrorTicksFromAnnotationModel

import org.eclipse.jdt.core.ISourceReference; //导入依赖的package包/类
private int getErrorTicksFromAnnotationModel(IAnnotationModel model, ISourceReference sourceElement) throws CoreException {
	int info= 0;
	Iterator<Annotation> iter= model.getAnnotationIterator();
	while ((info != ERRORTICK_ERROR) && iter.hasNext()) {
		Annotation annot= iter.next();
		IMarker marker= isAnnotationInRange(model, annot, sourceElement);
		if (marker != null) {
			int priority= marker.getAttribute(IMarker.SEVERITY, -1);
			if (priority == IMarker.SEVERITY_WARNING) {
				info= ERRORTICK_WARNING;
			} else if (priority == IMarker.SEVERITY_ERROR) {
				info= ERRORTICK_ERROR;
			}
		}
	}
	return info;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:18,代码来源:ProblemsLabelDecorator.java


注:本文中的org.eclipse.jdt.core.ISourceReference类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。