Java 类org.eclipse.jdt.core.ILocalVariable 实例源码

项目:eclipse.jdt.ls    文件:JDTUtils.java   
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;
}
项目:eclipse.jdt.ls    文件:JavaElementLabelComposer.java   
/**
 * Appends the styled label for a local variable.
 *
 * @param localVariable the element to render
 * @param flags the rendering flags. Flags with names starting with 'F_' are considered.
 */
public void appendLocalVariableLabel(ILocalVariable localVariable, long flags) {
    if (getFlag(flags, JavaElementLabels.F_PRE_TYPE_SIGNATURE)) {
        appendTypeSignatureLabel(localVariable, localVariable.getTypeSignature(), flags);
        fBuilder.append(' ');
    }

    if (getFlag(flags, JavaElementLabels.F_FULLY_QUALIFIED)) {
        appendElementLabel(localVariable.getDeclaringMember(), JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.M_FULLY_QUALIFIED | JavaElementLabels.T_FULLY_QUALIFIED | (flags & QUALIFIER_FLAGS));
        fBuilder.append('.');
    }

    fBuilder.append(getElementName(localVariable));

    if (getFlag(flags, JavaElementLabels.F_APP_TYPE_SIGNATURE)) {
        fBuilder.append(JavaElementLabels.DECL_STRING);
        appendTypeSignatureLabel(localVariable, localVariable.getTypeSignature(), flags);
    }

    // post qualification
    if (getFlag(flags, JavaElementLabels.F_POST_QUALIFIED)) {
        fBuilder.append(JavaElementLabels.CONCAT_STRING);
        appendElementLabel(localVariable.getDeclaringMember(), JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.M_FULLY_QUALIFIED | JavaElementLabels.T_FULLY_QUALIFIED | (flags & QUALIFIER_FLAGS));
    }
}
项目:eclipse.jdt.ls    文件:GetterSetterCorrectionSubProcessor.java   
private static boolean isAvailable(IJavaElement javaElement) throws JavaModelException {
    if (javaElement == null) {
        return false;
    }
    if (!javaElement.exists()) {
        return false;
    }
    if (javaElement.isReadOnly()) {
        return false;
    }
    // work around for https://bugs.eclipse.org/bugs/show_bug.cgi?id=48422
    // the Java project is now cheating regarding its children so we shouldn't
    // call isStructureKnown if the project isn't open.
    // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=52474
    if (!(javaElement instanceof IJavaProject) && !(javaElement instanceof ILocalVariable) && !javaElement.isStructureKnown()) {
        return false;
    }
    if (javaElement instanceof IMember && ((IMember) javaElement).isBinary()) {
        return false;
    }
    return true;
}
项目:Migrate-Skeletal-Implementation-to-Interface-Refactoring    文件:MigrateSkeletalImplementationToInterfaceRefactoringProcessor.java   
private static boolean parameterListMatches(ILocalVariable[] parameters, IMethod method,
        ILocalVariable[] sourceParameters, IMethod sourceMethod) throws JavaModelException {
    if (parameters.length == sourceParameters.length) {
        for (int i = 0; i < parameters.length; i++) {
            String paramString = Util.getQualifiedNameFromTypeSignature(parameters[i].getTypeSignature(),
                    method.getDeclaringType());
            String sourceParamString = Util.getQualifiedNameFromTypeSignature(
                    sourceParameters[i].getTypeSignature(), sourceMethod.getDeclaringType());

            if (!paramString.equals(sourceParamString))
                return false;
        }
        return true;
    } else
        return false;
}
项目:junit-tools    文件:JDTUtils.java   
public static String createParamList(IMethod method, boolean withParamTypes)
        throws JavaModelException {
    StringBuilder params = new StringBuilder();
    String comma = "";
    for (ILocalVariable variable : method.getParameters()) {
        params.append(comma);
        comma = ", ";

        if (withParamTypes) {
            params.append(
                    Signature.getSignatureSimpleName(variable
                            .getTypeSignature())).append(" ");
        }

        params.append(variable.getElementName());
    }

    return params.toString();
}
项目:che    文件:ParametersHints.java   
private String getMethodParametersAsString(IMethod method) throws JavaModelException {
  ILocalVariable[] parameters = method.getParameters();

  int paramsLength = parameters.length;
  int index = 0;

  StringBuffer buffer = new StringBuffer();

  for (ILocalVariable parameter : parameters) {
    JavaElementLabels.getLocalVariableLabel(
        parameter, JavaElementLabels.F_PRE_TYPE_SIGNATURE, buffer);
    index++;

    if (index < paramsLength) {
      buffer.append(", ");
    }
  }

  return buffer.toString();
}
项目:che    文件:RefactoringManager.java   
private static RenameSupport createRenameSupport(IJavaElement element, String newName, int flags)
    throws CoreException {
  switch (element.getElementType()) {
    case IJavaElement.PACKAGE_FRAGMENT:
      return RenameSupport.create((IPackageFragment) element, newName, flags);
    case IJavaElement.COMPILATION_UNIT:
      return RenameSupport.create((ICompilationUnit) element, newName, flags);
    case IJavaElement.TYPE:
      return RenameSupport.create((IType) element, newName, flags);
    case IJavaElement.METHOD:
      final IMethod method = (IMethod) element;
      if (method.isConstructor())
        return createRenameSupport(method.getDeclaringType(), newName, flags);
      else return RenameSupport.create((IMethod) element, newName, flags);
    case IJavaElement.FIELD:
      return RenameSupport.create((IField) element, newName, flags);
    case IJavaElement.TYPE_PARAMETER:
      return RenameSupport.create((ITypeParameter) element, newName, flags);
    case IJavaElement.LOCAL_VARIABLE:
      return RenameSupport.create((ILocalVariable) element, newName, flags);
  }
  return null;
}
项目:che    文件:RefactoringAvailabilityTester.java   
public static boolean isGeneralizeTypeAvailable(final IJavaElement element)
    throws JavaModelException {
  if (element != null && element.exists()) {
    String type = null;
    if (element instanceof IMethod) type = ((IMethod) element).getReturnType();
    else if (element instanceof IField) {
      final IField field = (IField) element;
      if (JdtFlags.isEnum(field)) return false;
      type = field.getTypeSignature();
    } else if (element instanceof ILocalVariable) return true;
    else if (element instanceof IType) {
      final IType clazz = (IType) element;
      if (JdtFlags.isEnum(clazz)) return false;
      return true;
    }
    if (type == null || PrimitiveType.toCode(Signature.toString(type)) != null) return false;
    return true;
  }
  return false;
}
项目:vsminecraft    文件:JavaElementLabelComposer.java   
/**
 * Appends the styled label for a local variable.
 *
 * @param localVariable the element to render
 * @param flags the rendering flags. Flags with names starting with 'F_' are considered.
 */
