Java Code Examples for org.eclipse.jdt.core.Flags#isStatic()

The following examples show how to use org.eclipse.jdt.core.Flags#isStatic() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DialogFactoryHelperImpl.java    From jenerate with Eclipse Public License 1.0 6 votes vote down vote up
private IField[] getNonStaticNonCacheFields(IType objectClass, PreferencesManager preferencesManager)
        throws JavaModelException {
    Set<String> cacheFields = new HashSet<>();
    cacheFields.add(preferencesManager.getCurrentPreferenceValue(JeneratePreferences.HASHCODE_CACHING_FIELD));
    cacheFields.add(preferencesManager.getCurrentPreferenceValue(JeneratePreferences.TOSTRING_CACHING_FIELD));

    IField[] fields;
    fields = objectClass.getFields();

    List<IField> result = new ArrayList<>();

    for (int i = 0, size = fields.length; i < size; i++) {
        if (!Flags.isStatic(fields[i].getFlags()) && !cacheFields.contains(fields[i].getElementName())) {
            result.add(fields[i]);
        }
    }

    return result.toArray(new IField[result.size()]);
}
 
Example 2
Source File: NewTypeWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Sets the modifiers.
 *
 * @param modifiers <code>F_PUBLIC</code>, <code>F_PRIVATE</code>,
 * <code>F_PROTECTED</code>, <code>F_ABSTRACT</code>, <code>F_FINAL</code>
 * or <code>F_STATIC</code> or a valid combination.
 * @param canBeModified if <code>true</code> the modifier fields are
 * editable; otherwise they are read-only
 * @see Flags
 */
public void setModifiers(int modifiers, boolean canBeModified) {
	if (Flags.isPublic(modifiers)) {
		fAccMdfButtons.setSelection(PUBLIC_INDEX, true);
	} else if (Flags.isPrivate(modifiers)) {
		fAccMdfButtons.setSelection(PRIVATE_INDEX, true);
	} else if (Flags.isProtected(modifiers)) {
		fAccMdfButtons.setSelection(PROTECTED_INDEX, true);
	} else {
		fAccMdfButtons.setSelection(DEFAULT_INDEX, true);
	}
	if (Flags.isAbstract(modifiers)) {
		fOtherMdfButtons.setSelection(ABSTRACT_INDEX, true);
	}
	if (Flags.isFinal(modifiers)) {
		fOtherMdfButtons.setSelection(FINAL_INDEX, true);
	}
	if (Flags.isStatic(modifiers)) {
		fOtherMdfButtons.setSelection(STATIC_INDEX, true);
	}

	fAccMdfButtons.setEnabled(canBeModified);
	fOtherMdfButtons.setEnabled(canBeModified);
}
 
Example 3
Source File: Initializer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @private Debugging purposes
 */
protected void toStringInfo(int tab, StringBuffer buffer, Object info, boolean showResolvedInfo) {
	buffer.append(tabString(tab));
	if (info == null) {
		buffer.append("<initializer #"); //$NON-NLS-1$
		buffer.append(this.occurrenceCount);
		buffer.append("> (not open)"); //$NON-NLS-1$
	} else if (info == NO_INFO) {
		buffer.append("<initializer #"); //$NON-NLS-1$
		buffer.append(this.occurrenceCount);
		buffer.append(">"); //$NON-NLS-1$
	} else {
		try {
			buffer.append("<"); //$NON-NLS-1$
			if (Flags.isStatic(getFlags())) {
				buffer.append("static "); //$NON-NLS-1$
			}
		buffer.append("initializer #"); //$NON-NLS-1$
		buffer.append(this.occurrenceCount);
		buffer.append(">"); //$NON-NLS-1$
		} catch (JavaModelException e) {
			buffer.append("<JavaModelException in toString of " + getElementName()); //$NON-NLS-1$
		}
	}
}
 
Example 4
Source File: MethodOverrideTester.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Finds an overriding method in a type.
 * @param overridingType The type to find methods in
 * @param overridden The overridden method
 * @return The overriding method or <code>null</code> if no method is overriding.
 * @throws JavaModelException if a problem occurs
 */
