Java Code Examples for org.eclipse.jdt.core.Flags#AccStatic

The following examples show how to use org.eclipse.jdt.core.Flags#AccStatic . 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: GetterSetterCompletionProposal.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @param document
 * @param offset
 * @param importRewrite
 * @param completionSnippetsSupported
 * @param addComments
 * @return
 * @throws CoreException
 * @throws BadLocationException
 */
public String updateReplacementString(IDocument document, int offset, ImportRewrite importRewrite, boolean completionSnippetsSupported, boolean addComments) throws CoreException, BadLocationException {
	int flags= Flags.AccPublic | (fField.getFlags() & Flags.AccStatic);
	String stub;
	if (fIsGetter) {
		String getterName= GetterSetterUtil.getGetterName(fField, null);
		stub = GetterSetterUtil.getGetterStub(fField, getterName, addComments, flags);
	} else {
		String setterName= GetterSetterUtil.getSetterName(fField, null);
		stub = GetterSetterUtil.getSetterStub(fField, setterName, addComments, flags);
	}

	// use the code formatter
	String lineDelim= TextUtilities.getDefaultLineDelimiter(document);
	String replacement = CodeFormatterUtil.format(CodeFormatter.K_CLASS_BODY_DECLARATIONS, stub, 0, lineDelim, fField.getJavaProject());

	if (replacement.endsWith(lineDelim)) {
		replacement = replacement.substring(0, replacement.length() - lineDelim.length());
	}

	return replacement;
}
 
Example 2
Source File: GroovyDocumentUtil.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
public static void refreshUserLibrary(Repository repository) {
    try {
        FunctionsRepositoryFactory.getUserFunctionCatgory().removeAllFunctions();
        GroovyRepositoryStore store = repository.getRepositoryStore(GroovyRepositoryStore.class);
        IJavaProject javaProject = repository.getJavaProject();
        for (IRepositoryFileStore artifact : store.getChildren()) {
            IType type = javaProject.findType(artifact.getDisplayName().replace("/", "."));
            if (type != null) {
                for (IMethod m : type.getMethods()) {
                    if (m.getFlags() == (Flags.AccStatic | Flags.AccPublic)) {
                        FunctionsRepositoryFactory.getUserFunctionCatgory()
                                .addFunction(new GroovyFunction(m, FunctionsRepositoryFactory.getUserFunctionCatgory()));
                    }
                }
            }
        }
    } catch (Exception e) {
        GroovyPlugin.logError(e);
    }
}
 
Example 3
Source File: XbaseImages.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected int toFlags(JvmVisibility visibility, boolean isAbstract, boolean isStatic, boolean isFinal) {
	int flags = toFlags(visibility);
	if(isAbstract)
		flags |= Flags.AccAbstract;
	if(isStatic)
		flags |= Flags.AccStatic;
	if(isFinal)
		flags |= Flags.AccFinal;
	return flags;
}
 
Example 4
Source File: GetterSetterCompletionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected boolean updateReplacementString(IDocument document, char trigger, int offset, ImportRewrite impRewrite) throws CoreException, BadLocationException {

	CodeGenerationSettings settings= JavaPreferencesSettings.getCodeGenerationSettings(fField.getJavaProject());
	boolean addComments= settings.createComments;
	int flags= Flags.AccPublic | (fField.getFlags() & Flags.AccStatic);

	String stub;
	if (fIsGetter) {
		String getterName= GetterSetterUtil.getGetterName(fField, null);
		stub= GetterSetterUtil.getGetterStub(fField, getterName, addComments, flags);
	} else {
		String setterName= GetterSetterUtil.getSetterName(fField, null);
		stub= GetterSetterUtil.getSetterStub(fField, setterName, addComments, flags);
	}

	// use the code formatter
	String lineDelim= TextUtilities.getDefaultLineDelimiter(document);

	IRegion region= document.getLineInformationOfOffset(getReplacementOffset());
	int lineStart= region.getOffset();
	int indent= Strings.computeIndentUnits(document.get(lineStart, getReplacementOffset() - lineStart), settings.tabWidth, settings.indentWidth);

	String replacement= CodeFormatterUtil.format(CodeFormatter.K_CLASS_BODY_DECLARATIONS, stub, indent, lineDelim, fField.getJavaProject());

	if (replacement.endsWith(lineDelim)) {
		replacement= replacement.substring(0, replacement.length() - lineDelim.length());
	}

	setReplacementString(Strings.trimLeadingTabsAndSpaces(replacement));
	return true;
}
 