public void appendLocalVariableLabel(ILocalVariable localVariable, long flags) {
    if (getFlag(flags, F_PRE_TYPE_SIGNATURE)) {
        appendTypeSignatureLabel(localVariable, localVariable.getTypeSignature(), flags);
        fBuffer.append(' ');
    }

    if (getFlag(flags, F_FULLY_QUALIFIED)) {
        appendElementLabel(localVariable.getDeclaringMember(), M_PARAMETER_TYPES | M_FULLY_QUALIFIED | T_FULLY_QUALIFIED | (flags & QUALIFIER_FLAGS));
        fBuffer.append('.');
    }

    fBuffer.append(getElementName(localVariable));

    if (getFlag(flags, F_APP_TYPE_SIGNATURE)) {
        int offset= fBuffer.length();
        fBuffer.append(DECL_STRING);
        appendTypeSignatureLabel(localVariable, localVariable.getTypeSignature(), flags);
    }

    // post qualification
    if (getFlag(flags, F_POST_QUALIFIED)) {
        fBuffer.append(CONCAT_STRING);
        appendElementLabel(localVariable.getDeclaringMember(), M_PARAMETER_TYPES | M_FULLY_QUALIFIED | T_FULLY_QUALIFIED | (flags & QUALIFIER_FLAGS));
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:RefactoringAvailabilityTester.java   
public static boolean isGeneralizeTypeAvailable(final IJavaElement element) throws JavaModelException {
    if (element != null && element.exists()) {
        String type= null;
        if (element instanceof IMethod)
            type= ((IMethod) element).getReturnType();
        else if (element instanceof IField) {
            final IField field= (IField) element;
            if (JdtFlags.isEnum(field))
                return false;
            type= field.getTypeSignature();
        } else if (element instanceof ILocalVariable)
            return true;
        else if (element instanceof IType) {
            final IType clazz= (IType) element;
            if (JdtFlags.isEnum(clazz))
                return false;
            return true;
        }
        if (type == null || PrimitiveType.toCode(Signature.toString(type)) != null)
            return false;
        return true;
    }
    return false;
}
项目:Eclipse-Postfix-Code-Completion    文件:Checks.java   
public static boolean isAvailable(IJavaElement javaElement) throws JavaModelException {
    if (javaElement == null)
        return false;
    if (! javaElement.exists())
        return false;
    if (javaElement.isReadOnly())
        return false;
    // work around for https://bugs.eclipse.org/bugs/show_bug.cgi?id=48422
    // the Java project is now cheating regarding its children so we shouldn't
    // call isStructureKnown if the project isn't open.
    // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=52474
    if (!(javaElement instanceof IJavaProject) && !(javaElement instanceof ILocalVariable) && !javaElement.isStructureKnown())
        return false;
    if (javaElement instanceof IMember && ((IMember)javaElement).isBinary())
        return false;
    return true;
}
项目:Eclipse-Postfix-Code-Completion    文件:LambdaMethod.java   
public void getHandleMemento(StringBuffer buff, boolean serializeParent) {
    if (serializeParent) {
        ((LambdaExpression) getParent()).getHandleMemento(buff, true, false);
    }
    appendEscapedDelimiter(buff, getHandleMementoDelimiter());
    escapeMementoName(buff, getElementName());
    buff.append(JEM_COUNT);
    buff.append(this.parameterTypes.length);
    for (int i = 0, length = this.parameterTypes.length; i < length; i++) {
        appendEscapedDelimiter(buff, JEM_STRING);
        escapeMementoName(buff, this.parameterTypes[i]);
        appendEscapedDelimiter(buff, JEM_STRING);
        escapeMementoName(buff, this.parameterNameStrings[i]);
    }
    appendEscapedDelimiter(buff, JEM_STRING);
    escapeMementoName(buff, this.returnTypeString);
    appendEscapedDelimiter(buff, JEM_STRING);
    escapeMementoName(buff, this.key);
    ILocalVariable[] arguments = this.elementInfo.arguments;
    for (int i = 0, length = arguments.length; i < length; i++) {
        LocalVariable local = (LocalVariable) arguments[i];
        local.getHandleMemento(buff, false);
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:RefactoringAvailabilityTester.java   
public static boolean isGeneralizeTypeAvailable(final IJavaElement element) throws JavaModelException {
    if (element != null && element.exists()) {
        String type= null;
        if (element instanceof IMethod)
            type= ((IMethod) element).getReturnType();
        else if (element instanceof IField) {
            final IField field= (IField) element;
            if (JdtFlags.isEnum(field))
                return false;
            type= field.getTypeSignature();
        } else if (element instanceof ILocalVariable)
            return true;
        else if (element instanceof IType) {
            final IType clazz= (IType) element;
            if (JdtFlags.isEnum(clazz))
                return false;
            return true;
        }
        if (type == null || PrimitiveType.toCode(Signature.toString(type)) != null)
            return false;
        return true;
    }
    return false;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:Checks.java   
public static boolean isAvailable(IJavaElement javaElement) throws JavaModelException {
    if (javaElement == null)
        return false;
    if (! javaElement.exists())
        return false;
    if (javaElement.isReadOnly())
        return false;
    // work around for https://bugs.eclipse.org/bugs/show_bug.cgi?id=48422
    // the Java project is now cheating regarding its children so we shouldn't
    // call isStructureKnown if the project isn't open.
    // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=52474
    if (!(javaElement instanceof IJavaProject) && !(javaElement instanceof ILocalVariable) && !javaElement.isStructureKnown())
        return false;
    if (javaElement instanceof IMember && ((IMember)javaElement).isBinary())
        return false;
    return true;
}
项目:jive    文件:SelectionTokenizer.java   
/**
 * Tokenizes the supplied {@code IJavaElement} depending on its type.
 * 
 * @param element
 *          the element to tokenize
 * @throws JavaModelException
 *           if there is a failure in the Java model
 */
private void tokenize(final IJavaElement element) throws JavaModelException
{
  switch (element.getElementType())
  {
    case IJavaElement.PACKAGE_FRAGMENT:
      initialize((IPackageFragment) element);
      break;
    case IJavaElement.TYPE:
      initialize((IType) element);
      break;
    case IJavaElement.FIELD:
      initialize((IField) element);
      break;
    case IJavaElement.METHOD:
      initialize((IMethod) element);
      break;
    case IJavaElement.LOCAL_VARIABLE:
      initialize((ILocalVariable) element);
      break;
  }
}
项目:byteman-editor    文件:AbstractBytemanAssistProcessor.java   
/**
 * Creates string to display for the specified method.
 */
protected String createDisplayString(IMethod method) throws JavaModelException {
    StringBuilder sb = new StringBuilder();
    sb.append(method.getElementName()).append("(");
    ILocalVariable[] parameters = method.getParameters();
    if(parameters.length > 0) {
        StringBuilder variables = new StringBuilder();
        for(ILocalVariable variable : parameters) {
            if(variables.length() != 0) {
                variables.append(", ");
            }
            variables.append(
                    Signature.toString(variable.getTypeSignature())).append(" ").append(variable.getElementName());
        }
        sb.append(variables);
    }
    sb.append(")");
    if(method.isConstructor()) {
        sb.append(DESC_CONSTRUCTOR);
    } else {
        sb.append(" : ").append(Signature.toString(method.getReturnType()));
    }
    return sb.toString();
}
项目:eclipse.jdt.ls    文件:HoverInfoProvider.java   
private MarkedString computeSignature(IJavaElement element)  {
    if (element == null) {
        return null;
    }
    String elementLabel = null;
    if (element instanceof ILocalVariable) {
        elementLabel = JavaElementLabels.getElementLabel(element,LOCAL_VARIABLE_FLAGS);
    } else {
        elementLabel = JavaElementLabels.getElementLabel(element,COMMON_SIGNATURE_FLAGS);
    }

    return new MarkedString(LANGUAGE_ID, elementLabel);
}
项目:Migrate-Skeletal-Implementation-to-Interface-Refactoring    文件:Util.java   
public static String getMethodIdentifier(IMethod method) throws JavaModelException {
    StringBuilder sb = new StringBuilder();
    sb.append((method.getElementName()) + "(");
    ILocalVariable[] parameters = method.getParameters();
    for (int i = 0; i < parameters.length; i++) {
        sb.append(edu.cuny.citytech.defaultrefactoring.core.utils.Util
                .getQualifiedNameFromTypeSignature(parameters[i].getTypeSignature(), method.getDeclaringType()));
        if (i != (parameters.length - 1))
            sb.append(",");
    }
    sb.append(")");
    return sb.toString();
}
项目:Migrate-Skeletal-Implementation-to-Interface-Refactoring    文件:MigrateSkeletalImplementationToInterfaceRefactoringProcessor.java   
/**
 * Finds the target (interface) method declaration in the given type for the
 * given source method.
 *
 * @param sourceMethod
 *            The method that will be migrated to the target interface.
 * @param destinationInterface
 *            The interface for which sourceMethod will be migrated.
 * @return The target method that will be manipulated or null if not found.
 * @throws JavaModelException
 */
private static IMethod findTargetMethod(IMethod sourceMethod, IType destinationInterface)
        throws JavaModelException {
    if (destinationInterface == null)
        return null; // not found.

    Assert.isNotNull(sourceMethod);
    Assert.isLegal(sourceMethod.exists(), "Source method does not exist.");
    Assert.isLegal(destinationInterface.exists(), "Target interface does not exist.");
    Assert.isLegal(destinationInterface.isInterface(), "Target interface must be an interface.");

    IMethod ret = null;

    for (IMethod method : destinationInterface.getMethods())
        if (method.exists() && method.getElementName().equals(sourceMethod.getElementName())) {
            ILocalVariable[] parameters = method.getParameters();
            ILocalVariable[] sourceParameters = sourceMethod.getParameters();

            if (parameterListMatches(parameters, method, sourceParameters, sourceMethod))
                if (ret != null)
                    throw new IllegalStateException(
                            "Found multiple matches of method: " + sourceMethod.getElementName() + " in interface: "
                                    + destinationInterface.getElementName());
                else
                    ret = method;
        }
    return ret;
}
项目:junit-tools    文件:GeneratorWizardMain.java   
/**
    * Updates the method from the page.
    * 
    * @param method
    * @param tmlMethod
    * @throws JavaModelException
    */
   public void updateModelMethod(IMethod method, Method tmlMethod)
    throws JavaModelException {
Result result;
Param param;
String returnType;

tmlMethod.setName(method.getElementName());
tmlMethod.setModifier(JDTUtils.getMethodModifier(method));
tmlMethod.setStatic(JDTUtils.isStatic(method));
tmlMethod.setSignature(method.getSignature());

// parameters
ILocalVariable[] parameters = method.getParameters();

for (ILocalVariable parameter : parameters) {
    param = getObjectFactory().createParam();
    param.setName(parameter.getElementName());
    param.setType(Signature.getSignatureSimpleName(parameter
        .getTypeSignature()));

    tmlMethod.getParam().add(param);
}

// return type
returnType = method.getReturnType();
if (returnType != null && !returnType.equals("V")) {
    result = getObjectFactory().createResult();
    result.setName("result");
    result.setType(Signature.getSignatureSimpleName(returnType));
    tmlMethod.setResult(result);
}
   }
项目:che    文件:RenameTypeTest.java   
private void checkMappedSimilarElementsExist(Refactoring ref) {
  RenameTypeProcessor rtp = (RenameTypeProcessor) ((RenameRefactoring) ref).getProcessor();
  IJavaElementMapper mapper = (IJavaElementMapper) rtp.getAdapter(IJavaElementMapper.class);
  IJavaElement[] similarElements = rtp.getSimilarElements();
  if (similarElements == null) return;
  for (int i = 0; i < similarElements.length; i++) {
    IJavaElement element = similarElements[i];
    if (!(element instanceof ILocalVariable)) {
      IJavaElement newElement = mapper.getRefactoredJavaElement(element);
      TestCase.assertTrue(newElement.exists());
      Assert.assertFalse(element.exists());
    }
  }
}
项目:che    文件:RenameLocalVariableProcessor.java   
/**
 * Creates a new rename local variable processor.
 *
 * @param localVariable the local variable, or <code>null</code> if invoked by scripting
 */
public RenameLocalVariableProcessor(ILocalVariable localVariable) {
  fLocalVariable = localVariable;
  fUpdateReferences = true;
  if (localVariable != null)
    fCu = (ICompilationUnit) localVariable.getAncestor(IJavaElement.COMPILATION_UNIT);
  fNewName = ""; // $NON-NLS-1$
  fIsComposite = false;
}
项目:che    文件:RenameLocalVariableProcessor.java   
/**
 * Creates a new rename local variable processor.
 *
 * <p>This constructor is only used by <code>RenameTypeProcessor</code>.
 *
 * @param localVariable the local variable
 * @param manager the change manager
 * @param node the compilation unit node
 * @param categorySet the group category set
 */
RenameLocalVariableProcessor(
    ILocalVariable localVariable,
    TextChangeManager manager,
    CompilationUnit node,
    GroupCategorySet categorySet) {
  this(localVariable);
  fChangeManager = manager;
  fCategorySet = categorySet;
  fCompilationUnitNode = node;
  fIsComposite = true;
}
项目:che    文件:RenameTypeProcessor.java   
/**
 * @param matchOffset offset of the match
 * @param parentElement parent element of the match
 * @return true iff the given search match offset (must be a match of a type reference) lies
 *     before the element name of its enclosing java element, false if not. In other words: If
 *     this method returns true, the match is the declared type (or return type) of the enclosing
 *     element.
 * @throws JavaModelException should not happen
 */
private boolean isInDeclaredType(int matchOffset, IJavaElement parentElement)
    throws JavaModelException {
  if (parentElement != null) {
    int enclosingNameOffset = 0;
    if (parentElement instanceof IMethod || parentElement instanceof IField)
      enclosingNameOffset = ((IMember) parentElement).getNameRange().getOffset();
    else if (parentElement instanceof ILocalVariable)
      enclosingNameOffset = ((ILocalVariable) parentElement).getNameRange().getOffset();

    return (matchOffset < enclosingNameOffset);
  }
  return false;
}
项目:che    文件:RenameTypeProcessor.java   
private RenameLocalVariableProcessor createLocalRenameProcessor(
    final ILocalVariable local, final String newName, final CompilationUnit compilationUnit) {
  final RenameLocalVariableProcessor processor =
      new RenameLocalVariableProcessor(
          local, fChangeManager, compilationUnit, CATEGORY_LOCAL_RENAME);
  processor.setNewElementName(newName);
  processor.setUpdateReferences(getUpdateReferences());
  return processor;
}
项目:che    文件:RefactoringAvailabilityTester.java   
public static boolean isInlineTempAvailable(final JavaTextSelection selection)
    throws JavaModelException {
  final IJavaElement[] elements = selection.resolveElementAtOffset();
  if (elements.length != 1) return false;
  return (elements[0] instanceof ILocalVariable)
      && isInlineTempAvailable((ILocalVariable) elements[0]);
}
项目:che    文件:RefactoringAvailabilityTester.java   
public static boolean isPromoteTempAvailable(final JavaTextSelection selection)
    throws JavaModelException {
  final IJavaElement[] elements = selection.resolveElementAtOffset();
  if (elements.length != 1) return false;
  return (elements[0] instanceof ILocalVariable)
      && isPromoteTempAvailable((ILocalVariable) elements[0]);
}
项目:che    文件:RefactoringAvailabilityTester.java   
public static boolean isRenameElementAvailable(IJavaElement element) throws CoreException {
  switch (element.getElementType()) {
    case IJavaElement.JAVA_PROJECT:
      return isRenameAvailable((IJavaProject) element);
    case IJavaElement.PACKAGE_FRAGMENT_ROOT:
      return isRenameAvailable((IPackageFragmentRoot) element);
    case IJavaElement.PACKAGE_FRAGMENT:
      return isRenameAvailable((IPackageFragment) element);
    case IJavaElement.COMPILATION_UNIT:
      return isRenameAvailable((ICompilationUnit) element);
    case IJavaElement.TYPE:
      return isRenameAvailable((IType) element);
    case IJavaElement.METHOD:
      final IMethod method = (IMethod) element;
      if (method.isConstructor()) return isRenameAvailable(method.getDeclaringType());
      else return isRenameAvailable(method);
    case IJavaElement.FIELD:
      final IField field = (IField) element;
      if (Flags.isEnum(field.getFlags())) return isRenameEnumConstAvailable(field);
      else return isRenameFieldAvailable(field);
    case IJavaElement.TYPE_PARAMETER:
      return isRenameAvailable((ITypeParameter) element);
    case IJavaElement.LOCAL_VARIABLE:
      return isRenameAvailable((ILocalVariable) element);
  }
  return false;
}
项目:che    文件:Checks.java   
public static boolean isAvailable(IJavaElement javaElement) throws JavaModelException {
  if (javaElement == null) return false;
  if (!javaElement.exists()) return false;
  if (javaElement.isReadOnly()) return false;
  // work around for https://bugs.eclipse.org/bugs/show_bug.cgi?id=48422
  // the Java project is now cheating regarding its children so we shouldn't
  // call isStructureKnown if the project isn't open.
  // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=52474
  if (!(javaElement instanceof IJavaProject)
      && !(javaElement instanceof ILocalVariable)
      && !javaElement.isStructureKnown()) return false;
  if (javaElement instanceof IMember && ((IMember) javaElement).isBinary()) return false;
  return true;
}
项目:che    文件:JavaMatchFilter.java   
@Override
public boolean isApplicable(JavaSearchQuery query) {
  QuerySpecification spec = query.getSpecification();
  if (spec instanceof ElementQuerySpecification) {
    ElementQuerySpecification elementSpec = (ElementQuerySpecification) spec;
    IJavaElement element = elementSpec.getElement();
    return element instanceof IField || element instanceof ILocalVariable;
  } else if (spec instanceof PatternQuerySpecification) {
    PatternQuerySpecification patternSpec = (PatternQuerySpecification) spec;
    return patternSpec.getSearchFor() == IJavaSearchConstants.FIELD;
  }
  return false;
}
项目:che    文件:JavaElementLabelComposer.java   
/**
 * Appends the styled label for a local variable.
 *
 * @param localVariable the element to render
 * @param flags the rendering flags. Flags with names starting with 'F_' are considered.
 */
public void appendLocalVariableLabel(ILocalVariable localVariable, long flags) {
  if (getFlag(flags, JavaElementLabels.F_PRE_TYPE_SIGNATURE)) {
    appendTypeSignatureLabel(localVariable, localVariable.getTypeSignature(), flags);
    fBuffer.append(' ');
  }

  if (getFlag(flags, JavaElementLabels.F_FULLY_QUALIFIED)) {
    appendElementLabel(
        localVariable.getDeclaringMember(),
        JavaElementLabels.M_PARAMETER_TYPES
            | JavaElementLabels.M_FULLY_QUALIFIED
            | JavaElementLabels.T_FULLY_QUALIFIED
            | (flags & QUALIFIER_FLAGS));
    fBuffer.append('.');
  }

  fBuffer.append(getElementName(localVariable));

  if (getFlag(flags, JavaElementLabels.F_APP_TYPE_SIGNATURE)) {
    int offset = fBuffer.length();
    fBuffer.append(JavaElementLabels.DECL_STRING);
    appendTypeSignatureLabel(localVariable, localVariable.getTypeSignature(), flags);
    //          if (getFlag(flags, JavaElementLabels.COLORIZE)) {
    //              fBuffer.setStyle(offset, fBuffer.length() - offset, DECORATIONS_STYLE);
    //          }
  }

  // post qualification
  if (getFlag(flags, JavaElementLabels.F_POST_QUALIFIED)) {
    fBuffer.append(JavaElementLabels.CONCAT_STRING);
    appendElementLabel(
        localVariable.getDeclaringMember(),
        JavaElementLabels.M_PARAMETER_TYPES
            | JavaElementLabels.M_FULLY_QUALIFIED
            | JavaElementLabels.T_FULLY_QUALIFIED
            | (flags & QUALIFIER_FLAGS));
  }
}
项目:Eclipse-Postfix-Code-Completion    文件:RenameLocalVariableProcessor.java   
/**
 * Creates a new rename local variable processor.
 * @param localVariable the local variable, or <code>null</code> if invoked by scripting
 */
public RenameLocalVariableProcessor(ILocalVariable localVariable) {
    fLocalVariable= localVariable;
    fUpdateReferences= true;
    if (localVariable != null)
        fCu= (ICompilationUnit) localVariable.getAncestor(IJavaElement.COMPILATION_UNIT);
    fNewName= ""; //$NON-NLS-1$
    fIsComposite= false;
}
项目:Eclipse-Postfix-Code-Completion    文件:RenameTypeProcessor.java   
/**
 * @param matchOffset offset of the match
 * @param parentElement parent element of the match
 * @return true iff the given search match offset (must be a match of a type
 * reference) lies before the element name of its enclosing java element,
 * false if not. In other words: If this method returns true, the match is
 * the declared type (or return type) of the enclosing element.
 * @throws JavaModelException should not happen
 *
 */
private boolean isInDeclaredType(int matchOffset, IJavaElement parentElement) throws JavaModelException {
    if (parentElement != null) {
        int enclosingNameOffset= 0;
        if (parentElement instanceof IMethod || parentElement instanceof IField)
            enclosingNameOffset= ((IMember) parentElement).getNameRange().getOffset();
        else if (parentElement instanceof ILocalVariable)
            enclosingNameOffset= ((ILocalVariable) parentElement).getNameRange().getOffset();

        return (matchOffset < enclosingNameOffset);
    }
    return false;
}
项目:Eclipse-Postfix-Code-Completion    文件:RefactoringAvailabilityTester.java   
public static boolean isRenameElementAvailable(IJavaElement element) throws CoreException {
    switch (element.getElementType()) {
        case IJavaElement.JAVA_PROJECT:
            return isRenameAvailable((IJavaProject) element);
        case IJavaElement.PACKAGE_FRAGMENT_ROOT:
            return isRenameAvailable((IPackageFragmentRoot) element);
        case IJavaElement.PACKAGE_FRAGMENT:
            return isRenameAvailable((IPackageFragment) element);
        case IJavaElement.COMPILATION_UNIT:
            return isRenameAvailable((ICompilationUnit) element);
        case IJavaElement.TYPE:
            return isRenameAvailable((IType) element);
        case IJavaElement.METHOD:
            final IMethod method= (IMethod) element;
            if (method.isConstructor())
                return isRenameAvailable(method.getDeclaringType());
            else
                return isRenameAvailable(method);
        case IJavaElement.FIELD:
            final IField field= (IField) element;
            if (Flags.isEnum(field.getFlags()))
                return isRenameEnumConstAvailable(field);
            else
                return isRenameFieldAvailable(field);
        case IJavaElement.TYPE_PARAMETER:
            return isRenameAvailable((ITypeParameter) element);
        case IJavaElement.LOCAL_VARIABLE:
            return isRenameAvailable((ILocalVariable) element);
    }
    return false;
}
项目:Eclipse-Postfix-Code-Completion    文件:RefactoringExecutionStarter.java   
private static RenameSupport createRenameSupport(IJavaElement element, String newName, int flags) throws CoreException {
    switch (element.getElementType()) {
        case IJavaElement.JAVA_PROJECT:
            return RenameSupport.create((IJavaProject) element, newName, flags);
        case IJavaElement.PACKAGE_FRAGMENT_ROOT:
            return RenameSupport.create((IPackageFragmentRoot) element, newName);
        case IJavaElement.PACKAGE_FRAGMENT:
            return RenameSupport.create((IPackageFragment) element, newName, flags);
        case IJavaElement.COMPILATION_UNIT:
            return RenameSupport.create((ICompilationUnit) element, newName, flags);
        case IJavaElement.TYPE:
            return RenameSupport.create((IType) element, newName, flags);
        case IJavaElement.METHOD:
            final IMethod method= (IMethod) element;
            if (method.isConstructor())
                return createRenameSupport(method.getDeclaringType(), newName, flags);
            else
                return RenameSupport.create((IMethod) element, newName, flags);
        case IJavaElement.FIELD:
            return RenameSupport.create((IField) element, newName, flags);
        case IJavaElement.TYPE_PARAMETER:
            return RenameSupport.create((ITypeParameter) element, newName, flags);
        case IJavaElement.LOCAL_VARIABLE:
            return RenameSupport.create((ILocalVariable) element, newName, flags);
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion    文件:RenameTypeWizardSimilarElementsPage.java   
public Object getParent(Object element) {
    if (element instanceof IMember || element instanceof ILocalVariable) {
        return ((IJavaElement) element).getParent();
    }
    if (element instanceof ICompilationUnit)
        return null;
    Assert.isTrue(false, "Should not get here"); //$NON-NLS-1$
    return null;
}
项目:Eclipse-Postfix-Code-Completion    文件:RenameTypeWizardSimilarElementsPage.java   
@Override
public int category(Object element) {

    /*
     * We'd like to present the elements in the same order as they
     * appear in the source. This can be achieved by assigning a
     * distinct category to every element; the category being derived
     * from the source position of the element.
     */

    ISourceRange sourceRange= null;
    if (element instanceof IMember) {
        IMember member= (IMember) element;
        try {
            sourceRange= member.getNameRange();
        } catch (JavaModelException e) {
            // fall through
        }
    }
    if (element instanceof ILocalVariable) {
        ILocalVariable var= (ILocalVariable) element;
        sourceRange= var.getNameRange();
    }

    if (sourceRange != null)
        return 100 + sourceRange.getOffset(); // +100: safe distance from all other categories.

    return super.category(element);
}
项目:Eclipse-Postfix-Code-Completion    文件:RenameTypeWizardSimilarElementsPage.java   
private ISourceRange getNameRange(IJavaElement element) throws JavaModelException {
    if (element instanceof IMember)
        return ((IMember) element).getNameRange();
    else if (element instanceof ILocalVariable)
        return ((ILocalVariable) element).getNameRange();
    else
        return null;
}
项目:Eclipse-Postfix-Code-Completion    文件:FindAction.java   
IType getType(IJavaElement element) {
    if (element == null)
        return null;

    IType type= null;
    if (element.getElementType() == IJavaElement.TYPE)
        type= (IType)element;
    else if (element instanceof IMember)
        type= ((IMember)element).getDeclaringType();
    else if (element instanceof ILocalVariable) {
        type= (IType)element.getAncestor(IJavaElement.TYPE);
    }
    return type;
}
项目:Eclipse-Postfix-Code-Completion    文件:AbstractInfoView.java   
/**
 * Computes the contents description that will be displayed for the current element.
 *
 * @param part the part that triggered the current element update, or <code>null</code>
 * @param selection the new selection, or <code>null</code>
 * @param inputElement the new java element that will be displayed
 * @param localASTMonitor a progress monitor
 * @return the contents description for the provided <code>inputElement</code>
 * @since 3.4
 */
protected String computeDescription(IWorkbenchPart part, ISelection selection, IJavaElement inputElement, IProgressMonitor localASTMonitor) {
    long flags;
    if (inputElement instanceof ILocalVariable)
        flags= LOCAL_VARIABLE_TITLE_FLAGS;
    else if (inputElement instanceof ITypeParameter)
        flags= TYPE_PARAMETER_TITLE_FLAGS;
    else
        flags= TITLE_FLAGS;

    return JavaElementLabels.getElementLabel(inputElement, flags);
}