public IMethod findOverridingMethodInType(IType overridingType, IMethod overridden) throws JavaModelException {
	int flags= overridden.getFlags();
	if (Flags.isPrivate(flags) || Flags.isStatic(flags) || overridden.isConstructor())
		return null;
	IMethod[] overridingMethods= overridingType.getMethods();
	for (int i= 0; i < overridingMethods.length; i++) {
		IMethod overriding= overridingMethods[i];
		flags= overriding.getFlags();
		if (Flags.isPrivate(flags) || Flags.isStatic(flags) || overriding.isConstructor())
			continue;
		if (isSubsignature(overriding, overridden)) {
			return overriding;
		}
	}
	return null;
}
 
Example 5
Source File: MethodOverrideTester.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Finds an overridden method in a type. With generics it is possible that 2 methods in the same type are overridden at the same time.
 * In that case the first overridden method found is returned.
 * @param overriddenType The type to find methods in
 * @param overriding The overriding method
 * @return The first overridden method or <code>null</code> if no method is overridden
 * @throws JavaModelException if a problem occurs
 */
public IMethod findOverriddenMethodInType(IType overriddenType, IMethod overriding) throws JavaModelException {
	int flags= overriding.getFlags();
	if (Flags.isPrivate(flags) || Flags.isStatic(flags) || overriding.isConstructor())
		return null;
	IMethod[] overriddenMethods= overriddenType.getMethods();
	for (int i= 0; i < overriddenMethods.length; i++) {
		IMethod overridden= overriddenMethods[i];
		flags= overridden.getFlags();
		if (Flags.isPrivate(flags) || Flags.isStatic(flags) || overridden.isConstructor())
			continue;
		if (isSubsignature(overriding, overridden)) {
			return overridden;
		}
	}
	return null;
}
 
Example 6
Source File: ExtractFieldRefactoring.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private Expression wrapAsFieldAccessExpression(SimpleName fieldName) {
	AST ast = fCURewrite.getAST();
	ASTRewrite rewrite = fCURewrite.getASTRewrite();
	List<String> variableNames = Arrays.asList(getExcludedVariableNames());
	if (variableNames.contains(fFieldName)) {
		int modifiers = getModifiers();
		if (Flags.isStatic(modifiers)) {
			try {
				String enclosingTypeName = getEnclosingTypeName();
				SimpleName typeName = ast.newSimpleName(enclosingTypeName);
				if (fLinkedProposalModel != null) {
					fLinkedProposalModel.getPositionGroup(KEY_NAME, true).addPosition(rewrite.track(typeName), false);
				}
				QualifiedName qualifiedName = ast.newQualifiedName(typeName, fieldName);
				return qualifiedName;
			} catch (JavaModelException e) {
				return wrapAsFieldAccess(fieldName, ast);
			}
		} else {
			return wrapAsFieldAccess(fieldName, ast);
		}
	}

	return fieldName;
}
 
Example 7
Source File: NLSSearchQuery.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private boolean isNLSField(IField field) throws JavaModelException {
	int flags= field.getFlags();
	if (!Flags.isPublic(flags))
		return false;

	if (!Flags.isStatic(flags))
		return false;

	String fieldName= field.getElementName();
	if (NLSRefactoring.BUNDLE_NAME_FIELD.equals(fieldName))
		return false;

	if ("RESOURCE_BUNDLE".equals(fieldName)) //$NON-NLS-1$
		return false;

	return true;
}
 
Example 8
Source File: MemberFilter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
	try {
		if (element instanceof IMember) {
			IMember member= (IMember) element;
			int memberType= member.getElementType();

			if (hasFilter(FILTER_FIELDS) && memberType == IJavaElement.FIELD) {
				return false;
			}

			if (hasFilter(FILTER_LOCALTYPES) && memberType == IJavaElement.TYPE && isLocalType((IType) member)) {
				return false;
			}

			if (member.getElementName().startsWith("<")) { // filter out <clinit> //$NON-NLS-1$
				return false;
			}
			int flags= member.getFlags();
			if (hasFilter(FILTER_STATIC) && (Flags.isStatic(flags) || isFieldInInterfaceOrAnnotation(member)) && memberType != IJavaElement.TYPE) {
				return false;
			}
			if (hasFilter(FILTER_NONPUBLIC) && !Flags.isPublic(flags) && !isMemberInInterfaceOrAnnotation(member) && !isTopLevelType(member) && !isEnumConstant(member)) {
				return false;
			}
		}
	} catch (JavaModelException e) {
		// ignore
	}
	return true;
}
 
