如何关闭Eclipse按空格和等号键自动补全内

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何关闭Eclipse按空格和等号键自动补全内相关的知识,希望对你有一定的参考价值。

工具:

Eclipse 

方法:

    打开Eclipse,选择show view->Other,找到Plug-ins。有的可能不用点other就能看到

    在下面的窗口周中点Plug-ins,找到org.eclipse.jface.text点inport as->source project导入到Eclipse中编辑

    在工程中分别展开src->org.eclipse.jface.text.contentassist,打开completionProposalPopup.Java

    按ctrl+F在文件中搜索“getTriggerCharacters”。重点把if (contains(triggers, key)) 修改为if (key != '=' && key != 0x20 && contains(triggers, key)) 

    导出文件,选择Deployable plugins andfragments成功导出文件后,新导出的压缩包复制到eclipse的plugins文件件中将旧的文件夹替换掉就ok了,烦人的空格,等号 补全也就消失了

参考技术A 当我们在Eclipse中设置按下任何字母都弹出候选菜单后(默认只有再按”.”后才会后输入的弹出菜单), 当是设置完后每次在输入变量的时候Eclipse就会自动给我们补全变量,就是在你输入的变量后面加上变量类型名。或者是在其他输入的时候有时并不需要将菜单中的第一个条目添加到内容中,但是一按下空格键或者是其他任意键,Eclipse就把第一个个给补上的。反而还要往回删除才满足要求,这一点是非常烦人的,今天就给大家提供一个能彻底解决此问题的方法:
打开Eclipse :
关闭Eclipse按空格和等号键自动补全内容0
选择show view->Other,找到Plug-ins。有的可能不用点other就能看到
关闭Eclipse按空格和等号键自动补全内容1
在下面的窗口周中点Plug-ins,找到org.eclipse.jface.text点inport as->source project导入到Eclipse中编辑
关闭Eclipse按空格和等号键自动补全内容2
在工程中分别展开src->org.eclipse.jface.text.contentassist,打开completionProposalPopup.java
关闭Eclipse按空格和等号键自动补全内容3
按ctrl+F在文件中搜索“getTriggerCharacters”。
重点
把if (contains(triggers, key))
修改为if (key != ‘=’ && key != 0x20 && contains(triggers, key)) 这里的0x20是空格的意思。
关闭Eclipse按空格和等号键自动补全内容4
导出文件,选择Deployable plugins andfragments
关闭Eclipse按空格和等号键自动补全内容5
关闭Eclipse按空格和等号键自动补全内容6
成功导出文件后,新导出的压缩包中的jar文件复制到eclipse的plugins文件夹中,然后将旧的jar文件替换掉就ok了(你的eclipse的旧plugins文件夹),烦人的空格,等号 补全也就消失了

Eclipse变量名自动补全问题 自定义上屏按键为TAB

示例:

@Configuration
@ComponentScan("com.test3")
public class AppConfig {
}
@Component
public class Bean2 {
}
public class MyTest {

    public static void main(String[] args) {
      //完成了扫描,但是完成这个扫描工作的不是
AnnotationConfigApplicationContext里的scannner
//context.scan("com.test3"); 这句采用的是scanner扫描的

AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class); System.out.println(context.getBean(Bean2.class)); } }

源码解析:

 public AnnotationConfigApplicationContext(Class... annotatedClasses) {
        1.this(); 
        2.this.register(annotatedClasses);
        3.this.refresh();
    }