Example 5
Source File: XbaseReferenceProposalCreator.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected Image computeImage(JvmFeature feature) {
	int flags = 0;
	int decorator = 0;
	switch(feature.getVisibility()) {
		case PUBLIC: flags = Flags.AccPublic; break;
		case PROTECTED: flags = Flags.AccProtected; break;
		case PRIVATE: flags = Flags.AccPrivate; break;
		case DEFAULT: flags = Flags.AccDefault; break;
	}
	JvmDeclaredType declaringType = feature.getDeclaringType();
	boolean interfaceOrAnnotation = false;
	if (declaringType instanceof JvmGenericType) {
		interfaceOrAnnotation = ((JvmGenericType) declaringType).isInterface();
	} else if (declaringType instanceof JvmAnnotationType) {
		interfaceOrAnnotation = true;
	}
	if (feature instanceof JvmConstructor) {
		decorator = JavaElementImageDescriptor.CONSTRUCTOR;
		if (declaringType.isAbstract()) {
			flags |= Flags.AccAbstract;
			decorator |= JavaElementImageDescriptor.ABSTRACT;
		}
		return computeConstructorImage(declaringType.getDeclaringType() != null, interfaceOrAnnotation, flags, decorator);
	} else if (feature instanceof JvmOperation) {
		JvmOperation operation = (JvmOperation) feature;
		if (operation.isStatic()) {
			flags |= Flags.AccStatic;
			decorator |= JavaElementImageDescriptor.STATIC;
		}
		if (operation.isAbstract()) {
			flags |= Flags.AccAbstract;
			decorator |= JavaElementImageDescriptor.ABSTRACT;
		}
		if (operation.isFinal()) {
			flags |= Flags.AccFinal;
			decorator |= JavaElementImageDescriptor.FINAL;
		}
		return computeMethodImage(interfaceOrAnnotation, flags, decorator);
	} else if (feature instanceof JvmField) {
		JvmField field = (JvmField) feature;
		if (field.isStatic()) {
			flags |= Flags.AccStatic;
			decorator |= JavaElementImageDescriptor.STATIC;
		}
		if (field.isFinal()) {
			flags |= Flags.AccFinal;
			decorator |= JavaElementImageDescriptor.FINAL;
		}
		if (declaringType instanceof JvmEnumerationType)
			flags |= Flags.AccEnum;
		return computeFieldImage(interfaceOrAnnotation, flags, decorator);
	} 
	return null;
}
 
Example 6
Source File: JdtTypesProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Compute the JVM modifiers that corresponds to the given description.
 *
 * <p>This function fixes the issue related to the missed modifiers given to the content assist.
 *
 * @param context the current content assist context.
 * @param description the description.
 * @return the JVM modifiers.
 * @since 2.11
 */
protected int getDirtyStateModifiers(ContentAssistContext context, IEObjectDescription description) {
	EObject eobject = description.getEObjectOrProxy();
	if (eobject.eIsProxy()) {
		eobject = EcoreUtil.resolve(eobject, context.getResource().getResourceSet());
	}
	int accessModifiers = Flags.AccPublic;
	int otherModifiers = 0;
	if (eobject instanceof JvmMember) {
		final JvmMember member = (JvmMember) eobject;
		switch (member.getVisibility()) {
		case PUBLIC:
			accessModifiers = Flags.AccPublic;
			break;
		case PRIVATE:
			accessModifiers = Flags.AccPrivate;
			break;
		case PROTECTED:
			accessModifiers = Flags.AccProtected;
			break;
		case DEFAULT:
		default:
			accessModifiers = Flags.AccDefault;
			break;
		}
		if (DeprecationUtil.isDeprecated(member)) {
			otherModifiers |= Flags.AccDeprecated;
		}
		if (eobject instanceof JvmDeclaredType) {
			final JvmDeclaredType type = (JvmDeclaredType) eobject;
			if (type.isFinal()) {
				otherModifiers |= Flags.AccFinal;
			}
			if (type.isAbstract()) {
				otherModifiers |= Flags.AccAbstract;
			}
			if (type.isStatic()) {
				otherModifiers |= Flags.AccStatic;
			}
			if (type instanceof JvmEnumerationType) {
                otherModifiers |= Flags.AccEnum;
            } else  if (type instanceof JvmAnnotationType) {
                otherModifiers |= Flags.AccAnnotation;
            } else if (type instanceof JvmGenericType) {
                if (((JvmGenericType) type).isInterface()) {
                    otherModifiers |= Flags.AccInterface;
                }
            }
		}
	}
	return accessModifiers | otherModifiers;
}