Example 9
Source File: MethodProposalInfo.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Tests if a method equals to the given signature. Parameter types are only
 * compared by the simple name, no resolving for the fully qualified type
 * name is done. Constructors are only compared by parameters, not the name.
 *
 * @param name Name of the method
 * @param paramTypes The type signatures of the parameters e.g.
 *        <code>{"QString;","I"}</code>
 * @param isConstructor Specifies if the method is a constructor
 * @param method the method to be compared with this info's method
 * @param typeVariables a map from type variables to types
 * @param type the given type that declares the method
 * @return Returns <code>true</code> if the method has the given name and
 *         parameter types and constructor state.
 * @throws JavaModelException if the method does not exist or if an exception occurs while accessing its corresponding resource
 */
private boolean isSameMethodSignature(String name, String[] paramTypes, boolean isConstructor, IMethod method, Map<String, char[]> typeVariables, IType type) throws JavaModelException {
	if (isConstructor || name.equals(method.getElementName())) {
		if (isConstructor == method.isConstructor()) {
			String[] otherParams= method.getParameterTypes(); // types may be type variables
			boolean isBinaryConstructorForNonStaticMemberClass=
					method.isBinary()
					&& type.isMember()
					&& !Flags.isStatic(type.getFlags());
			int syntheticParameterCorrection= isBinaryConstructorForNonStaticMemberClass && paramTypes.length == otherParams.length - 1 ? 1 : 0;
			if (paramTypes.length == otherParams.length - syntheticParameterCorrection) {
				fFallbackMatch= method;
				String signature= method.getSignature();
				String[] otherParamsFromSignature= Signature.getParameterTypes(signature); // types are resolved / upper-bounded
				// no need to check method type variables since these are
				// not yet bound when proposing a method
				for (int i= 0; i < paramTypes.length; i++) {
					String ourParamName= computeSimpleTypeName(paramTypes[i], typeVariables);
					String otherParamName1= computeSimpleTypeName(otherParams[i + syntheticParameterCorrection], typeVariables);
					String otherParamName2= computeSimpleTypeName(otherParamsFromSignature[i + syntheticParameterCorrection], typeVariables);

					if (!ourParamName.equals(otherParamName1) && !ourParamName.equals(otherParamName2)) {
						return false;
					}
				}
				return true;
			}
		}
	}
	return false;
}
 
Example 10
Source File: SetterAttributeProposalComputer.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Determines whether the argument is a setter method based on heuristics
 * similar to GWT's OwnerFieldClass.
 */
private boolean isSetterMethod(IMethod method) throws JavaModelException {
  // All setter methods should be public void setSomething(...)
  // (com.google.gwt.uibinder.rebind.model.OwnerFieldClass.isSetterMethod)
  String methodName = method.getElementName();

  return methodName.startsWith(SETTER_PREFIX)
      && methodName.length() > SETTER_PREFIX_LENGTH
      && Character.isUpperCase(methodName.charAt(SETTER_PREFIX_LENGTH))
      && Flags.isPublic(method.getFlags())
      && !Flags.isStatic(method.getFlags())
      && Signature.SIG_VOID.equals(method.getReturnType());
}
 
Example 11
Source File: SearchUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static boolean isPrimitiveConstantOrString(IJavaElement element) {
	if (element != null && element.getElementType() == IJavaElement.FIELD) {
		IField field= (IField)element;
		int flags;
		try {
			flags= field.getFlags();
		} catch (JavaModelException ex) {
			return false;
		}
		return Flags.isStatic(flags) && Flags.isFinal(flags) && isPrimitiveOrString(field);
	}
	return false;
}
 