public GenericApplicationContext() {
        this.customClassLoader = false;
        this.refreshed = new AtomicBoolean();
        this.beanFactory = new DefaultListableBeanFactory();
//实例化一个工厂DefaultListableBeanFactory }

 


1.this();
public AnnotationConfigApplicationContext() {
        1.1.this.reader = new AnnotatedBeanDefinitionReader(this);
    //实例化一个AnnotatedBeanDefinitionReader 1.2.
this.scanner = new ClassPathBeanDefinitionScanner(this);
    //ClassPathBeanDefinitionScanner,能够扫描我们bd,能够扫描一个类,并且转换成bd }
 1.1.this.reader = new AnnotatedBeanDefinitionReader(this);
public AnnotatedBeanDefinitionReader(BeanDefinitionRegistry registry) {
        1.1.1.this(registry, getOrCreateEnvironment(registry));
    }
 1.1.1.this(registry, getOrCreateEnvironment(registry));

private static Environment getOrCreateEnvironment(BeanDefinitionRegistry registry) {
        Assert.notNull(registry, "BeanDefinitionRegistry must not be null");
        return (Environment)(registry instanceof EnvironmentCapable ? ((EnvironmentCapable)registry).getEnvironment() : new StandardEnvironment());
    }
public AnnotatedBeanDefinitionReader(BeanDefinitionRegistry registry, Environment environment) {
        this.beanNameGenerator = new AnnotationBeanNameGenerator();
        this.scopeMetadataResolver = new AnnotationScopeMetadataResolver();
        Assert.notNull(registry, "BeanDefinitionRegistry must not be null");
        Assert.notNull(environment, "Environment must not be null");
        this.registry = registry;
        this.conditionEvaluator = new ConditionEvaluator(registry, environment, (ResourceLoader)null);


  1.1.1.1 委托AnnotationConfigUtils
AnnotationConfigUtils.registerAnnotationConfigProcessors(this.registry); }

1.1.1.1

public static void registerAnnotationConfigProcessors(BeanDefinitionRegistry registry) {
        registerAnnotationConfigProcessors(registry, (Object)null);
    }
public static Set<BeanDefinitionHolder> registerAnnotationConfigProcessors(BeanDefinitionRegistry registry, @Nullable Object source) {
        DefaultListableBeanFactory beanFactory = unwrapDefaultListableBeanFactory(registry);
        if (beanFactory != null) {
            if (!(beanFactory.getDependencyComparator() instanceof AnnotationAwareOrderComparator)) {          //1、添加AnnotationAwareOrderComparator类的对象,主要去排序
                beanFactory.setDependencyComparator(AnnotationAwareOrderComparator.INSTANCE);
            }

            if (!(beanFactory.getAutowireCandidateResolver() instanceof ContextAnnotationAutowireCandidateResolver)) {
                beanFactory.setAutowireCandidateResolver(new ContextAnnotationAutowireCandidateResolver());
            }
        }

        Set<BeanDefinitionHolder> beanDefs = new LinkedHashSet(8);
        RootBeanDefinition def;
    //往BeanDefinitionMap注册一个ConfigurationClassPostProcessor?  
    //

why?因为需要在invokeBeanFactoryPostProcessors
invokeBeanFactoryPostProcessors主要是在spring的beanFactory初始化的过程中去做一些事情,怎么来做这些事情呢?
委托了多个实现了BeanDefinitionRegistryPostProcessor或者BeanFactoryProcessor接口的类来做这些事情,有自定义的也有spring内部的
其中ConfigurationClassPostProcessor就是一个spring内部的BeanDefinitionRegistryPostProcessor
因为如果你不添加这里就没有办法委托ConfigurationClassPostProcessor做一些功能


if (!registry.containsBeanDefinition("org.springframework.context.annotation.internalConfigurationAnnotationProcessor")) { def = new RootBeanDefinition(ConfigurationClassPostProcessor.class); def.setSource(source); beanDefs.add(registerPostProcessor(registry, def, "org.springframework.context.annotation.internalConfigurationAnnotationProcessor")); } if (!registry.containsBeanDefinition("org.springframework.context.annotation.internalAutowiredAnnotationProcessor")) { def = new RootBeanDefinition(AutowiredAnnotationBeanPostProcessor.class); def.setSource(source); beanDefs.add(registerPostProcessor(registry, def, "org.springframework.context.annotation.internalAutowiredAnnotationProcessor")); } if (jsr250Present && !registry.containsBeanDefinition("org.springframework.context.annotation.internalCommonAnnotationProcessor")) { def = new RootBeanDefinition(CommonAnnotationBeanPostProcessor.class); def.setSource(source); beanDefs.add(registerPostProcessor(registry, def, "org.springframework.context.annotation.internalCommonAnnotationProcessor")); } if (jpaPresent && !registry.containsBeanDefinition("org.springframework.context.annotation.internalPersistenceAnnotationProcessor")) { def = new RootBeanDefinition(); try { def.setBeanClass(ClassUtils.forName("org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor", AnnotationConfigUtils.class.getClassLoader())); } catch (ClassNotFoundException var6) { throw new IllegalStateException("Cannot load optional framework class: org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor", var6); } def.setSource(source); beanDefs.add(registerPostProcessor(registry, def, "org.springframework.context.annotation.internalPersistenceAnnotationProcessor")); } if (!registry.containsBeanDefinition("org.springframework.context.event.internalEventListenerProcessor")) { def = new RootBeanDefinition(EventListenerMethodProcessor.class); def.setSource(source); beanDefs.add(registerPostProcessor(registry, def, "org.springframework.context.event.internalEventListenerProcessor")); } if (!registry.containsBeanDefinition("org.springframework.context.event.internalEventListenerFactory")) { def = new RootBeanDefinition(DefaultEventListenerFactory.class); def.setSource(source); beanDefs.add(registerPostProcessor(registry, def, "org.springframework.context.event.internalEventListenerFactory")); } return beanDefs; }

 

 @Nullable
    private static DefaultListableBeanFactory unwrapDefaultListableBeanFactory(BeanDefinitionRegistry registry) {
        if (registry instanceof DefaultListableBeanFactory) {
            return (DefaultListableBeanFactory)registry;
        } else {
            return registry instanceof GenericApplicationContext ? ((GenericApplicationContext)registry).getDefaultListableBeanFactory() : null; 
//AnnotationConfigApplicationContext继承了
GenericApplicationContext,所以执行青色部分
} }
 1.2.this.scanner = new ClassPathBeanDefinitionScanner(this);

public ClassPathBeanDefinitionScanner(BeanDefinitionRegistry registry) {
        this(registry, true);
    }
public ClassPathBeanDefinitionScanner(BeanDefinitionRegistry registry, boolean useDefaultFilters) {
        this(registry, useDefaultFilters, getOrCreateEnvironment(registry));
    }
public ClassPathBeanDefinitionScanner(BeanDefinitionRegistry registry, boolean useDefaultFilters, Environment environment) {
        this(registry, useDefaultFilters, environment, registry instanceof ResourceLoader ? (ResourceLoader)registry : null); //AnnotationConfigApplicationContext实现了ResourceLoader接口,所以执行青色部分
}
public ClassPathBeanDefinitionScanner(BeanDefinitionRegistry registry, boolean useDefaultFilters, Environment environment, @Nullable ResourceLoader resourceLoader) {
        this.beanDefinitionDefaults = new BeanDefinitionDefaults();
        this.beanNameGenerator = new AnnotationBeanNameGenerator();
        this.scopeMetadataResolver = new AnnotationScopeMetadataResolver();
        this.includeAnnotationConfig = true;
        Assert.notNull(registry, "BeanDefinitionRegistry must not be null");
        this.registry = registry;
        if (useDefaultFilters) {
            this.registerDefaultFilters();
        }

        this.setEnvironment(environment);
        this.setResourceLoader(resourceLoader);
    }
2.this.register(annotatedClasses);

 public void register(Class... annotatedClasses) {
        Assert.notEmpty(annotatedClasses, "At least one annotated class must be specified");
        this.reader.register(annotatedClasses);
    }
public void register(Class... annotatedClasses) {
        Class[] var2 = annotatedClasses;
        int var3 = annotatedClasses.length;

        for(int var4 = 0; var4 < var3; ++var4) {
            Class<?> annotatedClass = var2[var4];
            this.registerBean(annotatedClass);
        }

    }
 public void registerBean(Class<?> annotatedClass) {
        this.doRegisterBean(annotatedClass, (Supplier)null, (String)null, (Class[])null);
    }
<T> void doRegisterBean(Class<T> annotatedClass, @Nullable Supplier<T> instanceSupplier, @Nullable String name, @Nullable Class<? extends Annotation>[] qualifiers, BeanDefinitionCustomizer... definitionCustomizers) {
        AnnotatedGenericBeanDefinition abd = new AnnotatedGenericBeanDefinition(annotatedClass);
        if (!this.conditionEvaluator.shouldSkip(abd.getMetadata())) {
            abd.setInstanceSupplier(instanceSupplier);
            ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(abd);
            abd.setScope(scopeMetadata.getScopeName());
            String beanName = name != null ? name : this.beanNameGenerator.generateBeanName(abd, this.registry);
            AnnotationConfigUtils.processCommonDefinitionAnnotations(abd);
            int var10;
            int var11;
            if (qualifiers != null) {
                Class[] var9 = qualifiers;
                var10 = qualifiers.length;

                for(var11 = 0; var11 < var10; ++var11) {
                    Class<? extends Annotation> qualifier = var9[var11];
                    if (Primary.class == qualifier) {
                        abd.setPrimary(true);
                    } else if (Lazy.class == qualifier) {
                        abd.setLazyInit(true);
                    } else {
                        abd.addQualifier(new AutowireCandidateQualifier(qualifier));
                    }
                }
            }

            BeanDefinitionCustomizer[] var13 = definitionCustomizers;
            var10 = definitionCustomizers.length;

            for(var11 = 0; var11 < var10; ++var11) {
                BeanDefinitionCustomizer customizer = var13[var11];
                customizer.customize(abd);
            }

            BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(abd, beanName);
            definitionHolder = AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, definitionHolder, this.registry);
            BeanDefinitionReaderUtils.registerBeanDefinition(definitionHolder, this.registry);
        }
    }
 3.this.refresh();
 

//准备工作包括设置启动时间,是否激活标识位, 初始化属性源(property source)配置


public void refresh() throws BeansException, IllegalStateException { Object var1 = this.startupShutdownMonitor; synchronized(this.startupShutdownMonitor) { this.prepareRefresh(); ConfigurableListableBeanFactory beanFactory = this.obtainFreshBeanFactory(); this.prepareBeanFactory(beanFactory); try { this.postProcessBeanFactory(beanFactory); this.invokeBeanFactoryPostProcessors(beanFactory); this.registerBeanPostProcessors(beanFactory); this.initMessageSource(); this.initApplicationEventMulticaster(); this.onRefresh(); this.registerListeners(); this.finishBeanFactoryInitialization(beanFactory); this.finishRefresh(); } catch (BeansException var9) { if (this.logger.isWarnEnabled()) { this.logger.warn("Exception encountered during context initialization - cancelling refresh attempt: " + var9); } this.destroyBeans(); this.cancelRefresh(var9); throw var9; } finally { this.resetCommonCaches(); } } }
 protected void prepareBeanFactory(ConfigurableListableBeanFactory beanFactory) {
        
//添加一个类加载器
beanFactory.setBeanClassLoader(this.getClassLoader()); 

//
添加bean表达式解释器,能获取bean中的属性在前台页面

beanFactory.setBeanExpressionResolver(new StandardBeanExpressionResolver(beanFactory.getBeanClassLoader()));

//对象与String类型的转换 <property ref="dao"/>
beanFactory.addPropertyEditorRegistrar(
new ResourceEditorRegistrar(this, this.getEnvironment()));

beanFactory.addBeanPostProcessor(
new ApplicationContextAwareProcessor(this));
//添加一个后置处理器ApplicationContextAwareProcessor
//添加了自动注入忽略的列表
beanFactory.ignoreDependencyInterface(EnvironmentAware.
class); beanFactory.ignoreDependencyInterface(EmbeddedValueResolverAware.class); beanFactory.ignoreDependencyInterface(ResourceLoaderAware.class); beanFactory.ignoreDependencyInterface(ApplicationEventPublisherAware.class); beanFactory.ignoreDependencyInterface(MessageSourceAware.class); beanFactory.ignoreDependencyInterface(ApplicationContextAware.class); beanFactory.registerResolvableDependency(BeanFactory.class, beanFactory); beanFactory.registerResolvableDependency(ResourceLoader.class, this); beanFactory.registerResolvableDependency(ApplicationEventPublisher.class, this); beanFactory.registerResolvableDependency(ApplicationContext.class, this); beanFactory.addBeanPostProcessor(new ApplicationListenerDetector(this)); if (beanFactory.containsBean("loadTimeWeaver")) { beanFactory.addBeanPostProcessor(new LoadTimeWeaverAwareProcessor(beanFactory)); beanFactory.setTempClassLoader(new ContextTypeMatchClassLoader(beanFactory.getBeanClassLoader())); } if (!beanFactory.containsLocalBean("environment")) { beanFactory.registerSingleton("environment", this.getEnvironment()); } if (!beanFactory.containsLocalBean("systemProperties")) { beanFactory.registerSingleton("systemProperties", this.getEnvironment().getSystemProperties()); } if (!beanFactory.containsLocalBean("systemEnvironment")) { beanFactory.registerSingleton("systemEnvironment", this.getEnvironment().getSystemEnvironment()); } }

 重要步骤:



以上是关于如何关闭Eclipse按空格和等号键自动补全内的主要内容,如果未能解决你的问题,请参考以下文章

Eclipse变量名自动补全问题 自定义上屏按键为TAB

Eclipse点击空格总是自动补全代码怎么办,如何自动补全代码,代码提示

eclipse/myeclipse 变量名自动补全问题

Linux Shell 按Tab键不能补全

eclipse和myeclipse中如何关闭自动补全括号,花括号,双引号等功能

eclipse自动补全快捷键