Example 12
Source File: StubUtility.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static String[] getFieldNameSuggestions(IJavaProject project, String baseName, int dimensions, int modifiers, String[] excluded) {
	if (Flags.isFinal(modifiers) && Flags.isStatic(modifiers)) {
		return getVariableNameSuggestions(NamingConventions.VK_STATIC_FINAL_FIELD, project, baseName, dimensions, new ExcludedCollection(excluded), true);
	} else if (Flags.isStatic(modifiers)) {
		return getVariableNameSuggestions(NamingConventions.VK_STATIC_FIELD, project, baseName, dimensions, new ExcludedCollection(excluded), true);
	}
	return getVariableNameSuggestions(NamingConventions.VK_INSTANCE_FIELD, project, baseName, dimensions, new ExcludedCollection(excluded), true);
}
 
Example 13
Source File: SelfEncapsulateFieldRefactoring.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private static void checkName(RefactoringStatus status, String name, List<IMethodBinding> usedNames, IType type, boolean reUseExistingField, IField field) {
	if ("".equals(name)) { //$NON-NLS-1$
		status.addFatalError(RefactoringCoreMessages.Checks_Choose_name);
		return;
	}
	boolean isStatic = false;
	try {
		isStatic = Flags.isStatic(field.getFlags());
	} catch (JavaModelException e) {
		JavaLanguageServerPlugin.log(e);
	}
	status.merge(Checks.checkMethodName(name, field));
	for (Iterator<IMethodBinding> iter = usedNames.iterator(); iter.hasNext();) {
		IMethodBinding method = iter.next();
		String selector = method.getName();
		if (selector.equals(name)) {
			if (!reUseExistingField) {
				status.addFatalError(Messages.format(RefactoringCoreMessages.SelfEncapsulateField_method_exists,
						new String[] { BindingLabelProviderCore.getBindingLabel(method, JavaElementLabels.ALL_FULLY_QUALIFIED), BasicElementLabels.getJavaElementName(type.getElementName()) }));
			} else {
				boolean methodIsStatic = Modifier.isStatic(method.getModifiers());
				if (methodIsStatic && !isStatic) {
					status.addWarning(Messages.format(RefactoringCoreMessages.SelfEncapsulateFieldRefactoring_static_method_but_nonstatic_field,
							new String[] { BasicElementLabels.getJavaElementName(method.getName()), BasicElementLabels.getJavaElementName(field.getElementName()) }));
				}
				if (!methodIsStatic && isStatic) {
					status.addFatalError(Messages.format(RefactoringCoreMessages.SelfEncapsulateFieldRefactoring_nonstatic_method_but_static_field, new String[] { BasicElementLabels.getJavaElementName(method.getName()), BasicElementLabels.getJavaElementName(field.getElementName()) }));
				}
				return;
			}

		}
	}
	if (reUseExistingField) {
		status.addFatalError(Messages.format(
			RefactoringCoreMessages.SelfEncapsulateFieldRefactoring_methoddoesnotexist_status_fatalError,
			new String[] { BasicElementLabels.getJavaElementName(name), BasicElementLabels.getJavaElementName(type.getElementName())}));
	}
}
 
Example 14
Source File: RenamePackageProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private void updateImport(ICompilationUnit cu, IImportDeclaration importDeclaration, String updatedImport) throws JavaModelException {
	ImportChange importChange= fImportsManager.getImportChange(cu);
	if (Flags.isStatic(importDeclaration.getFlags())) {
		importChange.removeStaticImport(importDeclaration.getElementName());
		importChange.addStaticImport(Signature.getQualifier(updatedImport), Signature.getSimpleName(updatedImport));
	} else {
		importChange.removeImport(importDeclaration.getElementName());
		importChange.addImport(updatedImport);
	}
}
 
Example 15
Source File: CompletionProposalLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Returns a version of <code>descriptor</code> decorated according to
 * the passed <code>modifier</code> flags.
 *
 * @param descriptor the image descriptor to decorate
 * @param proposal the proposal
 * @return an image descriptor for a method proposal
 * @see Flags
 */
private ImageDescriptor decorateImageDescriptor(ImageDescriptor descriptor, CompletionProposal proposal) {
	int adornments= 0;
	int flags= proposal.getFlags();
	int kind= proposal.getKind();

	boolean deprecated= Flags.isDeprecated(flags);
	if (!deprecated) {
		CompletionProposal[] requiredProposals= proposal.getRequiredProposals();
		if (requiredProposals != null) {
			for (int i= 0; i < requiredProposals.length; i++) {
				CompletionProposal requiredProposal= requiredProposals[i];
				if (requiredProposal.getKind() == CompletionProposal.TYPE_REF) {
					deprecated |= Flags.isDeprecated(requiredProposal.getFlags());
				}
			}
		}
	}
	if (deprecated)
		adornments |= JavaElementImageDescriptor.DEPRECATED;

	if (kind == CompletionProposal.FIELD_REF || kind == CompletionProposal.METHOD_DECLARATION || kind == CompletionProposal.METHOD_NAME_REFERENCE
			|| kind == CompletionProposal.METHOD_REF || kind == CompletionProposal.CONSTRUCTOR_INVOCATION)
		if (Flags.isStatic(flags))
			adornments |= JavaElementImageDescriptor.STATIC;

	if (kind == CompletionProposal.METHOD_DECLARATION || kind == CompletionProposal.METHOD_NAME_REFERENCE || kind == CompletionProposal.METHOD_REF
			|| kind == CompletionProposal.CONSTRUCTOR_INVOCATION)
		if (Flags.isSynchronized(flags))
			adornments |= JavaElementImageDescriptor.SYNCHRONIZED;
	if (kind == CompletionProposal.METHOD_DECLARATION || kind == CompletionProposal.METHOD_NAME_REFERENCE || kind == CompletionProposal.METHOD_REF)
		if (Flags.isDefaultMethod(flags))
			adornments|= JavaElementImageDescriptor.DEFAULT_METHOD;
	if (kind == CompletionProposal.ANNOTATION_ATTRIBUTE_REF)
		if (Flags.isAnnnotationDefault(flags))
			adornments|= JavaElementImageDescriptor.ANNOTATION_DEFAULT;

	if (kind == CompletionProposal.TYPE_REF && Flags.isAbstract(flags) && !Flags.isInterface(flags))
		adornments |= JavaElementImageDescriptor.ABSTRACT;

	if (kind == CompletionProposal.FIELD_REF) {
		if (Flags.isFinal(flags))
			adornments |= JavaElementImageDescriptor.FINAL;
		if (Flags.isTransient(flags))
			adornments |= JavaElementImageDescriptor.TRANSIENT;
		if (Flags.isVolatile(flags))
			adornments |= JavaElementImageDescriptor.VOLATILE;
	}

	return new JavaElementImageDescriptor(descriptor, adornments, JavaElementImageProvider.SMALL_SIZE);
}
 
Example 16
Source File: RefactoringAvailabilityTester.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
public static boolean isDelegateCreationAvailable(final IField field) throws JavaModelException {
	return field.exists() && (Flags.isStatic(field.getFlags()) && Flags.isFinal(field.getFlags()) /*
																									* &&
																									* hasInitializer(field)
																									*/);
}
 
Example 17
Source File: CompletionProposalRequestor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
private CompletionItemKind mapKind(final CompletionProposal proposal) {
	//When a new CompletionItemKind is added, don't forget to update SUPPORTED_KINDS
	int kind = proposal.getKind();
	int flags = proposal.getFlags();
	switch (kind) {
	case CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION:
	case CompletionProposal.CONSTRUCTOR_INVOCATION:
		return CompletionItemKind.Constructor;
	case CompletionProposal.ANONYMOUS_CLASS_DECLARATION:
	case CompletionProposal.TYPE_REF:
		if (Flags.isInterface(flags)) {
			return CompletionItemKind.Interface;
		} else if (Flags.isEnum(flags)) {
			return CompletionItemKind.Enum;
		}
		return CompletionItemKind.Class;
	case CompletionProposal.FIELD_IMPORT:
	case CompletionProposal.METHOD_IMPORT:
	case CompletionProposal.METHOD_NAME_REFERENCE:
	case CompletionProposal.PACKAGE_REF:
	case CompletionProposal.TYPE_IMPORT:
	case CompletionProposal.MODULE_DECLARATION:
	case CompletionProposal.MODULE_REF:
		return CompletionItemKind.Module;
	case CompletionProposal.FIELD_REF:
		if (Flags.isEnum(flags)) {
			return CompletionItemKind.EnumMember;
		}
		if (Flags.isStatic(flags) && Flags.isFinal(flags)) {
			return CompletionItemKind.Constant;
		}
		return CompletionItemKind.Field;
	case CompletionProposal.FIELD_REF_WITH_CASTED_RECEIVER:
		return CompletionItemKind.Field;
	case CompletionProposal.KEYWORD:
		return CompletionItemKind.Keyword;
	case CompletionProposal.LABEL_REF:
		return CompletionItemKind.Reference;
	case CompletionProposal.LOCAL_VARIABLE_REF:
	case CompletionProposal.VARIABLE_DECLARATION:
		return CompletionItemKind.Variable;
	case CompletionProposal.METHOD_DECLARATION:
	case CompletionProposal.METHOD_REF:
	case CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER:
	case CompletionProposal.POTENTIAL_METHOD_DECLARATION:
		return CompletionItemKind.Method;
		//text
	case CompletionProposal.ANNOTATION_ATTRIBUTE_REF:
	case CompletionProposal.JAVADOC_BLOCK_TAG:
	case CompletionProposal.JAVADOC_FIELD_REF:
	case CompletionProposal.JAVADOC_INLINE_TAG:
	case CompletionProposal.JAVADOC_METHOD_REF:
	case CompletionProposal.JAVADOC_PARAM_REF:
	case CompletionProposal.JAVADOC_TYPE_REF:
	case CompletionProposal.JAVADOC_VALUE_REF:
	default:
		return CompletionItemKind.Text;
	}
}
 
Example 18
Source File: RefactoringAvailabilityTester.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public static boolean isDelegateCreationAvailable(final IField field) throws JavaModelException {
	return field.exists() && (Flags.isStatic(field.getFlags()) && Flags.isFinal(field.getFlags()) /*
	 * &&
	 * hasInitializer(field)
	 */);
}
 
Example 19
Source File: JavadocContents.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private String computeMethodAnchorPrefixEnd(BinaryMethod method) throws JavaModelException {
	String typeQualifiedName = null;
	if (this.type.isMember()) {
		IType currentType = this.type;
		StringBuffer buffer = new StringBuffer();
		while (currentType != null) {
			buffer.insert(0, currentType.getElementName());
			currentType = currentType.getDeclaringType();
			if (currentType != null) {
				buffer.insert(0, '.');
			}
		}
		typeQualifiedName = new String(buffer.toString());
	} else {
		typeQualifiedName = this.type.getElementName();
	}
	
	String methodName = method.getElementName();
	if (method.isConstructor()) {
		methodName = typeQualifiedName;
	}
	IBinaryMethod info = (IBinaryMethod) method.getElementInfo();

	char[] genericSignature = info.getGenericSignature();
	String anchor = null;
	if (genericSignature != null) {
		genericSignature = CharOperation.replaceOnCopy(genericSignature, '/', '.');
		anchor = Util.toAnchor(0, genericSignature, methodName, Flags.isVarargs(method.getFlags()));
		if (anchor == null) throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.UNKNOWN_JAVADOC_FORMAT, method));
	} else {
		anchor = Signature.toString(method.getSignature().replace('/', '.'), methodName, null, true, false, Flags.isVarargs(method.getFlags()));
	}
	IType declaringType = this.type;
	if (declaringType.isMember()) {
		// might need to remove a part of the signature corresponding to the synthetic argument (only for constructor)
		if (method.isConstructor() && !Flags.isStatic(declaringType.getFlags())) {
			int indexOfOpeningParen = anchor.indexOf('(');
			if (indexOfOpeningParen == -1) {
				// should not happen as this is a method signature
				return null;
			}
			int index = indexOfOpeningParen;
			indexOfOpeningParen++;
			int indexOfComma = anchor.indexOf(',', index);
			if (indexOfComma != -1) {
				index = indexOfComma + 2;
			} else {
				// no argument, but a synthetic argument
				index = anchor.indexOf(')', index);
			}
			anchor = anchor.substring(0, indexOfOpeningParen) + anchor.substring(index);
		}
	}
	return anchor + JavadocConstants.ANCHOR_PREFIX_END;
}
 
Example 20
Source File: IntroduceIndirectionRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private boolean isStaticTarget() throws JavaModelException {
	return Flags.isStatic(fTargetMethod.getFlags());
}